rsync+sersync实时同步

一、rsync服务端配置

1、安装rsync软件

##查看是否安装软件
rpm -qa rsync
##安装软件
yum install -y rsync

2、创建rsync虚拟用户

useradd -M -s /sbin/nologin rsync

3、编写/etc/rsyncd.conf配置文件

uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
ignore errors
list = false
read only = false
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
path = /backup

4、编写/etc/rsync.password认证文件,并修改权限

echo 'rsync_backup:zhengsy' > /etc/rsync.password
chmod 600 /etc/rsync.password

5、创建备份目录,并修改权限

mkdir /backup
chown -R rsync.rsync /backup

二、rsync客户端部署

1、创建密码文件,并修改权限

echo 'zhengsy' > /etc/rsync.password
chmod 600 /etc/rsync.password

2、测试rysnc传输文件

rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password

这里写图片描述

3、sersync软件安装

网址:https://sourceforge.net/projects/sersync/?source=navbar
unzip sersync_installdir_64bit.zip
cd sersync_installdir_64bit
mv sersync /usr/local/

4、编写配置文件

<?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>
    <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="/data">
            <remote ip="172.16.1.41" name="backup"/>
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            <commonParams params="-az"/>
            <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
            <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>

5、启动sersync

sersync -dro /usr/local/sersync/conf/confxml.xml

猜你喜欢

转载自blog.csdn.net/zsycsnd/article/details/81180675