sersync部署

1.下载安装inotify-tools

[root@nfs /usr/local]# yum install -y inotify-tools

2.下载安装sersync

[root@nfs /usr/local]# wget https://github.com/wsgzao/sersync/blob/master/sersync2.5.4_64bit_binary_stable_final.tar.gz

3.解压sersync包

[root@nfs /usr/local]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs /usr/local]# mv GNU-Linux-x86 sersync

4.配置sersync

[root@nfs sersync]# cat confxml.xml

需要改的地方:
 12     <inotify>
 13         <delete start="true"/>
 14         <createFolder start="true"/>
 15         <createFile start="true"/>
 16         <closeWrite start="true"/>
 17         <moveFrom start="true"/>
 18         <moveTo start="true"/>
 19         <attrib start="true"/>
 20         <modify start="true"/>
 21     </inotify>

 23     <sersync>
 24         <localpath watch="/data">
 25             <remote ip="172.16.1.41" name="data"/>


 28         </localpath>
 29         <rsync>
 30             <commonParams params="-az"/>
 31             <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.passwd"/>





所有配置:
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>                                                          #调试模式
<fileSystem xfs="true"/>                                                        #Centos7默认是xfs文件系统,要开启
<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="true"/>
    <closeWrite start="true"/>
    <moveFrom start="true"/>
    <moveTo start="true"/>
    <attrib start="true"/>
    <modify start="true"/>
</inotify>

<sersync>
    <localpath watch="/data">                                                   #监控上面变化的目录
        <remote ip="172.16.1.41" name="data"/>                                  #变化后传到的目的模块
        <!--<remote ip="192.168.8.39" name="tongbu"/>-->
        <!--<remote ip="192.168.8.40" name="tongbu"/>-->
    </localpath>                
    <rsync>
        <commonParams params="-az"/>                                            #rsync执行时加的参数
        <auth start="true" users="rsync_backup" passwordfile="/etc/password"/>          #虚拟用户和虚拟用户的密码
        <userDefinedPort start="false" port="874"/><!-- port=874 -->
        <timeout start="true" time="100"/><!-- timeout=100 -->                  #超时时间
        <ssh start="false"/>                                                    #ssh协议是否开启,走rsync协议,所以不需要
    </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">
    <filter start="false">
    </filter>
<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>

5.查看sersync参数

[root@nfs /usr/local]# /usr/local/sersync/sersync2 -h
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
_______________________________________________________
参数-d:启用守护进程模式
参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
c参数-n: 指定开启守护线程的数量,默认为10个
参数-o:指定配置文件,默认使用confxml.xml文件
参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
参数-m:单独启用其他模块,使用 -m socket 开启socket模块
参数-m:单独启用其他模块,使用 -m http 开启http模块
不加-m参数,则默认执行同步程序

6.启动sersync

[root@nfs /usr/local]# /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml 

set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d  run as a daemon
option: -r  rsync all the local files to the remote servers before the sersync work
option: -o  config xml name:  /usr/local/sersync/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
will ignore the inotify createFile event 
daemon start,sersync run behind the console 
use rsync password-file :
user is rsync_backup
passwordfile is     /etc/rsync.passwd
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) 
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /data && rsync -az -R --delete ./ [email protected]::data --password-file=/etc/rsync.passwd >/dev/null 2>&1 
run the sersync: 
watch path is: /data

7.测试文件实时同步

[root@backup /data]# ll upload
total 16
-rw-r--r--. 1 www www 22 Sep  9 09:07 11_lhd_nfs.txt
-rw-r--r--. 1 www www 22 Sep  9 09:30 22_lhd_nfs.txt
-rw-r--r--. 1 www www 22 Sep  9 11:31 333_lhd_nfs.txt
-rw-r--r--. 1 www www 22 Sep  9 11:34 44_lhd_nfs.txt

8.监控多个目录实时同步

[root@nfs /usr/local/sersync]# cp confxml.xml confxml1.xml
[root@nfs /backup]# ps -ef | grep sersync
root       4321      1  0 12:05 ?        00:00:00 /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml
root       4374      1  0 12:08 ?        00:00:00 /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml1.xml

猜你喜欢

转载自www.cnblogs.com/skyy/p/12331659.html
今日推荐