第1章 数据实时同步介绍

1.1 什么是实时同步:如何实现实时同步

1.2 实现实时同步的方法

1.2.1 实时同步原理介绍

1.3 inotify+rsync 方式实现数据同步

1.3.1 Inotify简介

inotify的实现有几款软件:

1.3.2 inotify+rsync使用方式

inotify 对同步数据目录信息的监控

rsync  完成对数据信息的实时同步

1.4 部署inotify软件的前提

1.4.1 三个重要文件的说明

<td style="width: 57.75pt; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt;" width="77">
  <p style="text-align: center;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif;">默认值</span></strong>
  </p>
</td>

<td style="width: 324.6pt; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt;" width="433">
  <p style="text-align: center;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif;">作用说明</span></strong>
  </p>
</td>
<td style="width: 57.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="77">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    8192
  </p>
</td>

<td style="width: 324.6pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="433">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">设置</span>inotifywait<span style="font-family: '微软雅黑',sans-serif;">或</span>inotifywatch<span style="font-family: '微软雅黑',sans-serif;">命令可以监视的文件数量(单进程)</span>
  </p>
</td>
<td style="width: 57.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="77">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    128
  </p>
</td>

<td style="width: 324.6pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="433">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">设置每个用户可以运行的</span>inotifywait<span style="font-family: '微软雅黑',sans-serif;">或</span>inotifywatch<span style="font-family: '微软雅黑',sans-serif;">命令的进程数</span>
  </p>
</td>
<td style="width: 57.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="77">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    16384
  </p>
</td>

<td style="width: 324.6pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="433">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">设置</span>inotify<span style="font-family: '微软雅黑',sans-serif;">实例事件(</span>event<span style="font-family: '微软雅黑',sans-serif;">)队列可容纳的事件数量</span>
  </p>
</td>

1.4.2 【服务优化】可以将三个文件的数值调大,监听更大的范围

1.4.3 【官方说明】三个重要文件

/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

    inotify软件的参考资料链接:

1.5.2 inotify主要安装的两个软件

说明:在实时实时同步的时候,主要是利用inotifywait对目录进行监控

1.5.3 inotifywait命令参数说明

<td style="width: 360pt; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: none; background: #bfbfbf; padding: 0cm 5.4pt;" width="480">
  <p style="text-align: center;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif;">含义</span></strong>
  </p>
</td>
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <strong><span style="font-family: '微软雅黑',sans-serif; courier new"4courier new"; color: red;">(重要参数)</span></strong>
  </p>
</td>

<td style="width: 360.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="480">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    Keep listening for events forever.&nbsp; Without this option, inotifywait will exit after one event is received.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">始终保持事件监听。</span>
  </p>
</td>
<td style="width: 360.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="480">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    111
  </p>
</td>
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <strong><span style="font-family: '微软雅黑',sans-serif; courier new"4courier new"; color: red;">(重要参数)</span></strong>
  </p>
</td>

<td style="width: 360.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="480">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    Watch all subdirectories of any directories passed as arguments.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">递归监控目录数据信息变化</span>
  </p>
</td>
<td style="width: 360.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="480">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    Print events to <file> rather than stdout.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">打印事件到文件中,相当于标准正确输出</span>
  </p>
</td>
<td style="width: 360.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="480">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    Output errors to syslog(3) system log module rather than stderr.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">发送错误到</span>syslog<span style="font-family: '微软雅黑',sans-serif;">相当于标准错误输出</span>
  </p>
</td>
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <strong><span style="font-family: '微软雅黑',sans-serif; courier new"4courier new"; color: red;">(重要参数)</span></strong>
  </p>
</td>

<td style="width: 360.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="480">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    If specified once, the program will be less verbose.&nbsp; Specifically, it will not state&nbsp; when&nbsp; it&nbsp; has&nbsp; completed establishing all inotify watches.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">输出信息少(只打印事件信息)</span>
  </p>
</td>
<td style="width: 360.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="480">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    Exclude all events on files matching the extended regular expression <pattern>.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">排除文件或目录</span>
  </p>
</td>
<td style="width: 360.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="480">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    Like --exclude but case insensitive.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">排除文件或目录时,不区分大小写</span>
  </p>
</td>
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <strong><span style="font-family: '微软雅黑',sans-serif; courier new"4courier new"; color: red;">(重要参数)</span></strong>
  </p>
</td>

