使用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

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



   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

   
       
       
   
   
       
       
       
       
       
   
   
   
       
       
       
       
   
   
   

   
     
   
       
       
   
   

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,看备份服务器是否也一并删除。
如果成功了,基本上文件增加、修改和删除就都可以同步到备份服务器了。

你可能感兴趣的:(Linux)