[root@salt-client01 src]# echo export path=$path:/usr/local/sersync/bin>>/etc/profile #声明环境变量
[root@salt-client01 src]# source /etc/profile
[root@salt-client01 src]# sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml #启动
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -r rsync all the local files to the remote servers before the sersync work
option: -d run as a daemon
option: -o config xml name: /usr/local/sersync/conf/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
daemon start,sersync run behind the console
use rsync password-file :
user is rsync_body
passwordfile is /etc/rsync.password
config xml parse success
please set /etc/rsyncd.conf max connections=0 manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
max threads numbers is: 22 = 12(thread pool nums) + 10(sub threads)
please according your cpu ,use -n param to adjust the cpu rate
——————————————
rsync the directory recursivly to the remote servers once
working please wait…
execute command: cd /data && rsync -artuz -r –delete ./ –timeout=100 rsync_body@192.168.91.166::data –password-file=/etc/rsync.password >/dev/null 2>&1
run the sersync:
watch path is: /data #此时可以看出sersync已经启动成功了
#检测脚本
[root@salt-client01 log]# pwd
/usr/local/sersync/log
[root@salt-client01 log]# vim rsync_fail_log.sh
[root@salt-client01 log]# chmod +x rsync_fail_log.sh
[root@salt-client01 ~]# cat /usr/local/sersync/log/rsync_fail_log.sh
#!/bin/bash
#purpose: check sersync whether it is alive
#author: cai meng zhi
sersync=”/usr/local/sersync/bin/sersync2″
conf_file=”/usr/local/sersync/conf/confxml.xml”
status=$(ps aux |grep sersync2|grep -v grep|wc -l)
if [ $status -eq 0 ];
then
$sersync -d -r -o $conf_file &
else
exit 0;
fi
脚本写好以后,添加到计划任务中去
*/1 * * * * /bin/bash /usr/local/sersync/log/rsync_fail_log.sh > /dev/null 2>&1
测试同步:
客户端新增文件
[root@salt-client01 data]# cp /etc/passwd 192.168.91.156.passwd
[root@salt-client01 data]# ll
total 4
-rw-r–r– 1 root root 1928 nov 10 18:15 192.168.91.156.passwd
-rw-r–r– 1 root root 0 nov 10 17:27 3
服务端检测
[root@salt-master data]# cd /data/
[root@salt-master data]# ll
total 8
-rw-r–r– 1 root root 1928 nov 10 18:15 192.168.91.156.passwd #说明已经同步过来了
-rw-r–r– 1 root root 0 nov 10 17:27 3
drwxr-xr-x 2 root root 4096 nov 10 17:27 data
客户端测试删除
[root@salt-client01 data]# rm rf 192.168.91.156.passwd
rm: cannot remove `rf: no such file or directory
rm: remove regular file `192.168.91.156.passwd? y
[root@salt-client01 data]# ll
total 0
-rw-r–r– 1 root root 0 nov 10 17:27 3
[root@salt-client01 data]#
服务器端:
[root@salt-master data]# ll
total 4
-rw-r–r– 1 root root 0 nov 10 17:27 3 #说明已经删除掉了
drwxr-xr-x 2 root root 4096 nov 10 17:27 data