1、看看两台服务器的设置:
主服务器 10.1.1.1 安装sersync
同步服务器 10.1.1.2 开启rsync服务
sersync服务下载地址http://code.google.com/p/sersync/downloads/list
2、在机器上安装rsync
- yum -y install rsync
3、在同步服务器(10.1.1.2)上配置rsync
vi /etc/rsyncd.conf |
- uid=root
- gid=root
- max connections=36000
- use chroot=no
- log file=/var/log/rsyncd.log
- pid file=/var/run/rsyncd.pid
- lock file=/var/run/rsyncd.lock
- [tongbu]
- path=/var/www/static
- comment = xoyo video files
- ignore errors = yes
- read only = no
- hosts allow = 10.1.1.1
- hosts deny = *
保存退出!
然后启动服务
rsync --daemon |
查看进程,确认服务正常开启
[root@localhost ~]# netstat -tunlp | grep rsync tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 3318/rsync tcp 0 0 :::873 :::* LISTEN 3318/rsync |
4、在主服务器(10.1.1.1)上安装并配置sersync
tar zxvf sersync2.5_32bit_binary_stable_final.tar.gz |
在目录下我们可以看见两个文件confxml.xml 和 sersync2,其中xml是相关的配置信息,sersync2是一个程序文件
vi confxml.xml |
- <localpath watch="/var/www/wwwroot/www/workspace/apps/uishang/www/">
- <remote ip="10.1.1.2" name="tongbu"/>
- <!--<remote ip="192.168.8.39" name="tongbu"/>-->
- <!--<remote ip="192.168.8.40" name="tongbu"/>-->
-
</localpath>
把这里的配置填好,很简单,watch就是监控本地的目录,remote就是远程机器的信息,name填写刚才在目标同步服务器上的rsync的配置文件上的信息,然后确保目录存在,并权限正确
- <rsync>
- <commonParams params="-artuz"/>
- <auth start="true" users="root" passwordfile="/etc/rsync.pas"/>
- <userDefinedPort start="false" port="874"/><!-- port=874 -->
- <timeout start="false" time="100"/><!-- timeout=100 -->
- <ssh start="false"/>
-
</rsync>
commonParams可以用户自定义rsync参数,默认是-artuz auth start="false" 设置为true的时候,使用rsync的认证模式传送,需要配置user与passwrodfile(--password-file=/etc /rsync.pas),来使用。userDefinedPort 当远程同步目标服务器的rsync端口不是默认端口的时候使用(--port=874)。timeout设置rsync的timeout时间 (--timeout=100)。ssh 使用rsync -e ssh的方式进行传输。rsync.pas文件一行一个用户例如:root:123456
现在可以开始运行程序:同步之前可以先进行整体同步一次:
./sersync2 -r |
然后后台运行程序,监控目录
./sersync2 -d |
如果有多个XML可以加参数来指定
sersync -d -o config.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
- daemon thread num: 10
- parse xml config file
- host ip : localhost host port: 8008
- daemon start,sersync run behind the console
- config xml parse success
- please set /etc/rsyncd.conf max connections=0 Manually
- sersync working thread 112 = 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
- run the sersync:
- watch path is: /var/www/static
没有报错,再看看进程:
[root@localhost GNU-Linux-x86]# ps -aef | grep sersync2 root 30868 1 0 01:03 ? 00:00:00 ./sersync2 -d root 30896 30809 0 01:04 pts/3 00:00:00 grep sersync2 |
OK!服务正在后台运行!
然后可以去试试在目录下新建些东西看看是否成功!
错误解决
rsync: failed to connect to x.x.x.x: No route to host
原因:防火墙设置
解决办法:打开873端口
#iptables -I INPUT -p tcp -m state –state NEW -m tcp –dport 873 -j ACCEPT
#iptables -I INPUT -p udp -m state –state NEW -m udp –dport 873 -j ACCEPT
或者:
关闭防火墙:/etc/init.d/iptables stop