sersync文件单项实时同步

本文详细介绍了如何使用rsync和sersync在两台服务器间实现文件同步。包括rsync服务配置、sersync安装及配置过程,并解决了同步过程中可能出现的防火墙问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、看看两台服务器的设置:

主服务器          10.1.1.1    安装sersync

同步服务器       10.1.1.2     开启rsync服务

sersync服务下载地址http://code.google.com/p/sersync/downloads/list

 

2、在机器上安装rsync

  1. yum -y install rsync 

 

 

3、在同步服务器(10.1.1.2)上配置rsync

 

 vi /etc/rsyncd.conf
  1. uid=root 
  2. gid=root 
  3. max connections=36000 
  4. use chroot=no 
  5. log file=/var/log/rsyncd.log  
  6. pid file=/var/run/rsyncd.pid  
  7. lock file=/var/run/rsyncd.lock  
  8.  
  9. [tongbu]  
  10. path=/var/www/static
  11. comment  = xoyo video files  
  12. ignore errors = yes 
  13. read only = no 
  14. hosts allow =  10.1.1.1  
  15. 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
cd GNU-Linux-x86/

在目录下我们可以看见两个文件confxml.xml 和 sersync2,其中xml是相关的配置信息,sersync2是一个程序文件

 

 vi confxml.xml
  1. <localpath watch="/var/www/wwwroot/www/workspace/apps/uishang/www/"> 
  2.   <remote ip="10.1.1.2" name="tongbu"/> 
  3.   <!--<remote ip="192.168.8.39" name="tongbu"/>--> 
  4.   <!--<remote ip="192.168.8.40" name="tongbu"/>--> 
  5. </localpath>

把这里的配置填好,很简单,watch就是监控本地的目录,remote就是远程机器的信息,name填写刚才在目标同步服务器上的rsync的配置文件上的信息,然后确保目录存在,并权限正确

  1. <rsync> 
  2.   <commonParams params="-artuz"/> 
  3.   <auth start="true" users="root" passwordfile="/etc/rsync.pas"/> 
  4.   <userDefinedPort start="false" port="874"/><!-- port=874 --> 
  5.   <timeout start="false" time="100"/><!-- timeout=100 --> 
  6.   <ssh start="false"/> 
  7. </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

运行后可以看见一段这样的信息:

  1. set the system param  
  2. execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches  
  3. execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events  
  4. parse the command param  
  5. option: -d      run as a daemon  
  6. daemon thread num: 10  
  7. parse xml config file  
  8. host ip : localhost     host port: 8008  
  9. daemon start,sersync run behind the console   
  10. config xml parse success  
  11. please set /etc/rsyncd.conf max connections=0 Manually  
  12. sersync working thread 112  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)   
  13. Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)  
  14. please according your cpu ,use -n param to adjust the cpu rate  
  15. run the sersync:   
  16. 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

转载于:https://www.cnblogs.com/neier/archive/2013/01/28/2879853.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值