172.21.45.52(Sersync server)源服务器
172.11.251.51(Rsync server)目标服务器
客户端安装rsync
yum -y install rsync
vim /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
uid = root
gid = root
use chroot = yes
max connections = 100
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
timeout = 600
log file = /home/log/rsync.log
ignore errors
read only = false
list = false
hosts allow = 172.21.45.0/24
host deny = 0.0.0.0/32
auth users = backup
secrets file = /etc/rsync.password
# ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
# [ftp]
# path = /home/ftp
# comment = ftp export area
[html]
comment = html
path = /home/html
[root@Rsync ~]# echo “backup:damowang” > /etc/rsync.password
[root@Rsync ~]# chmod 600 /etc/rsync.password
[root@Rsync ~]# rsync --daemon
[root@Rsync ~]# ss -lntup |grep rsync
源端
[root@Sersync ~]# echo “damowang” > /etc/rsync.password
[root@Sersync ~]# chmod 600 /etc/rsync.password
源端测试
rsync -azvp /home/nmon.sh backup@192.168.3.5::htmlb/ --password-file=/etc/rsync.password
[root@Sersync ~]# unzip sersync-master.zip
[root@Sersync ~]# tar xf sersync-master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/
[root@Sersync ~]# cd /usr/local/
[root@Sersync local]# mv GNU-Linux-x86/ sersync
[root@Sersync local]# cd sersync/
[root@Sersync sersync]# cp confxml.xml confxml.xml.$(date +%F)
[root@Sersync sersync]# vim confxml.xml
vim confxml.xml
# 修改24、25行
<sersync>
<localpath watch="/var/www/html"> # 本地同步目录
<remote ip="192.168.94.44" name="www"/> # rsync模块名
# 修改31行
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="backup" passwordfile="/etc/rsync.password"/>
sersync2 -d -r -o /usr/local/sersync/confxml.xml
服务脚本
#! /bin/bash
#集合三同步
#sersyncd
#
. /etc/rc.d/init.d/functions
case "$1" in
start)
cd /usr/local/sersync
/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxmlc.xml
if [ $? -eq 0 ]
then
echo -e "Staring sersyncd [ OK ]"
exit 0
fi
;;
stop)
kill 'ps aux | grep sersync2 | grep -v grep | awk '{print $2}''
if [ $? -eq 0 ]
then
echo -e "Stopping sersyncd [ OK ]"
exit 0
fi
;;
status)
ps aux | grep sersync2 | grep -v grep
;;
esac