inotify+rsync实现实时同步
<span class="log-zd"><span class="log-close"><a title="隐藏目录"><i class="be be-cross"></i><strong>目录</strong></a></span></span>
1.1 什么是实时同步:如何实现实时同步
- 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化
- 发现目录中数据产生变化,就利用rsync服务推送到备份服务器上
1.2 实现实时同步的方法
inotify+rsync 方式实现数据同步
sersync 方式实现实时数据同步 详情参照:http://www.cnblogs.com/clsn/p/7707828.html
1.2.1 实时同步原理介绍
1.3 inotify+rsync 方式实现数据同步
1.3.1 Inotify简介
Inotify是一种强大的,细粒度的。异步的文件系统事件监控机制,linux内核从2.6.13起,加入了 Inotify支持,通过Inotify可以监控文件系统中添加、删除,修改、移动等各种事件,利用这个内核接口,第三方软件就可以监控文件系统下文件的各种变化情况,而 inotify-tools 正是实施这样监控的软件。国人周洋在金山公司也开发了类似的实时同步软件sersync。
<p class="a" style="text-indent: 21pt; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">
<span lang="EN-US">sersync</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 宋体; mso-hansi-font-family: 宋体;">软件实际上就是在</span><span lang="EN-US"> inotify</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 宋体; mso-hansi-font-family: 宋体;">软件基础上进行开发的,功能要更加强大些</span> <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 宋体; mso-hansi-font-family: 宋体;">,多了定时重传机制,过滤机制了提供接口做</span><span lang="EN-US"> CDN</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 宋体; mso-hansi-font-family: 宋体;">,支持多线程橾作。</span>
</p>
Inotify实际是一种事件驱动机制,它为应用程序监控文件系统事件提供了实时响应事件的机制,而无须通过诸如cron等的轮询机制来获取事件。cron等机制不仅无法做到实时性,而且消耗大量系统资源。相比之下,inotify基于事件驱动,可以做到对事件处理的实时响应,也没有轮询造成的系统资源消耗,是非常自然的事件通知接口,也与自然世界事件机制相符合。
inotify的实现有几款软件:
1.3.2 inotify+rsync使用方式
inotify 对同步数据目录信息的监控
rsync 完成对数据信息的实时同步
利用脚本进行结合
1.4 部署inotify软件的前提
需要2.6.13以后内核版本才能支持inotify软件。2.6.13内核之后版本,在没有安装inotify软件之前,应该有这三个文件。
1.4.1 三个重要文件的说明
<td style="width: 57.75pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt;" width="77">
<p class="MsoNormal" style="text-align: center;" align="center">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">默认值</span></strong>
</p>
</td>
<td style="width: 324.6pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt;" width="433">
<p class="MsoNormal" style="text-align: center;" align="center">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">作用说明</span></strong>
</p>
</td>
<td style="width: 57.75pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="77">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">8192</span>
</p>
</td>
<td style="width: 324.6pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="433">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">设置</span><span lang="EN-US">inotifywait</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">或</span><span lang="EN-US">inotifywatch</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">命令可以监视的文件数量(单进程)</span>
</p>
</td>
<td style="width: 57.75pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="77">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">128</span>
</p>
</td>
<td style="width: 324.6pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="433">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">设置每个用户可以运行的</span><span lang="EN-US">inotifywait</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">或</span><span lang="EN-US">inotifywatch</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">命令的进程数</span>
</p>
</td>
<td style="width: 57.75pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="77">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">16384</span>
</p>
</td>
<td style="width: 324.6pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="433">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">设置</span><span lang="EN-US">inotify</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">实例事件(</span><span lang="EN-US">event</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">)队列可容纳的事件数量</span>
</p>
</td>
1.4.3 【官方说明】三个重要文件1.4.2 【服务优化】可以将三个文件的数值调大,监听更大的范围
/proc/sys/fs/inotify/max_user_instances This specifies an upper limit on the number of inotify instances that can be created per real user ID.
/proc/sys/fs/inotify/max_user_watches This specifies an upper limit on the number of watches that can be created per real user ID.
1.5 inotify软件介绍及参数说明
1.5.1 两种安装方式
注:
YUM 安装需要有epel源
手工编译安装方式需要到github上进行下载软件包
inotify软件的参考资料链接:
1.5.2 inotify主要安装的两个软件
说明:在实时实时同步的时候,主要是利用inotifywait对目录进行监控
1.5.3 inotifywait命令参数说明
<td style="width: 360pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #bfbfbf; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: center;" align="center">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">含义</span></strong>
</p>
</td>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: red;">(重要参数)</span></strong>
</p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">Keep listening for events forever. Without this option, inotifywait will exit after one event is received.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">始终保持事件监听。</span>
</p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">111</span>
</p>
</td>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: red;">(重要参数)</span></strong>
</p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">Watch all subdirectories of any directories passed as arguments.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">递归监控目录数据信息变化</span>
</p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">Print events to <file> rather than stdout.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">打印事件到文件中,相当于标准正确输出</span>
</p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">Output errors to syslog(3) system log module rather than stderr.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">发送错误到</span><span lang="EN-US">syslog</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">相当于标准错误输出</span>
</p>
</td>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: red;">(重要参数)</span></strong>
</p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">If specified once, the program will be less verbose. Specifically, it will not state when it has completed establishing all inotify watches.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">输出信息少(只打印事件信息)</span>
</p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">Exclude all events on files matching the extended regular expression <pattern>.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">排除文件或目录</span>
</p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">Like --exclude but case insensitive.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">排除文件或目录时,不区分大小写</span>
</p>
</td>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: red;">(重要参数)</span></strong>
</p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">Print using a specified printf-like format string; read the man page for more details.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">指定时间输出格式</span>
</p>
</td>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: red;">(重要参数)</span></strong>
</p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">Print using a specified printf-like formatstring; read the man page for more details.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">打印使用指定的输出类似格式字符串;即实际监控输出内容</span>
</p>
</td>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: red;">(重要参数)</span></strong>
</p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">Listen for specific event(s). If omitted, all events are listened for.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">指定监听指定的事件,如果省略,表示所有事件都进行监听</span>
</p>
</td>
<td style="width: 416.7pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #bfbfbf; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: center;" align="center">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">事件说明</span></strong>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">file or directory contents were read</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录内容被读取</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">file or directory contents were writterv</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录内容被写入</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">file or directory attributes changed</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录属性改变</span>
</p>
</td>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: red;">(重要参数)</span></strong>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">file or directory closed, after being opened in writeable mode.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录关闭,在写入模式打开之后关闭的。</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">file or directory closed, after being opened in read-only mode.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录关闭,在只读模式打开之后关闭的</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">file or directory closed, regardless of read/write mode </span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录关闭,不管读或是写模式</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; tab-stops: 47.55pt;">
<span lang="EN-US">file or directory opened </span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; tab-stops: 47.55pt;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录被打开</span>
</p>
</td>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">拉</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; tab-stops: 44.15pt;">
<span lang="EN-US">file or directory moved to watched directory</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; tab-stops: 44.15pt;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录被移动到监控的目录中</span>
</p>
</td>
<p class="MsoNormal">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">推</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" valign="top" width="556">
<p class="MsoNormal">
<span lang="EN-US">file or directory moved from watched directory</span>
</p>
<p class="MsoNormal">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录被移动从监控的目录中</span>
</p>
</td>
<p class="MsoNormal">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: red;">(重要参数)</span></strong>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" valign="top" width="556">
<p class="MsoNormal">
<span lang="EN-US">file or directory moved to or from watched directory</span>
</p>
<p class="MsoNormal">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录不管移动到或是移出监控目录都触发事件</span>
</p>
</td>
<p class="MsoNormal">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: red;">(重要参数)</span></strong>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" valign="top" width="556">
<p class="MsoNormal">
<span lang="EN-US">file or directory created within watched directory</span>
</p>
<p class="MsoNormal">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录创建在监控目录中</span>
</p>
</td>
<p class="MsoNormal">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: red;">(重要参数)</span></strong>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" valign="top" width="556">
<p class="MsoNormal">
<span lang="EN-US">file or directory deleted within watched directory</span>
</p>
<p class="MsoNormal">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录被删除在监控目录中</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" valign="top" width="556">
<p class="MsoNormal">
<span lang="EN-US">file or directory was deleted</span>
</p>
<p class="MsoNormal">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录被删除,目录本身被删除</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" valign="top" width="556">
<p class="MsoNormal">
<span lang="EN-US">file system containing file or directory unmounted</span>
</p>
</td>
1.5.4.1 【实例】inotifywait监控中的事件测试
1、创建事件
2、删除事件
3、修改事件
4、移动事件 moved_to
5、移动事件 moved_from
1.5.5 inotifywait 参数 –format 格式定义参数
<td style="width: 388.35pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #bfbfbf; padding: 0cm 5.4pt;" width="518">
<p class="MsoNormal" style="text-align: center;" align="center">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">参数说明</span></strong>
</p>
</td>
<td style="width: 388.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="518">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">事件出现时,监控文件或目录的名称信息</span>
</p>
</td>
<td style="width: 388.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="518">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">事件出现时,将显示监控目录下触发事件的文件或目录信息,否则为空</span>
</p>
</td>
<td style="width: 388.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="518">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">显示发生的事件信息,不同的事件信息用逗号进行分隔</span>
</p>
</td>
<td style="width: 388.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="518">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">显示发生的事件信息,不同的事件信息有</span><span lang="EN-US">x</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">进行分隔,可以修改</span><span lang="EN-US">X</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">为指定分隔符</span>
</p>
</td>
<td style="width: 388.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="518">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">输出时间格式中定义的时间格式信息,通过</span><span lang="EN-US"> --timefmt option </span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">语法格式指定时间信息</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">这个格式是通过</span><span lang="EN-US">strftime</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">函数进行匹配时间格式信息的</span>
</p>
</td>
1.5.6 inotifywait 参数–timefmt 时间格式参数
<td style="width: 416.7pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt;" valign="top" width="556">
<p class="MsoNormal" style="text-align: center;" align="center">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">参数说明</span></strong>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">The day of the month as a decimal number(range 01 to 31)</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">每月的第几天,显示倍息为十进制数(范围是</span><span lang="EN-US"> 01-31 )</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt; height: 39.15pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; tab-stops: 178.35pt;">
<span lang="EN-US">The month as a decimal number (range 01 to 12).</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; tab-stops: 178.35pt;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">显示月份,显示信息为十进制(范围</span><span lang="EN-US"> 01-12 )</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">The minute as a decimal number (range 00 to 59).</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">显示分钟,显示信息为十进制(范围</span><span lang="EN-US"> 00-59 )</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">The year as a decimal number without a century (range 00 to 99).</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">年份信息,显示信息为十进制,并且没有世纪信息</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">The year as a decimal number including the century.</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">年份信息,显示信息为十进制,并且包含世纪信息</span>
</p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="556">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">The hour as a decimal number using a 24-hour clock (range 00 to 23).</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">小时信息,显示信息为十进制,使用</span><span lang="EN-US"> 24</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">小时制(范围</span><span lang="EN-US"> 00-23 )</span>
</p>
</td>
1.5.6.1 修改输出的日期格式
1.5.7 -e[参数] 重要监控事件参数汇总表:
<td style="width: 120.5pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #bfbfbf; padding: 0cm 5.4pt;" width="161">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">包含事件</span></strong>
</p>
</td>
<td style="width: 303.3pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #bfbfbf; padding: 0cm 5.4pt;" width="404">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">备注说明</span></strong>
</p>
</td>
<td style="width: 120.5pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="161">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">close_write </span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">close_nowrite</span>
</p>
</td>
<td style="width: 303.3pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="404">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录关闭,不管读或是写模式</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">即包含写关闭与读关闭</span>
</p>
</td>
<td style="width: 120.5pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="161">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">create</span>
</p>
</td>
<td style="width: 303.3pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="404">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">包含文件创建事件,但不包含目录创建事件</span>
</p>
</td>
<td style="width: 120.5pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="161">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">moved_to </span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">moved_from</span>
</p>
</td>
<td style="width: 303.3pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="404">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">文件或目录不管移动到或是移动出监控目录都触发事件</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">即包含信息移入或移出监控目录事件</span>
</p>
</td>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span lang="EN-US">create </span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">创建、</span><span lang="EN-US"> delete </span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">删除、</span><span lang="EN-US"> movedjto </span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">移入、</span><span lang="EN-US"> close_write </span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">修</span> <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">改</span>
</p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
<span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';"> <span class="cnblogs_code">inotifywait -mrq /data --format <span style="color: #800000;">"</span><span style="color: #800000;">%w%f</span><span style="color: #800000;">"</span> -e create,delete,moved_to,close_write</span> </span>
</p>
</td>
1.6 对inotifywait命令的测试
对inotifywait命令测试的说明:
需要打开两个连接窗口
<p class="a">
<strong><span style="color: yellow;" lang="EN-US">2</span></strong><strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 宋体; mso-hansi-font-family: 宋体; color: yellow;">窗口</span></strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 宋体; mso-hansi-font-family: 宋体;">对文件夹进行操作,可在一窗口中查看出</span><span lang="EN-US">inotifywait</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 宋体; mso-hansi-font-family: 宋体;">的监控记录</span>
</p>
1.6.1 、创建文件的逻辑↓
1.6.2 创建目录逻辑↓
1.6.3 监控子目录下的文件↓
1.6.4 sed命令修改逻辑
[root@nfs01 ~]# inotifywait -mrq /data –timefmt "%d-%m-%y %H:%M" –format "%T %w%f 事件信息: %e" -e moved_from /data/test.txt 事件信息: OPEN /data/sedDh5R8v 事件信息: CREATE /data/sedDh5R8v 事件信息: OPEN /data/test.txt 事件信息: ACCESS /data/sedDh5R8v 事件信息: MODIFY /data/sedDh5R8v 事件信息: ATTRIB /data/sedDh5R8v 事件信息: ATTRIB /data/test.txt 事件信息: CLOSE_NOWRITE,CLOSE /data/sedDh5R8v 事件信息: CLOSE_WRITE,CLOSE /data/sedDh5R8v 事件信息: MOVED_FROM /data/test.txt 事件信息: MOVED_TO
sed命令替换逻辑 :
01. 创建临时文件
02. 将原文件内容放置到临时文件中,修改替换临时文件中的内容,原有文件不做改动
03. 重命名临时文件,覆盖原文件
1.6.5 inotifywait监控中 -e 的参数使用
说明:表示只监听create事件
说明:不指定-e参数,表示监听所有事件
- 删除事件delete
03. 修改事件close_write
04. 移动事件moved_to
1.7 实时同步命令参数示意图
第2章 inotify+rsync实时同步服务部署
2.1 第一个里程碑:部署rsync服务
2.1.1 rsync服务端部署
1)软件是否存在
2)进行软件服务配置
3)创建rsync管理用户
4)创建数据备份储存目录,目录修改属主
5)创建认证用户密码文件并进行授权600
6)启动rsync服务
至此服务端配置完成
2.1.2 rsync客户端配置
1)软件是否存在
2)创建安全认证文件,并进行修改权限600
- 测试数据传输
2.2 第二个里程碑:部署inotify服务
首先先确认是否有epel****源用来安装inotify-tools软件
2.2.1 安装inotify软件
两种安装方式
注:
手工编译安装方式需要到github上进行下载软件包
inotify软件的参考资料链接:
https://github.com/rvoicilas/inotify-tools/wiki
2.2.2 查看inotify安装上的两个命令(inotifywait,inotifywatch)
2.2.2.1 inotifywait和inotifywatch的作用:
使用inotify进行监控,等待产生变化的文件信息
man inotifywatch
inotifywatch - gather filesystem access statistics using inotify 使用inotify进行监控,收集文件系统访问统计佶息
2.3 第三个里程碑:编写脚本,实现rsync+inotify软件功能结合
2.3.1 rsync服务命令:
2.3.2 inotify服务命令:
2.3.3 编写脚本:
脚本说明:
2.3.4 对脚本进行优化
Path=/data backup_Server=172.16.1.41
/usr/bin/inotifywait -mrq –format ’%w%f’ -e create,close_write,delete /data | while read line
do
if [ -f $line ];then
rsync -az $line –delete rsync_backup@$backup_Server::nfsbackup –password-file=/etc/rsync.password
else
cd $Path &&
rsync -az ./ –delete rsync_backup@$backup_Server::nfsbackup –password-file=/etc/rsync.password
fi
done
2.4 第四个里程碑:测试编写的脚本
2.4.1 让脚本在后台运行
在/data 目录先创建6个文件
在backup服务器上,已经时候同步过去了6个文件。
2.5 利用while循环语句编写的脚本停止方法(kill)
** ****说明:**kill三个杀手不是万能的,在进程暂停时,无法杀死;kill -9 (危险)
2.5.1 查看后台都要哪些程序在运行
2.5.2 fg将后台的程序调到前台来
2.6 进程的前台和后台运行方法:
2.6.1 脚本后台运行方法
2.7 screen实现脚本程序后台运行
2.7.1 经过yum查找发现screen命令属于screen包
2.7.2 安装screen软件
2.7.3 screen命令的参数
在shell中输入 screen即可进入screen 视图
Screen****实现后台运行程序的简单步骤:
Screen****命令中用到的快捷键
我的博客即将同步至腾讯云+社区,邀请大家一同入驻。
<li>
<a href="#13_inotifyrsync">1.3 inotify+rsync 方式实现数据同步</a><ul>
<li>
<a href="#131_Inotify">1.3.1 Inotify简介</a>
</li>
<li>
<a href="#132_inotifyrsync">1.3.2 inotify+rsync使用方式</a>
</li>
</ul>
</li>
<li>
<a href="#14_inotify">1.4 部署inotify软件的前提</a><ul>
<li>
<a href="#141_nbsp">1.4.1 三个重要文件的说明 </a>
</li>
<li>
<a href="#143_142">1.4.3 【官方说明】三个重要文件1.4.2 【服务优化】可以将三个文件的数值调大,监听更大的范围</a>
</li>
</ul>
</li>
<li>
<a href="#15_inotify">1.5 inotify软件介绍及参数说明</a><ul>
<li>
<a href="#151">1.5.1 两种安装方式</a>
</li>
<li>
<a href="#152_inotify">1.5.2 inotify主要安装的两个软件</a>
</li>
<li>
<a href="#153_inotifywaitnbsp">1.5.3 inotifywait命令参数说明 </a>
</li>
<li>
<a href="#154_-e_nbspnbsp">1.5.4 -e[参数] 可以指定的事件类型 </a><ul>
<li>
<a href="#1541nbsp_inotifywait">1.5.4.1 【实例】inotifywait监控中的事件测试</a>
</li>
</ul>
</li>
<li>
<a href="#155_inotifywait_--format_nbsp">1.5.5 inotifywait 参数 --format 格式定义参数 </a>
</li>
<li>
<a href="#156_inotifywait_--timefmt">1.5.6 inotifywait 参数--timefmt 时间格式参数</a><ul>
<li>
<a href="#1561nbsp">1.5.6.1 修改输出的日期格式</a>
</li>
</ul>
</li>
<li>
<a href="#157_-e_nbsp">1.5.7 -e[参数] 重要监控事件参数汇总表: </a>
</li>
</ul>
</li>
<li>
<a href="#16_inotifywait">1.6 对inotifywait命令的测试</a><ul>
<li>
<a href="#161_darr">1.6.1 、创建文件的逻辑↓</a>
</li>
<li>
<a href="#162_darr">1.6.2 创建目录逻辑↓</a>
</li>
<li>
<a href="#163_darr">1.6.3 监控子目录下的文件↓</a>
</li>
<li>
<a href="#164_sed">1.6.4 sed命令修改逻辑</a>
</li>
<li>
<a href="#165_inotifywait_-e">1.6.5 inotifywait监控中 -e 的参数使用</a>
</li>
</ul>
</li>
<li>
<a href="#17">1.7 实时同步命令参数示意图</a>
</li>
<li>
<a href="#2_inotifyrsync">第2章 inotify+rsync实时同步服务部署</a>
</li>
<li>
<a href="#21_rsync">2.1 第一个里程碑:部署rsync服务</a><ul>
<li>
<a href="#211_rsync">2.1.1 rsync服务端部署</a>
</li>
<li>
<a href="#212_rsync">2.1.2 rsync客户端配置</a>
</li>
</ul>
</li>
<li>
<a href="#22_inotify">2.2 第二个里程碑:部署inotify服务</a><ul>
<li>
<a href="#221_inotify">2.2.1 安装inotify软件</a>
</li>
<li>
<a href="#222_inotifyinotifywaitinotifywatch">2.2.2 查看inotify安装上的两个命令(inotifywait,inotifywatch)</a><ul>
<li>
<a href="#2221nbsp_inotifywaitinotifywatch">2.2.2.1 inotifywait和inotifywatch的作用:</a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#23_rsyncinotify">2.3 第三个里程碑:编写脚本,实现rsync+inotify软件功能结合</a><ul>
<li>
<a href="#231_rsync">2.3.1 rsync服务命令:</a>
</li>
<li>
<a href="#232_inotify">2.3.2 inotify服务命令:</a>
</li>
<li>
<a href="#233">2.3.3 编写脚本:</a>
</li>
<li>
<a href="#234">2.3.4 对脚本进行优化</a>
</li>
</ul>
</li>
<li>
<a href="#24">2.4 第四个里程碑:测试编写的脚本</a><ul>
<li>
<a href="#241">2.4.1 让脚本在后台运行</a>
</li>
</ul>
</li>
<li>
<a href="#25_whilekill">2.5 利用while循环语句编写的脚本停止方法(kill)</a><ul>
<li>
<a href="#251">2.5.1 查看后台都要哪些程序在运行</a>
</li>
<li>
<a href="#252_fg">2.5.2 fg将后台的程序调到前台来</a>
</li>
</ul>
</li>
<li>
<a href="#26">2.6 进程的前台和后台运行方法:</a><ul>
<li>
<a href="#261">2.6.1 脚本后台运行方法</a>
</li>
</ul>
</li>
<li>
<a href="#27_screen">2.7 screen实现脚本程序后台运行</a><ul>
<li>
<a href="#271_yumscreenscreen">2.7.1 经过yum查找发现screen命令属于screen包</a>
</li>
<li>
<a href="#272_screen">2.7.2 安装screen软件</a>
</li>
<li>
<a href="#273_screen">2.7.3 screen命令的参数</a>
</li>
</ul>
</li>
- 原文作者:惨绿少年
- 原文链接:https://clsn.io/clsn/lx490.html
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。