Sersync+Rsync实时复制项目实践

>>>Inotify-tools+Rsync实时复制项目实践<<<

1.环境准备

backup服务器:安装rsync并以daemon的方式启动服务。参考文章:rsync配置

数据服务器:安装rsync、Sersync。

2.安装Sersync

下载地址:https://code.google.com/archive/p/sersync/downloads

或者:https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz

解压后会有如下两个文件

[root@Ansible sersync]# ll
total 1772
-rwxr-xr-x. 1 root root 2218 Mar 2 21:39 confxml.xml #配置文件
-rwxr-xr-x. 1 root root 1810128 Oct 26 2011 sersync2 #命令工具

3.配置文件confxml.xml

[root@Ansible sersync]# cat 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="true"/> #文件系统如果是xfs格式,请改为true
<filter start="false"> #排除不同步的文件
...
</filter>
<inotify> #可记录的事件动作
<delete start="true"/>
<createFolder start="true"/>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/root/data"> #监控的目录
<remote ip="192.168.244.139" name="test"/> #rsync服务器的地址以及同步的模块名字
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-avz"/> #rsync同步的参数
<auth start="true" users="backup" passwordfile="/etc/rsyncd.passwd"/> #同步的虚机账号以及密码文件,auth start改为true
<userDefinedPort start="false" port="874"/><!-- port=874 --> #rsync服务端口号
<timeout start="false" time="100"/><!-- timeout=100 --> #超时参数
<ssh start="false"/> #支持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">
...
</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.命令参数

[root@Ansible sersync]# ./sersync2 -o confxml.xml
-d:守护进程模式
-r:监控之前,将监控目录先同步一遍
-n:开始守护线程数量,默认10个
-o:指定配置文件,默认使用confxml.xml
-m:指定模块,默认为同步
如果需要同时监控多个目录,配置多个文件即可,如:
./sersync2 -o confxml2.xml
./sersync2 -o confxml3.xml

5.服务启动脚本

>>>服务启动脚本<<<


「 文章如果对你有帮助,请点个赞哦^^ 」 

0