<td style="width: 360.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="480">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    Print using a specified printf-like format string; read the man page for more details.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">指定时间输出格式</span>
  </p>
</td>
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <strong><span style="font-family: '微软雅黑',sans-serif; courier new"4courier new"; color: red;">(重要参数)</span></strong>
  </p>
</td>

<td style="width: 360.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="480">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    Print using a specified printf-like formatstring; read the man page for more details.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">打印使用指定的输出类似格式字符串;即实际监控输出内容</span>
  </p>
</td>
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <strong><span style="font-family: '微软雅黑',sans-serif; courier new"4courier new"; color: red;">(重要参数)</span></strong>
  </p>
</td>

<td style="width: 360.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="480">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    Listen for specific event(s).&nbsp; If omitted, all events are listened for.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">指定监听指定的事件,如果省略,表示所有事件都进行监听</span>
  </p>
</td>

1.5.4 -e[参数]  可以指定的事件类型

<td style="width: 416.7pt; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: none; background: #bfbfbf; padding: 0cm 5.4pt;" width="556">
  <p style="text-align: center;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif;">事件说明</span></strong>
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    file or directory contents were read
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录内容被读取</span>
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    file or directory contents were writterv
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录内容被写入</span>
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    file or directory attributes changed
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录属性改变</span>
  </p>
</td>
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <strong><span style="font-family: '微软雅黑',sans-serif; courier new"4courier new"; color: red;">(重要参数)</span></strong>
  </p>
</td>

<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    file or directory closed, after being opened in writeable mode.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录关闭,在写入模式打开之后关闭的。</span>
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    file or directory closed, after being opened in read-only mode.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录关闭,在只读模式打开之后关闭的</span>
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    file or directory closed, regardless of read/write mode
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录关闭,不管读或是写模式</span>
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    file or directory opened
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录被打开</span>
  </p>
</td>
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">拉</span>
  </p>
</td>

<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    file or directory moved to watched directory
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录被移动到监控的目录中</span>
  </p>
</td>
  <p>
    <span style="font-family: '微软雅黑',sans-serif;">推</span>
  </p>
</td>

<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="556">
  <p>
    file or directory moved from watched directory
  </p>
  
  <p>
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录被移动从监控的目录中</span>
  </p>
</td>
  <p>
    <strong><span style="font-family: '微软雅黑',sans-serif; courier new"4courier new";color: red;">(重要参数)</span></strong>
  </p>
</td>

<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="556">
  <p>
    file or directory moved to or from watched directory
  </p>
  
  <p>
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录不管移动到或是移出监控目录都触发事件</span>
  </p>
</td>
  <p>
    <strong><span style="font-family: '微软雅黑',sans-serif; courier new"4courier new";color: red;">(重要参数)</span></strong>
  </p>
</td>

<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="556">
  <p>
    file or directory created within watched directory
  </p>
  
  <p>
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录创建在监控目录中</span>
  </p>
</td>
  <p>
    <strong><span style="font-family: '微软雅黑',sans-serif; courier new"4courier new";color: red;">(重要参数)</span></strong>
  </p>
</td>

<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="556">
  <p>
    file or directory deleted within watched directory
  </p>
  
  <p>
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录被删除在监控目录中</span>
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="556">
  <p>
    file or directory was deleted
  </p>
  
  <p>
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录被删除,目录本身被删除</span>
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="556">
  <p>
    file system containing file or directory unmounted
  </p>
</td>

<span style=“courier new"4courier new”;background: olive;">1.5.4.1 <span style=“font-family: ‘微软雅黑’,sans-serif; courier new"4courier new”;background: olive;">【实例inotifywait<span style=“font-family: ‘微软雅黑’,sans-serif; courier new"4courier new”;background: olive;">监控中的事件测试

1、创建事件

2、删除事件

3、修改事件

4、移动事件 moved_to

1.5.5 inotifywait 参数 –format 格式定义参数

<td style="width: 388.35pt; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: none; background: #bfbfbf; padding: 0cm 5.4pt;" width="518">
  <p style="text-align: center;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif;">参数说明</span></strong>
  </p>
</td>
<td style="width: 388.35pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="518">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">事件出现时,监控文件或目录的名称信息</span>
  </p>
</td>
<td style="width: 388.35pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="518">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">事件出现时,将显示监控目录下触发事件的文件或目录信息,否则为空</span>
  </p>
