Linux文件系统上一般用scp&rsync来同步文件,而一般我们会选择后者来同步容量大的文件,而且可实现压缩、更新传输,配合sersync,更可实现同步传输。
环境部署:server(192168.3.11)端安装sersync,用来监控本机需备份目录,客户端(192.168.3.12)开启rsync守护进程即可,一旦所监控目录内容有变化,会实时更新目录内容至客户端。
sersync资源:
- wget --no-check-certificate https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz
- git clone https://github.com/wsgzao/sersync.git
Clinet端配置:
[root@varnish2 ~]# yum install rsync xinetd -y
[root@varnish2 ~]# vim /etc/rsyncd.conf
uid = root
gid = root
port = 873
address = 192.168.3.12
hosts allow = 192.168.3.0/24
use chroot = yes
maxconnections = 5
lock file = /var/run/rsync.lock
logfile = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd
[webback]
path = /backup
comment = web back server
list = yes
read only = false
auth users = backer
secrets file = /etc/rsync.passwd
[root@varnish2 ~]# mkdir /backup
[root@varnish2 ~]# vim /etc/rsync.passwd
backer:123456789
[root@varnish2 ~]# chmod 600 /etc/rsync.passwd
[root@varnish2 ~]# echo "welcome backup server" > /etc/rsyncd.motd
[root@varnish2 ~]# systemctl start xinetd
[root@varnish2 ~]# rsync --daemon --config=/etc/rsyncd.conf
[root@varnish2 ~]# netstat -antup|grep 873
tcp 0 0 192.168.3.12:873 0.0.0.0:* LISTEN 7636/rsync
server端配置:
[root@localhost html]# yum install rsync xinetd -y
[root@localhost html]# systemctl start xinetd
[root@localhost html]# rsync --daemon
[root@localhost html]# vim /etc/rsync.passwd
123456789
[root@localhost ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv GNU-Linux-x86/ sersync
[root@localhost local]# cd sersync/
[root@localhost sersync]# ls
confxml.xml sersync2
[root@localhost sersync]# vim confxml.xml
<localpath watch="/var/www/html">
<remote ip="192.168.3.12" name="webback"/>
..........
<auth start="true" users="backer" passwordfile="/etc/rsync.passwd"/>
[root@localhost sersync]# /usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml
测试:
在server端/var/www/html 内创建或删除文件,Client端也会同步进行对应操作