sersync同步配置

工作中,好多机子的数据都是一样的,手动给每个机子拷数据,很麻烦,也很浪费时间,于是就在网上搜到了这篇文章,也省去了使用crontab了,转载下:
sersync同步配置
两台测试机器ip:192.168.10.126 和192.168.134.54
操作系统类型:CentOS release 5.2
在服务器端192.168.10.126配置如下:
sersync包的下载地址:
http://sersync.googlecode.com/files/sersync2.4_32bit_binary.tar.gz
http://sersync.googlecode.com/files/sersync2.4_64bit_binary.tar.gz
tar -zxvf sersync2.4_32bit_binary.tar.gz
cd GNU-Linux-x86
里面有3个文件:
-rwxr-xr-x 1 root root    1220 Apr 7 03:05 confxml.xml
-rwxrwxrwx 1 root root       0 Apr 7 03:48 rsync_fail_log.sh
-rwxr-xr-x 1 root root 1494404 Apr 7 04:18 sersync2.4
根据自己的用途修改配置文件:vi confxml.xml (红色部分是我修改的ip及客户端rsync的名称)
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.2">
    <host hostip=" 192.168.10.126" port="8008"></host>
    <filter start="false">
        <exclude expression="(.*)\.gz"></exclude>
        <exclude expression="^info/*"></exclude>
    </filter>
    <sersync>
        <localpath watch="/opt/tongbu" debug="false">
            <remote ip=" 192.168.134.54" name="tongbu"/>
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
        </localpath>
        <rsyncauth start="flase" users="www" passwordfile="/etc/rsync.pas"/>
        <crontab start="false" schedule="600">
            <crontabfilter start="false">
                <exclude expression="*.php"></exclude>
                <exclude expression="info/*"></exclude>
            </crontabfilter>
        </crontab>
        <plugin start="false" name="refreshCDN"/>
    </sersync>
    <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>
    <plugin name="socket">
        <localpath watch="/opt/tongbu">
            <deshost ip="192.168.138.20" port="8009"/>
        </localpath>
    </plugin>
</head>
在服务器端192.168.134.54配置如下:
下载rsync源码包:rsync-3.0.7.tar.gz
tar -zxvf rsync-3.0.7.tar.gz
cd rsync-3.0.7 ; ./configure --prefix=/usr/local/rsync --disable-ipv6 ;make && make install
mkdir -p /opt/tongbu
vi /etc/rsyncd.conf
[tongbu]
path=/opt/tongbu
uid = root     //这个也很重要,否则会报错
comment = test
ignore errors = yes
read only = no
hosts allow = 192.168.10.126/24
hosts deny = *
启动rsync:
rsync --daemon
检查rsync是否起来:
lsof -i :873
COMMAND PID USER   FD   TYPE DEVICE SIZE NODE NAME
rsync   2625 root    4u IPv6   5662       TCP *:rsync (LISTEN)
rsync   2625 root    5u IPv4   5663       TCP *:rsync (LISTEN)
表示已经起来,返回空,表示没有起来
确保防火墙能使 tcp的873端口通过
至此,2台服务器的配置完毕,然后再10.126上启动sersync
cd GNU-Linux-x86
./sersync2.4 -r -d
看下192.168.10.126机器上的/opt/tongbu/目录下的文件是否同步到192.168.134.54 的/opt/tongbu/的目录下,如果有说明成功了!(我这样配置是成功的)同步的时间几乎是实时的,非常的棒!!!
说明:
sersync2.4 的选项:
-h 查看帮助文件
-r 在同步程序开启前,将整个路径跟远程服务器同步一遍
-d 开启守护进程模式在后台运行
-o 指定配置文件,如果不是默认的confxml.xml的情况下
-n 指定同步守护线程数量,默认为10个,适用于现在的4核服务器。如果需增加或减少使用 '-n 数量'
通常最常用的启动方法:
-m 值调用插件程序,不调用同步数据机制
./sersync2.4 -d -r
原作者网站:
http://code.google.com/p/sersync/

猜你喜欢

转载自zfsn.iteye.com/blog/1276737