</td>
<td style="width: 388.35pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="518">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">显示发生的事件信息,不同的事件信息用逗号进行分隔</span>
  </p>
</td>
<td style="width: 388.35pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="518">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">显示发生的事件信息,不同的事件信息有</span>x<span style="font-family: '微软雅黑',sans-serif;">进行分隔,可以修改</span>X<span style="font-family: '微软雅黑',sans-serif;">为指定分隔符</span>
  </p>
</td>
<td style="width: 388.35pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="518">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">输出时间格式中定义的时间格式信息,通过</span> --timefmt option <span style="font-family: '微软雅黑',sans-serif;">语法格式指定时间信息</span>
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">这个格式是通过</span>strftime<span style="font-family: '微软雅黑',sans-serif;">函数进行匹配时间格式信息的</span>
  </p>
</td>

1.5.6 inotifywait 参数–timefmt 时间格式参数

<td style="width: 416.7pt; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt;" valign="top" width="556">
  <p style="text-align: center;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif;">参数说明</span></strong>
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    The day of the month as a decimal number(range 01 to 31)
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">每月的第几天,显示倍息为十进制数(范围是</span> 01-31 )
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt; height: 39.15pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    The month as a decimal number (range 01 to 12).
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">显示月份,显示信息为十进制(范围</span> 01-12 )
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    The minute as a decimal number (range 00 to 59).
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">显示分钟,显示信息为十进制(范围</span> 00-59 )
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    The year as a decimal number without a century (range 00 to 99).
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">年份信息,显示信息为十进制,并且没有世纪信息</span>
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    The year as a decimal number including the century.
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">年份信息,显示信息为十进制,并且包含世纪信息</span>
  </p>
</td>
<td style="width: 416.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="556">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    The hour as a decimal number using a 24-hour clock (range 00 to 23).
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">小时信息,显示信息为十进制,使用</span> 24<span style="font-family: '微软雅黑',sans-serif;">小时制(范围</span> 00-23 )
  </p>
</td>

1.5.6.1 修改输出的日期格式

1.5.7 -e[参数] 重要监控事件参数汇总表:

<td style="width: 120.5pt; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: none; background: #bfbfbf; padding: 0cm 5.4pt;" width="161">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <strong><span style="font-family: '微软雅黑',sans-serif;">包含事件</span></strong>
  </p>
</td>

<td style="width: 303.3pt; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: none; background: #bfbfbf; padding: 0cm 5.4pt;" width="404">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <strong><span style="font-family: '微软雅黑',sans-serif;">备注说明</span></strong>
  </p>
</td>
<td style="width: 120.5pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="161">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    close_write&nbsp;&nbsp;
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    close_nowrite
  </p>
</td>

<td style="width: 303.3pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="404">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录关闭,不管读或是写模式</span>
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">即包含写关闭与读关闭</span>
  </p>
</td>
<td style="width: 120.5pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="161">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    create
  </p>
</td>

<td style="width: 303.3pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="404">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">包含文件创建事件,但不包含目录创建事件</span>
  </p>
</td>
<td style="width: 120.5pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="161">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    moved_to&nbsp;&nbsp;
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    moved_from
  </p>
</td>

<td style="width: 303.3pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" width="404">
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">文件或目录不管移动到或是移动出监控目录都触发事件</span>
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">即包含信息移入或移出监控目录事件</span>
  </p>
</td>
  <p style="text-align: justify; text-justify: inter-ideograph;">
    create <span style="font-family: '微软雅黑',sans-serif;">创建、</span> delete <span style="font-family: '微软雅黑',sans-serif;">删除、</span> movedjto <span style="font-family: '微软雅黑',sans-serif;">移入、</span> close_write <span style="font-family: '微软雅黑',sans-serif;">修</span> <span style="font-family: '微软雅黑',sans-serif;">改</span>
  </p>
  
  <p style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif;">inotifywait -mrq /data --format "%w%f"&nbsp; -e create,delete,moved_to,close_write</span>
  </p>
</td>

1.6 inotifywait命令的测试

1.6.1 、创建文件的逻辑↓

1.6.2 创建目录逻辑↓

1.6.3 监控子目录下的文件↓

<span style=“courier new"4courier new”;background: fuchsia;">1.6.4 sed<span style=“font-family: ‘微软雅黑’,sans-serif; courier new"4courier new”;background: fuchsia;">命令修改逻辑

