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

 

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

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

 

2、主服务器上配置sersync2(目录自己创建):vim /web/etc/confxml.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,看备份服务器是否也一并删除。

如果成功了,基本上文件增加、修改和删除就都可以同步到备份服务器了。

 

因为sersync2不好下载,所以我把它放到附件里了,可以下载使用。

 

 

 

  • uploads.tar.gz (48.9 KB)
  • 下载次数: 0

你可能感兴趣的:(linux)