Sersync部署

发布时间 2023-06-01 00:15:23作者: Junwu’sblog

确保rsync服务正确,c/s端

1.大前提Rsync Daemon服务正确
[root@nfs ~]# rsync -avz --delete /data/ rsync_backup@10.0.0.40::backup 

确保当前客户端机器,是否支持Inotify

[root@nfs ~]# ls /proc/sys/fs/inotify/
max_queued_events  max_user_instances  max_user_watches

Sersync安装

1.资料参考地址
谷歌项目地址:https://code.google.com/archive/p/sersync/

64位下载地址:https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz

32位下载地址:https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5_32bit_binary_stable_final.tar.gz

上不去google的可以直接wget我本地的包,这里只提供64位版本的:https://down.whsir.com/downloads/sersync2.5.4_64bit_binary_stable_final.tar.gz

压缩包里面有两个文件confxml.xml sersync2

sersync2 这个是sersync主程序

confxml.xml 这个是sersync配置文件
2.下载获取sersync软件包,上传至linux
[root@nfs ~]# tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz -C sersync2.5.4
GNU-Linux-x86/
GNU-Linux-x86/sersync2
GNU-Linux-x86/confxml.xml
3.检查sersync文件执行权限
[root@nfs GNU-Linux-x86]# ll
total 1772
-rwxr-xr-x. 1 root root    2214 Oct 25  2011 confxml.xml
-rwxr-xr-x. 1 root root 1810128 Oct 26  2011 sersync2

Sersync配置文件

## 配置文件参数解释
# sersync的过滤功能,排除指定的文件不复制
<?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>
# 指定监控事件,也就是触发监控管理的事件,true开启,false关闭
    <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主要功能模块
    <sersync>
#监控的目录 <localpath watch="/opt/tongbu"> # 填写rsync同步服务端ip地址,以及同步的模块名,支持复制到多台服务器 <remote ip="127.0.0.1" name="tongbu1"/> <!--<remote ip="192.168.8.39" name="tongbu"/>--> <!--<remote ip="192.168.8.40" name="tongbu"/>--> </localpath> # 配置rsync的信息 <rsync> # 命令的参数 <commonParams params="-artuz"/> # 填写rsync服务端验证的账号,密码文件 <auth start="false" users="root" passwordfile="/etc/rsync.pas"/> <userDefinedPort start="false" port="874"/><!-- port=874 --> <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="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>
        <localpath watch="/data">    #指定要监控的本地目录
            <remote ip="10.0.0.40" name="backup"/>    #指定要同步的目标服务器的IP地址,及目标服务器rsync的[模块]
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            <commonParams params="-artuz"/>    #rsync的参数
            <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>    #是否开启rsync的认证模式,需要配置users及passwordfile,根据情况开启(如果开启,注意密码文件权限一定要是600)
            <userDefinedPort start="false" port="874"/><!-- port=874 -->
            <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-->

Sersync部署应用

1.使用绝对路径查看sersync命令帮助
[root@nfs ~]# ~/sersync2.5.4/GNU-Linux-x86/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参数,则默认执行同步程序
________________________________________________________________
2.生成sersync命令快捷键
[root@nfs ~]# ln -s /sersync2.5.4/sersync2 /usr/local/bin/
[root@nfs ~]# sersync2 -h

这里有个坑:配置临时环境变量,为什么sersync命令不生效

 sersync软件服务开启,命令如下:

[root@nfs ~]# sersync -r -d -o /sersync2.5.4/
confxml.xml  sersync      
[root@nfs ~]# sersync -r -d -o /sersync2.5.4/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: -r     rsync all the local files to the remote servers before the sersync work
option: -d     run as a daemon
option: -o     config xml name:  /sersync2.5.4/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost    host port: 8008
daemon start,sersync run behind the console 
use rsync password-file :
user is    rsync_backup
passwordfile is     /etc/rsync.password
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 -artuz -R --delete ./ rsync_backup@10.0.0.40::backup --password-file=/etc/rsync.password >/dev/null 2>&1 
run the sersync: 
watch path is: /data

部署测试: