使用sync和sesync2进行服务器文件实时同步

主服务器: 192.168.1.8
备份服务器: 192.168.1.9
要求:主服务器上文件变动时能实时同步到备份服务器上。
方法:
在备份服务器上开启sync服务端,监听主服务器发送过来的文件传输请求,存储到相应位置。
主服务器开启sersync2服务端,监听某个目录文件变动并通知备份服务器的sync服务端。

操作步骤:

1、备份服务器开启sync服务:首先配置:vim /etc/rsyncd.conf

rsync服务端配置

uid = root
gid = root
use chroot = no
max connections = 200
timeout = 1000
transfer logging = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
log format = %t %a %m %f %b
port = 873
ignore errors
[dnoa]
path = /web/www
ignore errors = yes
read only = no
write only = yes
hosts allow = 192.168.1.8
hosts deny = *
list = yes
auth users = dnoa
secrets file = /etc/rsyncd.passwd

/etc/rsyncd.passwd的内容是:
用户名: 密码

启动服务: /usr/bin/rsync --daemon

服务建议写入自动启动脚本:/etc/rc.local

2、主服务器上配置sersync2(目录自己创建):vim /web/etc/confxml.xml

注意:这个文件比较复杂,但是需要配置的仅仅是彩色字体部分:

<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
   <host hostip="localhost" port="8008"></host>
   <debug start="false"/>
   <fileSystem xfs="false"/>
   <filter start="false">
   <exclude expression="(.*)\.svn"></exclude>
   <exclude expression="(.*)\.gz"></exclude>
   <exclude expression="^info/*"></exclude>
   <exclude expression="^static/*"></exclude>
   </filter>
   <inotify>
   <delete start="true"/>
   <createFolder start="true"/>
   <createFile start="true"/>
   <closeWrite start="true"/>
   <moveFrom start="true"/>
   <moveTo start="true"/>
   <attrib start="true"/>
   <modify start="true"/>
   </inotify>

   <sersync>
       <localpath watch="/web/www">
       <remote ip="192.168.1.9" name="dnoa"/>
   </localpath>
   <rsync>
       <commonParams params="-artuz"/>
       <auth start="true" users="dnoa" passwordfile="/etc/rsyncd.passwd"/>
       <userDefinedPort start="false" port="874"/><!-- port=874 -->
       <timeout start="false" time="100"/><!-- timeout=100 -->
       <ssh start="false"/>
   </rsync>
   <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
   <crontab start="false" schedule="600"><!--600mins-->
       <crontabfilter start="false">
       <exclude expression="*.php"></exclude>
       <exclude expression="info/*"></exclude>
       </crontabfilter>
   </crontab>
   <plugin start="false" name="command"/>
   </sersync>

   <plugin name="command">
   <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->
   <filter start="false">
       <include expression="(.*)\.php"/>
       <include expression="(.*)\.sh"/>
   </filter>
   </plugin>
</head>

rsyncd.passwd的配置内容是:
密码
注意不需要用户名,因为用户名配置在xml中。

启动服务: sersync2 -d -r -o /web/etc/confxml.xml

为了调试方便,可以将改为,再前端启动(去掉-d选项): sersync2 -r -o /web/etc/confxml.xml。
在主服务器创建文件 touch /web/www/test.file
看备份服务器是否也有了这个文件:ll /web/www/test.file
从主服务器上删除这个文件 rm -f /web/www/test.file,看备份服务器是否也一并删除。
如果成功了,基本上文件增加、修改和删除就都可以同步到备份服务器了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值