sersync实时同步
官网: https://code.google.com/archive/p/sersync/
安装
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz
tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
mv GNU-Linux-x86/ /usr/local/sersync
ln -s /usr/local/sersync/sersync2 /usr/bin/
配置文件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"/> <!-- 属性也同步 true为开启 false为关闭-->
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/home/bakup"> <!-- 本地服务器的同步目录 -->
<remote ip="11.7.171.36" name="/home/data_test"/> <!-- 本机需要和远程机器配置免密,远程机器的ip和同步到到目录地址 -->
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="false" users="root" passwordfile="/etc/rsync.pas"/> <!-- 我这里使用的shell同步不用配置sync 这里为false 不用改 -->
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="true"/> <!-- 这里需要启用 使用的是ssh同步 -->
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="false" schedule="600"><!--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>
启动sersync脚本
cat > /etc/init.d/sersync << EOF
#!/bin/bash
exispid() {
pidcount=$(ps -ef |grep sersync2 |grep -v grep |wc -l )
if [ $pidcount -eq 0 ];then
return 0 # 没运行返回0
else
return 1 # 运行返回1
fi
}
sersync_start() {
exispid
if [ $? -eq 0 ];then
/usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml >/dev/null 2>&1
echo -e "start sersync \t\t\t\t\t\t\t\t \033[32m [ OK ] \033[0m"
else
echo "sersync is runing!"
fi
}
sersync_stop() {
exispid
if [ $? -eq 0 ];then
echo "sersync is stop!"
else
kill -9 `ps -ef |grep sersync |grep -v grep |awk '{print $2}'` >/dev/null 2>&1
echo -e "stop sersync \t\t\t\t\t\t\t\t \033[32m [ OK ] \033[0m"
fi
}
case $1 in
start )
sersync_start
;;
stop )
sersync_stop
;;
restart)
sersync_stop
sersync_start
;;
* )
echo "stop|start|restart|"
;;
esac
EOF
chmod +x /etc/init.d/sersync

浙公网安备 33010602011771号