集群05-sersync工具实现实时复制到backup备份服务器
1、下载sersync
[root@nfs01 ~]# cd/usr/local/src/
[root@nfs01 src]# wget https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz
2、解压并重命名
[root@nfs01 src]# tar -zxvfsersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs01 src]# mv GNU-Linux-x86/ sersync
首先进行目录规划
[root@nfs01 src]# tree sersync
sersync
├── bin
│ └── sersync2
├── conf
│ └── confxml.xml
├── confxml.xml.bak
└── log
└──rsync_fail_log.sh(根据配置文件自动生成的)
3、配置sersync
[root@nfs01 src]# cd sersync
[root@nfs01 sersync]# cp confxml.xml confxml.xml.bak
[root@nfs01 sersync]# vim confxml.xml
<?xml version="1.0"encoding="ISO-8859-1"?>
<head version="2.5">
<hosthostip="localhost" port="8008"></host>
<debugstart="false"/>
<fileSystemxfs="false"/>
<filterstart="false"> #过滤规则,默认false不开启
<excludeexpression="(.*)\.svn"></exclude>
<excludeexpression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<excludeexpression="^static/*"></exclude>
</filter>
<inotify> #inotify事件监控
<deletestart="true"/>
<createFolderstart="true"/>
<createFilestart="false"/>
<closeWritestart="true"/>
<moveFromstart="true"/>
<moveTostart="true"/>
<attribstart="false"/>
<modifystart="false"/>
</inotify>
<sersync> #sersync配置
<localpathwatch="/data/">#同步目录
<remote ip="172.16.1.41" name="backup"/>#rsync服务器ip,name为模块
<!--<remoteip="192.168.8.39" name="tongbu"/>-->
<!--<remoteip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync> #rsync配置
<commonParams params="-artuz"/>#rsync参数,如可改为-avz
<auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/> #rsync用户名和密码文件
<userDefinedPort start="false"port="874"/><!-- port=874 --> #rsync端口
<timeout start="true"time="100"/><!-- timeout=100 --> #rsync超时时间
<ssh start="false"/>
</rsync>
<failLogpath="/tmp/rsync_fail_log.sh"timeToExecute="60"/><!--default every 60mins execute once--> #日志存放位置
<crontabstart="true"schedule="600"><!--600mins--> #定时任务
<crontabfilterstart="false">
<excludeexpression="*.php"></exclude>
<excludeexpression="info/*"></exclude>
</crontabfilter>
</crontab>
<pluginstart="false" name="command"/>
</sersync>
<pluginname="command">
<paramprefix="/bin/sh" suffix=""ignoreError="true"/> <!--prefix/opt/tongbu/mmm.sh suffix-->
<filterstart="false">
<includeexpression="(.*)\.php"/>
<includeexpression="(.*)\.sh"/>
</filter>
</plugin>
<pluginname="socket">
<localpathwatch="/opt/tongbu">
<deshost ip="192.168.138.20"port="8009"/>
</localpath>
</plugin>
<pluginname="refreshCDN">
<localpathwatch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfodomainname="ccms.chinacache.com" port="80"username="xxxx" passwd="xxxx"/>
<sendurlbase="http://pic.xoyo.com/cms"/>
<regexurl regex="false"match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>
4、启动sersync2
[root@nfs01 sersync]# bin/sersync2 -d -r -n 8 -oconf/confxml.xml
-d:后台运行
-r:启动时,同步一次
-n:进程数
-o:指定配置文件
5、开机启动
[root@nfs01 /]# vim /etc/rc.local
添加内容:
/usr/local/src/sersync/bin/sersync2 -d -r -n 8 -o/usr/local/src/sersync/conf/confxml.xml