分类: LINUX
2014-07-29 10:41:06
二、源服务器(sersync):192.168.0.1点击(此处)折叠或打开
- 1、开启防火墙tcp 873端口(Rsync默认端口)
- #vi /etc/sysconfig/iptables #编辑防火墙配置文件添加下面一行话:
- -A -INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT
- #service iptables restart #最后重启防火墙使配置生效
- 2、安装Rsync
- #yum install rsync #安装rsync
- 3、创建rsyncd.conf配置文件
- #vi /etc/rsyncd.conf
- --------------------------
- uid = root
- gid = root
- max connections = 3600
- read only = no
- log file = /var/log/rsyncd.log
- pid file = /var/run/rsyncd.pid
- lock file = /var/run/rsyncd.lock
- [tbtest] #模块自定义名称 ---这个需要与源服务器Sersync对应
- path = /tongbu #需要同步的目录
- comment = Mirror to tongbu test
- ignore errors = yes
- read only = no
- hosts allow = 192.168.0.1 #允许访问源服务器IP
- hosts deny = 0.0.0.0/32 #拒绝所有IP连接,先允许后拒绝
- ------------------------------
- 4、启动服务:
- # ulimit -SHn 65535
- #/usr/bin/rsync --daemon /etc/rsyncd.conf
- 5、设置开机自启动:
- #echo "ulimit -SHn 65535" >>/etc/rc.local
- #echo "/usr/bin/rsync --daemon /etc/rsyncd.conf">>/etc/rc.local
- /* 小插曲:
- linux下用ulimit设置连接数最大值,默认是1024.
- 在高负载下要设置为更高,但最高只能为65535.
- ulimit只能做临时修改,重启后失效。
- 终极解除 Linux 系统的最大进程数和最大文件打开数限制:
- vim /etc/security/limits.conf
- # 添加如下的行
- * soft nproc 11000
- * hard nproc 11000
- * soft nofile 655350
- * hard nofile 655350
- */
1、安装rsync , 此步骤是为了手工测试配置是否正常,问题查找处理需要,以便部署sersync时无法查看原因而迷茫准备。网上很多教程都省略了。
2、安装sersync工具,实时触发rsync进行同步点击(此处)折叠或打开
- #yum install rsync
- #rsync -avzP /tongbu/ root@192.168.0.2::tbtest/
- /*
- /tongbu/ 同步目录
- root 用户名
- 192.168.0.2 目的服务器,安装并配置完毕rsync
- tbtest 模块自定义名称
- */
- 在源服务器192.168.0.1的/tongbu目录下新建
- #cd /tongbu
- #touch 1 2
- #echo "1">1
- #rsync -avzP /tongbu/ root@192.168.0.2::tbtest/ 对新文件开始同步测试
- 在目的服务器192.168.0.2查看/tongbu
- #cd /tongbu
- #ls 查看是否有新的文件同步过来
点击(此处)折叠或打开
- #cd /usr/local/src
- #wget
- #wget http:
- #tar zxvf sersync2.5_32bit_binary_stable_final.tar.gz
- GNU-Linux-x86/
- GNU-Linux-x86/sersync2
- GNU-Linux-x86/confxml.xml
- #mv /usr/local/src/GNU-Linux-x86/ /usr/local/sersync/
- #vi /usr/local/sersync/confxml.xml
点击(此处)折叠或打开
- <?xml version="1.0" encoding="ISO-8859-1"?>
- 2 <head version="2.5">
- 3 <host hostip="localhost" port="8008"></host>
- 4 <debug start="false"/>
- 5 <fileSystem xfs="false"/>
- 6 <filter start="true">
- 7 <exclude expression="^nosync/*"></exclude>
- 8 </filter>
- 9 <inotify>
- 10 <delete start="true"/>
- 11 <createFolder start="true"/>
- 12 <createFile start="false"/>
- 13 <closeWrite start="true"/>
- 14 <moveFrom start="true"/>
- 15 <moveTo start="true"/>
- 16 <attrib start="false"/>
- 17 <modify start="false"/>
- 18 </inotify>
- 19
- 20 <sersync>
- 21 <localpath watch="/tongbu">
- 22 <remote ip="192.168.0.2" name="tbtest"/>
- 23 </localpath>
- 24 <rsync>
- 25 <commonParams params="-artuz"/>
- 26 <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
- 27 <userDefinedPort start="false" port="874"/><!-- port=874 -->
- 28 <timeout start="false" time="100"/><!-- timeout=100 -->
- 29 <ssh start="false"/>
- 30 </rsync>
- 31 <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
- 32 <crontab start="false" schedule="600"><!--600mins-->
- 33 <crontabfilter start="false">
- 34 <exclude expression="*.php"></exclude>
- 35 <exclude expression="info/*"></exclude>
- 36 </crontabfilter>
- 37 </crontab>
- 38 <plugin start="false" name="command"/>
- 39 </sersync>
- 40
- 41 <plugin name="command">
- 42 <param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
- 43 <filter start="false">
- 44 <include expression="(.*)\.php"/>
- 45 <include expression="(.*)\.sh"/>
- 46 </filter>
- 47 </plugin>
- 48
- 49 </head>
点击(此处)折叠或打开
- 启动sersync
- #/usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml
- 设置开机自启动:
- #echo "/usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml">/etc/rc.local