centos7 sersync 4台服务器数据互相同步配置

发布时间 2023-08-11 14:51:04作者: 记忆抹不去

4台服务器安装rsync并配置

#安装
yum install  rsync -y

#配置
vim /etc/rsyncd.conf

uid = root
gid = root
use chroot = no
hosts allow=*
max connections = 3
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
[record]
path = /record/
comment = record
read only = false

#密码配置文件
vim /etc/rsync.password

root:qwer!@#123

systemctl  restart  rsyncd
systemctl  enable   rsyncd

 

4台服务器安装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 -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz 

mv GNU-Linux-x86  /usr/local/sersync

cd  /usr/local/sersync 				
cp confxml.xml confxml.xml-bak 		
vim  confxml.xml   #注意修改有"#"注释的地方修改,修改完去掉#注释xml不是这种注释
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="pbx-master" port="8008"></host>  
    <debug start="false"/>
    <fileSystem xfs="true"/>  #支持xfs
    <filter start="false">
    <exclude expression="(.*)\.svn"></exclude>
    <exclude expression="(.*)\.gz"></exclude>
    <exclude expression="^info/*"></exclude>
    <exclude expression="^static/*"></exclude>
    </filter>
    <inotify>
    <delete start="false"/>     #flase 表示只增加不删除文件
    <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="/record/">    #同步路径
        <remote ip="pbx-slave" name="record"/>   #name="record" 这个表示模块名
        <remote ip="pbx2-master" name="record"/>
        <remote ip="pbx2-slave" name="record"/>
        <!--<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="root" passwordfile="/etc/rsync.passowrd"/>    #校验密码配置需要为true
        <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-->  #修改同步失败日志位置,并且每60分钟对失败的log进行重新同步
    <crontab start="true" 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>

 

#手动启动的命令
/usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml -n 2   #-n 2 cpu限制2核

 

#systemctl  管理
vim /usr/lib/systemd/system/sersync.service
[Unit]
Description=named start stop
After=syslog.target network.target

[Service]
ExecStart=/usr/local/sersync/sersync2 -ro /usr/local/sersync/confxml.xml -n 2
ExecStop=/bin/kill -s TERM $MAINPID
Restart=always #异常关闭尝试启动

[Install]
WantedBy=multi-user.target
systemctl  restart  sersync
systemctl  enable  sersync