环境:

<span style="background-color: inherit;"><span style="color: black; font-size: 10.5pt; background-color: inherit;">主</span></span><span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">192.168.15.191<span style="background-color: inherit;">&nbsp;&nbsp;</span>/opt/tongbu&nbsp;</span></span>

<span style="background-color: inherit;"><span style="color: black; font-size: 10.5pt; background-color: inherit;">备</span></span><span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">192.168.15.192<span style="background-color: inherit;">&nbsp;<span style="background-color: inherit;">&nbsp;</span></span>/opt/tongbu</span></span>

<span style="background-color: inherit;"><span style="color: black; font-size: 10.5pt; background-color: inherit;">架构:</span></span><span style="background-color: inherit;"><span lang="EN-US" style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">Rsync+sersync</span></span>

<span style="background-color: inherit;"><span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">&nbsp;</span></span></span><span style="color: black; font-size: 10.5pt; background-color: inherit;">双方加</span><span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">hosts</span></span>

**<span style="color: rgb(68, 68, 68); font-family: 宋体; font-size: 10.5pt; background-color: rgb(243, 248, 251);">配置好两台服务器的</span>****<span lang="EN-US" style="color: rgb(68, 68, 68); font-family: &quot;}&quot;, serif; font-size: 10.5pt; background-color: rgb(243, 248, 251);">rsync</span>****<span style="color: rgb(68, 68, 68); font-family: 宋体; font-size: 10.5pt; background-color: rgb(243, 248, 251);">(两台都要配置)</span>**

**<span lang="EN-US" style="color: rgb(68, 68, 68); font-family: &quot;}&quot;, serif; font-size: 10.5pt; background-color: rgb(243, 248, 251);"><span style="background-color: inherit;">&nbsp;</span></span>**<span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: yellow;">yum install rsync</span>

**<span lang="EN-US" style="color: rgb(68, 68, 68); font-family: &quot;}&quot;, serif; font-size: 10.5pt; background-color: rgb(243, 248, 251);"><span style="background-color: inherit;">&nbsp;</span></span>**<span lang="EN-US" style="color: rgb(68, 68, 68); font-family: &quot;font-size:22.0pt;font-size:10.5pt;} &quot;; background-color: rgb(243, 248, 251);"><font face="宋体">vi /etc/rsyncd.conf</font></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">uid = root</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">gid = root</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">use chroot = no</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">max connections = 36000</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">log file = /var/log/rsyncd.log</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">pid file = /var/run/rsyncd.pid</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">lock file = /var/run/rsync.lock</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">[tongbu]</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">path = /opt/tongbu/</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">comment = test191<span style="background-color: inherit;">&nbsp;<span style="background-color: inherit;">&nbsp;</span></span></span></span><span style="background-color: inherit;"><span style="color: black; font-size: 10.5pt; background-color: inherit;">(自己主机名)</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">read only = no</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">hosts allow = 192.168.15.192/24</span></span>

<span style="color: rgb(68, 68, 68); font-size: 10.5pt; background-color: rgb(243, 248, 251);">(内容结束,</span><span lang="EN-US" style="color: rgb(68, 68, 68); font-family: &quot;}&quot;, serif; font-size: 10.5pt; background-color: rgb(243, 248, 251);">path</span><span style="color: rgb(68, 68, 68); font-size: 10.5pt; background-color: rgb(243, 248, 251);">为要同步的路径,</span><span lang="EN-US" style="color: red; font-family: &quot;}&quot;, serif; font-size: 10.5pt; background-color: rgb(243, 248, 251);">hosts allow</span><span style="color: red; font-size: 10.5pt; background-color: rgb(243, 248, 251);">为对方机器的</span><span lang="EN-US" style="color: red; font-family: &quot;}&quot;, serif; font-size: 10.5pt; background-color: rgb(243, 248, 251);">IP</span><span style="color: rgb(68, 68, 68); font-size: 10.5pt; background-color: rgb(243, 248, 251);">)</span>

<span style="background-color: inherit;"><span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">&nbsp;</span></span></span>

