centos 6.4 搭建rsync+sersync文件同步环境

发布时间:2020-12-17编辑:脚本学堂
本文介绍了在centos 6.4中搭建rsync+sersync文件同步环境的方法,有关rsync的用法,感兴趣的朋友参考下。

sersync原理是使用rsync命令推送同步的文件到rsync客户端。
优点是同步快,实时同步 使用资源少;
缺点是不只是双向实时同步,也就是说客户端新建文件不会同步到服务器端。

要实施双机实时同步的同学来说sersync不是一个好的办法。

sersync+rsync 客户端IP为192.168.16.130 服务器IP为192.168.16.128
实现目标:服务器端(推送端)/data/同步到客户端 /tmp/tongbu
客户端(只有rsync)配置
 

复制代码 代码示例:
yum -y install rsync

vi /etc/rsyncd.conf
 

复制代码 代码示例:
uid=root
gid=root
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/log/rsyncd.pid
lock file=/var/log/rsyncd.lock
[data]                     #rsync模块名,后面配置sersync会用到
path=/tmp/tongbu            #该同步目录只要uid所指定的用户有写权限即可
comment = website files
ignore errors = yes
read only = no
hosts allow = 192.168.16.0/24
#hosts deny = *
auth users = user
secrets file = /etc/rsync.pas

mkdir /tmp/tongbu
vi /etc/rsync.pas
 

复制代码 代码示例:
user:123456
chmod 600 /etc/rsync.pas
rsync --daemon --config=/etc/rsyncd.conf

服务器端配置
 

复制代码 代码示例:
yum -y install rsync
cd /usr/src
tar fzxv sersync.tar.gz
mkdir /usr/local/sersync
mkdir /usr/local/sersync/conf
mkdir /usr/local/sersync/bin
mkdir /usr/local/sersync/log
cd GNU-linux-x86/
cp confxml.xml /usr/local/sersync/conf/
cp sersync2 /usr/local/sersync/bin/
cp /usr/src/GNU-Linux-x86/sersync2 /bin/

vi /etc/rsync.pas
123456
chmod 600 /etc/rsync.pas
cd /usr/local/sersync/conf/
vi confxml.xml
 

复制代码 代码示例:

<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="192.168.16.128" 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="true"/>
        <closeWrite start="true"/>
        <moveFrom start="true"/>
        <moveTo start="true"/>
        <attrib start="true"/>
        <modify start="true"/>
    </inotify>

    <sersync>
        <localpath watch="/data">    #  要修改的
            <remote ip="192.168.16.130" name="data"/>  #要修改的
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            <commonParams params="-artuz"/>
            <auth start="true" users="user" passwordfile="/etc/rsync.pas"/>#要修改的
            <userDefinedPort start="false" port="873"/><!-- 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='#'" /*"></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>

使用命令:
killall sersync2 && sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml