zl程序教程

您现在的位置是:首页 >  云平台

当前栏目

sersync+rsync做实时同步详解程序员

实时同步程序员 详解 Rsync Sersync
2023-06-13 09:20:04 时间

1)下载sersync

wegt https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz

或者Windows下载再上传源主机youxi1。

2)解压

[[email protected] ~]# ls 

anaconda-ks.cfg sersync2.5.4_64bit_binary_stable_final.tar.gz 

[[email protected] ~]# tar xvf sersync2.5.4_64bit_binary_stable_final.tar.gz //解压 

GNU-Linux-x86/ 

GNU-Linux-x86/sersync2 

GNU-Linux-x86/confxml.xml 

[[email protected] ~]# ls 

anaconda-ks.cfg GNU-Linux-x86 sersync2.5.4_64bit_binary_stable_final.tar.gz 

[[email protected] ~]# mv GNU-Linux-x86 sersync 改名 

[[email protected] ~]# ls 

anaconda-ks.cfg sersync sersync2.5.4_64bit_binary_stable_final.tar.gz 

3)在目标主机youxi2上修改/etc/rsyncd.conf配置文件,以及密码文件

[[email protected] ~]# cat /etc/rsyncd.conf 

uid = root 

gid = root 

address = 192.168.5.102 

port = 873 

hosts allow = 192.168.5.101/24 

use chroot = yes 

max connections = 5 

pid file = /var/run/rsyncd.pid 

lock file = /var/run/rsync.lock 

log file = /var/log/rsyncd.log 

motd file = /etc/rsyncd.motd 

[backupwwwhtml] 

path = /backup/www/html 

comment = backup /www/html/ 

read only = false 

list = yes 

auth users = rsync2 

secrets file = /etc/rsync.passwd 

[[email protected] ~]# cat /etc/rsync.passwd 

rsync2:102102 

[[email protected] ~]# chmod 600 /etc/rsync.passwd

启动指定配置文件的rsync的守护进程

[[email protected] ~]# rsync --daemon --config=/etc/rsyncd.conf 

[[email protected] ~]# ps aux | grep rsync 

root 1478 0.0 0.0 114740 564 ? Ss 11:10 0:00 rsync --daemon --config=/etc/rsyncd.conf 

root 1485 0.0 0.0 112720 980 pts/0 R+ 11:12 0:00 grep --color=auto rsync 

4)源主机youxi1上修改sersync的配置文件

[[email protected] sersync]# vim confxml.xml 

 ?xml version="1.0" encoding="ISO-8859-1"? 

 head version="2.5" 

 host hostip="localhost" port="8008" /host 

 debug start="false"/ 

 fileSystem xfs="false"/ 

 filter start="false" 

 exclude expression="(.*)/.svn" /exclude 

 exclude expression="(.*)/.gz" /exclude 

 exclude expression="^info/*" /exclude 

 exclude expression="^static/*" /exclude 

 /filter 

 inotify 

 createFile start="false"/ 

 closeWrite start="true"/ 

 moveFrom start="true"/ 

 moveTo start="true"/ 

 attrib start="false"/ 

 modify start="false"/ 

 /inotify 

 sersync 

 localpath watch="/www/html" 

 remote ip="192.168.5.102" name="backupwwwhtml"/ //修改为目标主机IP地址和模块名 

 /localpath 

 rsync 

 commonParams params="-artuz"/ 

 auth start="true" users="rsync2" passwordfile="/etc/rsync.passwd"/ //开启,修改用户名和密码文件地址 

 userDefinedPort start="false" port="874"/ !-- port=874 -- 

 timeout start="false" time="100"/ !-- timeout=100 -- 

 ssh start="false"/ 

 /rsync 

 failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/ !--default e 

very 60mins execute once-- 

 crontab start="false" schedule="600" !--600mins-- 

 crontabfilter start="false" 

 exclude expression="*.php" /exclude 

 exclude expression="info/*" /exclude 

 /crontabfilter 

 /crontab 

 plugin start="false" name="command"/ 

 /sersync 

添加密码文件

[[email protected] sersync]# vim /etc/rsync.passwd 

102102 

[[email protected] html]# chmod 600 /etc/rsync.passwd

5)开启源主机youxi1的sersync的守护进程

[[email protected] sersync]# /root/sersync/sersync2 -dro /root/sersync/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: -d run as a daemon 

option: -r rsync all the local files to the remote servers before the sersync work 

option: -o config xml name: /root/sersync/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 rsync2 

passwordfile is /etc/rsync.passwd 

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 /www/html rsync -artuz -R --delete ./ [email protected]::backupwwwhtml --password-file=/etc/rsync.passwd /dev/null 2 1 

run the sersync: 

watch path is: /www/html 

6)测试

现在的目的主机youxi2情况如下

[[email protected] ~]# ls /backup/www/html/ 

adm crash empty gopher lib lock mail opt run tmp 

cache db games kerberos local log nis preserve spool yp 

对源主机youxi1的/www/html/目录下文件进行操作

[[email protected] sersync]# cd /www/html/ 

[[email protected] html]# ls 

adm crash empty gopher lib lock mail opt run tmp 

cache db games kerberos local log nis preserve spool yp 

[[email protected] html]# rm -rf adm/ 

[[email protected] html]# touch 1.txt 

[[email protected] html]# ls 

1.txt crash empty gopher lib lock mail opt run tmp 

cache db games kerberos local log nis preserve spool yp 

回到目的主机查看情况

[[email protected] ~]# ls /backup/www/html/ 

1.txt crash empty gopher lib lock mail opt run tmp 

cache db games kerberos local log nis preserve spool yp 

2781.html

服务器部署程序员系统优化网站设置运维