sed****<span style=“font-family: ‘微软雅黑’,sans-serif; courier new"4courier new”;background: lime;">命令替换逻辑 <span style=“font-family: ‘微软雅黑’,sans-serif; courier new"4courier new”;background: lime;">:

  1. 创建临时文件

  2. 将原文件内容放置到临时文件中,修改替换临时文件中的内容,原有文件不做改动

  3. 重命名临时文件,覆盖原文件

1.6.5 inotifywait监控中 -e 的参数使用

    说明:表示只监听create事件

    说明:不指定-e参数,表示监听所有事件

    03. 修改事件close_write

    04. 移动事件moved_to

1.7 实时同步命令参数示意图

第2章 inotify+rsync实时同步服务部署

2.1 第一个里程碑:部署rsync服务

2.1.1 rsync服务端部署

1)软件是否存在

2)进行软件服务配置

[backup] comment = "backup dir by oldboy" path = /backup

[nfsbackup] comment = "nfsbackup dir by hzs" path = /nfsbackup

3)创建rsync管理用户

4)创建数据备份储存目录,目录修改属主

5)创建认证用户密码文件并进行授权600

6)启动rsync服务

至此服务端配置完成

2.1.2 rsync客户端配置

1)软件是否存在

2)创建安全认证文件,并进行修改权限600

  1. 测试数据传输

2.2 第二个里程碑:部署inotify服务

首先先确认是否有epel****用来安装inotify-tools软件

2.2.1 安装inotify软件

注:

    inotify软件的参考资料链接:

2.2.2 查看inotify安装上的两个命令(inotifywait,inotifywatch)

2.2.2.1 inotifywaitinotifywatch的作用:

#命令 man手册说明 # man inotifywait inotifywait - wait for changes to files using inotify

使用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 对脚本进行优化

2.4 第四个里程碑:测试编写的脚本

2.4.1 让脚本在后台运行

backup服务器上,已经时候同步过去了6个文件。

2.5 利用while循环语句编写的脚本停止方法(kill

 说明:kill三个杀手不是万能的,在进程暂停时,无法杀死;kill -9 <span style=“font-family: ‘微软雅黑’,sans-serif; courier new"4courier new”; color: red;">(危险)

2.5.1 查看后台都要哪些程序在运行

2.5.2 fg将后台的程序调到前台来

2.6 进程的前台和后台运行方法:

2.6.1 脚本后台运行方法

nohup

2.7 screen实现脚本程序后台运行

2.7.1 经过yum查找发现screen命令属于screen

2.7.2 安装screen软件

2.7.3 screen命令的参数

shell中输入 screen即可进入screen 视图

Screen**实现后台运行程序的简单步骤:**

Screen**命令中用到的快捷键**

2.8 sersync软件实现实时同步

http://www.cnblogs.com/znix/p/7707828.html

    <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">1.4.1 三个重要文件的说明</a>
        </li>
        <li>
          <a href="#142">1.4.2 【服务优化】可以将三个文件的数值调大,监听更大的范围</a>
        </li>
        <li>
          <a href="#143">1.4.3 【官方说明】三个重要文件</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_inotifywait">1.5.3 inotifywait命令参数说明</a>
        </li>
        <li>
          <a href="#154_-e_nbsp">1.5.4 -e[参数] &nbsp;可以指定的事件类型</a><ul>
            <li>
              <a href="#1541nbspinotifywait">1.5.4.1&nbsp;【实例】inotifywait监控中的事件测试</a>
            </li>
          </ul>
        </li>
        
        <li>
          <a href="#155_inotifywait_--format">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&nbsp;修改输出的日期格式</a>
            </li>
          </ul>
        </li>
        
        <li>
          <a href="#157_-e">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 、创建文件的逻辑&darr;</a>
        </li>
        <li>
          <a href="#162_darr">1.6.2 创建目录逻辑&darr;</a>
        </li>
        <li>
          <a href="#163_darr">1.6.3 监控子目录下的文件&darr;</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>
  </ul>
</li>

<li>
  <a href="#2_inotifyrsync">第2章 inotify+rsync实时同步服务部署</a><ul>
    <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="#2221nbspinotifywaitinotifywatch">2.2.2.1&nbsp;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>
    
    <li>
      <a href="#28_sersync">2.8 sersync软件实现实时同步</a>
    </li>
  </ul>
</li>