**<span style="color: rgb(68, 68, 68); font-family: 宋体; font-size: 10.5pt; background-color: rgb(243, 248, 251);">下载</span>**<span style="background-color: inherit;">**<span lang="EN-US" style="color: rgb(68, 68, 68); font-family: &quot;}&quot;, serif; font-size: 10.5pt; background-color: rgb(243, 248, 251);">&nbsp;</span>**</span>**<span lang="EN-US" style="color: rgb(68, 68, 68); font-family: &quot;}&quot;, serif; font-size: 10.5pt; background-color: rgb(243, 248, 251);">sersync</span>**<span style="background-color: inherit;">**<span lang="EN-US" style="color: rgb(68, 68, 68); font-family: &quot;}&quot;, serif; font-size: 10.5pt; background-color: rgb(243, 248, 251);">&nbsp;</span>**</span>**<span style="color: rgb(68, 68, 68); font-family: 宋体; font-size: 10.5pt; background-color: rgb(243, 248, 251);">并配置(两台都要配置)</span>**

<span style="background-color: inherit;"><span lang="EN-US" style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">sersync</span></span><span style="background-color: inherit;"><span style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">下载地址:</span></span><span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz</span></span>

<span style="background-color: inherit;"><span style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">上传<span style="background-color: inherit;"><span lang="EN-US" style="background-color: inherit;">sersync2.5.4_64bit_binary_stable_final.tar.gz</span></span></span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz&nbsp;<span style="background-color: inherit;">&nbsp;</span><span lang="EN-US" style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">#</span></span></span><span style="background-color: inherit;"><span style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">解压得到<span style="background-color: inherit;"><span lang="EN-US" style="background-color: inherit;">GNU-Linux-x86</span></span>文件</span></span>

<span style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">新建目录<span lang="EN-US" style="background-color: yellow;">mkdir -p /usr/local/sersync</span></span>

<span style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">把</span><span style="background-color: inherit;"><span lang="EN-US" style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">GNU-Linux-x86</span></span><span style="background-color: inherit;"><span style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">文件里的两个文件,<span style="background-color: inherit;"><span lang="EN-US" style="background-color: inherit;">#</span></span>移动到<span style="background-color: inherit;"><span lang="EN-US" style="background-color: inherit;">/usr/local/sersync</span></span></span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">cd GNU-Linux-x86/</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">cp confxml.xml /usr/local/sersync</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">cp sersync2 /usr/local/sersync&nbsp;</span></span>

<span style="background-color: inherit;"><span style="color: red; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">配置<span style="background-color: inherit;"><span lang="EN-US" style="background-color: inherit;">sersync</span></span></span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">cd /usr/local/sersync<span style="background-color: inherit;">&nbsp;</span><span lang="EN-US" style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">#</span></span></span><span style="background-color: inherit;"><span style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">进入<span style="background-color: inherit;"><span lang="EN-US" style="background-color: inherit;">sersync</span></span>安装目录</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">cp confxml.xml confxml.xml-bak&nbsp;<span style="background-color: inherit;">&nbsp;</span><span lang="EN-US" style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">#</span></span></span><span style="background-color: inherit;"><span style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">备份原文件</span></span>

<span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;"><span style="background-color: inherit;">vi confxml.xml</span><span style="background-color: inherit;">&nbsp;<span style="background-color: inherit;">&nbsp;</span><span lang="EN-US" style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">#</span></span></span><span style="background-color: inherit;"><span style="color: blue; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">编辑,修改下面的代码</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">{<span style="background-color: inherit;">&nbsp;<span style="background-color: inherit;">&nbsp;</span></span></span></span><span style="background-color: inherit;"><span style="color: black; font-size: 10.5pt; background-color: inherit;">就修改这一块,其他默认</span></span>

<span style="background-color: inherit;"><span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">&nbsp;&nbsp;&nbsp;<span style="background-color: inherit;">&nbsp;</span></span>&lt;localpath watch=&quot;/opt/tongbu/ &quot;&gt;</span></span>

<span style="background-color: inherit;"><span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">&nbsp;&nbsp;&nbsp;<span style="background-color: inherit;">&nbsp;</span></span><span lang="EN-US" style="color: red; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">&lt;remote ip=&quot;192.168.15.192&quot; name=&quot;tongbu&quot;/&gt;</span></span></span>

