标签:
1.同步端和被同步端都需要安装rsync服务:
#yum install rsync
2.同步端还需要安装serync
#wget https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz #tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz #解压并移动到/usr/local/sersync目录即可 #mv GNU-Linux-x86 /usr/local/sersync
3.sersync配置文件:
# cat /usr/local/sersync/confxml.xml #后台同步运行:#/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/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> <delete start="true"/> <createFolder start="true"/> <createFile start="false"/> <closeWrite start="true"/> <moveFrom start="true"/> <moveTo start="true"/> <attrib start="true"/> <modify start="true"/> </inotify> <sersync> <localpath watch="/data/www"> <!-- #本地:同步端--> <remote ip="127.0.0.1" name="test"/><!-- #远端:被同步端--> <!--<remote ip="192.168.8.39" name="tongbu"/>--> <!--<remote ip="192.168.8.40" name="tongbu"/>--> </localpath> <rsync> <commonParams params="-artuz"/> <auth start="true" users="root" passwordfile="/etc/serync.pas"/><!-- 密码文件--> <userDefinedPort start="true" port="874"/><!-- port=874 端口要和rsync端口一致--> <timeout start="false" time="100"/><!-- timeout=100 --> <ssh start="false"/> </rsync> <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> <crontab start="true" schedule="5"><!--600mins 分钟--> <crontabfilter start="false"> <exclude expression="*.php"></exclude> <exclude expression="info/*"></exclude> </crontabfilter> </crontab> <plugin start="false" name="command"/> </sersync> <plugin name="command"> <param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix--> <filter start="false"> <include expression="(.*)\.php"/> <include expression="(.*)\.sh"/> </filter> </plugin> <plugin name="socket"> <localpath watch="/opt/tongbu"> <deshost ip="192.168.138.20" port="8009"/> </localpath> </plugin> <plugin name="refreshCDN"> <localpath watch="/data0/htdocs/cms.xoyo.com/site/"> <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/> <sendurl base="http://pic.xoyo.com/cms"/> <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/> </localpath> </plugin> </head>
4.被同步端的rsync的配置文件:
[root@localhost ~]# cat /etc/rsyncd.conf #运行:#rsync --daemon --config=/etc/rsyncd.conf #sync configuration file uid = root gid = root port = 874 max connections = 0 use chroot = yes timeout = 200 log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log format = %t %a %m %f %b auth users = root secrets file = /etc/rsync.pas #账号密码文件 [test] path = /data/test/ comment = "test directory file" list = yes read only = no ignore errors = yes hosts allow = * #一般填写同步端的IP hosts deny = *
5.同步端的sersync服务的检测脚本(#这部分直接引用网络上的):
cat ./check_sersync.sh #!/bin/bash SERSYNC="/usr/local/sersync/sersync2" CONF_FILE="/usr/local/sersync/confxml.xml" STATUS=$(ps aux |grep ‘sersync2‘|grep -v ‘grep‘|wc -l) if [ $STATUS -eq 0 ]; then $SERSYNC -d -r -o $CONF_FILE & else exit 0; fi
*/5 * * * * /root/check_sersync.sh > /dev/null 2>&1
标签:
原文地址:http://my.oschina.net/jk409/blog/407330