Chinaunix首页 | 论坛 | 博客
  • 博客访问: 577840
  • 博文数量: 94
  • 博客积分: 1452
  • 博客等级: 上尉
  • 技术积分: 982
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 15:38
文章分类

全部博文(94)

文章存档

2018年(3)

2014年(26)

2013年(11)

2012年(3)

2011年(43)

2010年(8)

分类: LINUX

2014-07-29 10:41:06

操作系统:CentOS 6.4
源服务器(sersync):192.168.0.1   ->  目标服务器(rsync):192.168.0.2
目的:使用root用户,把源服务器上/data/htdocs/ 目录实时同步到目标服务器的/data/htdocs/下

具体操作:
一、目标服务器(rsync):192.168.0.2

点击(此处)折叠或打开

  1. 1、开启防火墙tcp 873端口(Rsync默认端口)
  2. #vi /etc/sysconfig/iptables #编辑防火墙配置文件添加下面一行话:

  3. -A -INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT

  4. #service iptables restart #最后重启防火墙使配置生效

  5. 2、安装Rsync
  6. #yum install rsync #安装rsync

  7. 3、创建rsyncd.conf配置文件
  8. #vi /etc/rsyncd.conf
  9. --------------------------
  10. uid = root
  11. gid = root
  12. max connections = 3600
  13. read only = no
  14. log file = /var/log/rsyncd.log
  15. pid file = /var/run/rsyncd.pid
  16. lock file = /var/run/rsyncd.lock

  17. [tbtest] #模块自定义名称 ---这个需要与源服务器Sersync对应
  18. path = /tongbu #需要同步的目录
  19. comment = Mirror to tongbu test
  20. ignore errors = yes
  21. read only = no
  22. hosts allow = 192.168.0.1 #允许访问源服务器IP
  23. hosts deny = 0.0.0.0/32 #拒绝所有IP连接,先允许后拒绝
  24. ------------------------------

  25. 4、启动服务:
  26. # ulimit -SHn 65535
  27. #/usr/bin/rsync --daemon /etc/rsyncd.conf

  28. 5、设置开机自启动:
  29. #echo "ulimit -SHn 65535" >>/etc/rc.local
  30. #echo "/usr/bin/rsync --daemon /etc/rsyncd.conf">>/etc/rc.local

  31. /* 小插曲:
  32. linux下用ulimit设置连接数最大值,默认是1024.
  33. 在高负载下要设置为更高,但最高只能为65535.
  34. ulimit只能做临时修改,重启后失效。
  35. 终极解除 Linux 系统的最大进程数和最大文件打开数限制:
  36. vim /etc/security/limits.conf
  37. # 添加如下的行
  38. * soft nproc 11000
  39. * hard nproc 11000
  40. * soft nofile 655350
  41. * hard nofile 655350
  42. */
二、源服务器(sersync):192.168.0.1 
1、安装rsync  , 此步骤是为了手工测试配置是否正常,问题查找处理需要,以便部署sersync时无法查看原因而迷茫准备。网上很多教程都省略了。

点击(此处)折叠或打开

  1. #yum install rsync
  2. #rsync -avzP /tongbu/ root@192.168.0.2::tbtest/
  3.     /*
  4.         /tongbu/ 同步目录
  5.         root 用户名
  6.         192.168.0.2 目的服务器,安装并配置完毕rsync
  7.         tbtest 模块自定义名称
  8.         */

  9. 在源服务器192.168.0.1的/tongbu目录下新建
  10. #cd /tongbu
  11. #touch 1 2
  12. #echo "1">1

  13. #rsync -avzP /tongbu/ root@192.168.0.2::tbtest/ 对新文件开始同步测试

  14. 在目的服务器192.168.0.2查看/tongbu
  15. #cd /tongbu
  16. #ls 查看是否有新的文件同步过来
2、安装sersync工具,实时触发rsync进行同步

点击(此处)折叠或打开

  1. #cd /usr/local/src
  2. #wget
  3. #wget http: 
  4. #tar zxvf sersync2.5_32bit_binary_stable_final.tar.gz
  5.     GNU-Linux-x86/
  6.     GNU-Linux-x86/sersync2
  7.     GNU-Linux-x86/confxml.xml
  8. #mv /usr/local/src/GNU-Linux-x86/ /usr/local/sersync/
  9. #vi /usr/local/sersync/confxml.xml




点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2.       2 <head version="2.5">
  3.       3 <host hostip="localhost" port="8008"></host>
  4.       4 <debug start="false"/>
  5.       5 <fileSystem xfs="false"/>
  6.       6 <filter start="true">
  7.       7 <exclude expression="^nosync/*"></exclude>
  8.       8 </filter>
  9.       9 <inotify>
  10.      10 <delete start="true"/>
  11.      11 <createFolder start="true"/>
  12.      12 <createFile start="false"/>
  13.      13 <closeWrite start="true"/>
  14.      14 <moveFrom start="true"/>
  15.      15 <moveTo start="true"/>
  16.      16 <attrib start="false"/>
  17.      17 <modify start="false"/>
  18.      18 </inotify>
  19.      19
  20.      20 <sersync>
  21.      21 <localpath watch="/tongbu">
  22.      22 <remote ip="192.168.0.2" name="tbtest"/>
  23.      23 </localpath>
  24.      24 <rsync>
  25.      25 <commonParams params="-artuz"/>
  26.      26 <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
  27.      27 <userDefinedPort start="false" port="874"/><!-- port=874 -->
  28.      28 <timeout start="false" time="100"/><!-- timeout=100 -->
  29.      29 <ssh start="false"/>
  30.      30 </rsync>
  31.      31 <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
  32.      32 <crontab start="false" schedule="600"><!--600mins-->
  33.      33 <crontabfilter start="false">
  34.      34 <exclude expression="*.php"></exclude>
  35.      35 <exclude expression="info/*"></exclude>
  36.      36 </crontabfilter>
  37.      37 </crontab>
  38.      38 <plugin start="false" name="command"/>
  39.      39 </sersync>
  40.      40
  41.      41 <plugin name="command">
  42.      42 <param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
  43.      43 <filter start="false">
  44.      44 <include expression="(.*)\.php"/>
  45.      45 <include expression="(.*)\.sh"/>
  46.      46 </filter>
  47.      47 </plugin>
  48.      48
  49.      49 </head>




点击(此处)折叠或打开

  1. 启动sersync
  2. #/usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml
  3. 设置开机自启动:
  4. #echo "/usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml">/etc/rc.local


阅读(7184) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~