**<span style="color: rgb(68, 68, 68); font-family: 宋体; font-size: 10.5pt; background-color: rgb(243, 248, 251);">启动</span>****<span lang="EN-US" style="color: rgb(68, 68, 68); font-family: &quot;font-size:10.5pt;font-size:10.5pt;} &quot;; background-color: rgb(243, 248, 251);"><font face="宋体">sersync</font></span>****<span style="color: rgb(68, 68, 68); font-family: 宋体; font-size: 10.5pt; background-color: rgb(243, 248, 251);">后台</span>****<span lang="EN-US" style="color: rgb(68, 68, 68); font-family: &quot;font-size:10.5pt;font-size:10.5pt;} &quot;; background-color: rgb(243, 248, 251);"><font face="宋体">daemon</font></span>****<span style="color: rgb(68, 68, 68); font-family: 宋体; font-size: 10.5pt; background-color: rgb(243, 248, 251);">程序,开始进入监控(两台都要运行)</span>**

**<span style="background-color: inherit;"><span lang="EN-US" style="color: rgb(102, 102, 102); background-color: inherit;">Rsync</span></span><span style="color: rgb(102, 102, 102); background-color: inherit;"><span style="background-color: inherit;">的启动</span></span>**

<span lang="EN-US" style="color: red; background-color: yellow;">/usr/bin/rsync&nbsp;--daemon</span>

<span style="background-color: inherit;"><span style="color: rgb(68, 68, 68); font-family: 微软雅黑, sans-serif; font-size: 14pt; background-color: inherit;">(两台服务器都执行)在刚刚这个</span></span><span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 14pt; background-color: inherit;">cd /usr/local/sersync</span></span><span style="background-color: inherit;"><span style="color: rgb(68, 68, 68); font-family: 微软雅黑, sans-serif; font-size: 14pt; background-color: inherit;">下执行</span></span><span style="background-color: inherit;"><span lang="EN-US" style="color: rgb(68, 68, 68); font-family: &quot;font-size:14.0pt;font-size:10.5pt;} &quot;; background-color: inherit;"><font face="宋体">./sersync2 -d &ndash;r</font></span></span>

<span lang="EN-US" style="color: rgb(92, 92, 92); font-family: Consolas; font-size: 15pt; background-color: yellow;">/usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml</span>

<span style="color: rgb(68, 68, 68); font-size: 10.5pt; background-color: rgb(243, 248, 251);">在两台服务器的这个目录下建目录,加文件,删除文件看看,是不是同步了</span>

**<span style="background-color: inherit;"><span style="color: rgb(102, 102, 102); background-color: inherit;">开机启动<span lang="EN-US" style="background-color: inherit;">&nbsp;</span><span lang="EN-US" style="background-color: inherit;">vi /etc/rc.local<span style="background-color: inherit;">&nbsp;</span></span>添加</span></span>**

<span lang="EN-US" style="color: red; background-color: yellow;">/usr/bin/rsync&nbsp;--daemon</span>

<span style="background-color: inherit;"><span style="color: rgb(102, 102, 102); background-color: inherit;">若要停止服务,执行如下命令<span style="background-color: inherit;"><span lang="EN-US" style="background-color: inherit;">:</span></span></span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: rgb(102, 102, 102); background-color: inherit;">ps -ef|grep rsync</span></span>

<span style="background-color: inherit;"><span lang="EN-US" style="color: rgb(102, 102, 102); background-color: inherit;">cat&nbsp;/var/run/rsyncd.pid&nbsp;|&nbsp;xargs&nbsp;kill&nbsp;-9&nbsp;&amp;&amp;&nbsp;rm&nbsp;-rf&nbsp;/var/run/rsyncd.pid&nbsp;&nbsp;</span></span>

<span style="background-color: inherit;"><span style="background-color: inherit;"><span lang="EN-US" style="color: black; font-family: 微软雅黑, sans-serif; font-size: 10.5pt; background-color: inherit;">&nbsp;</span></span></span>