下载sersync 包 https://code.google.com/p/sersync/
说明:例如A为服务器,B为备份服务器,现在想要A上跟新文件,B上马上进行同步,需要在A上安装sersync, B上安装rsync服务器。且B上的rsync服务必须为domain实时监听(可以开启xinetd服务添加rsync进行实时监听)。
A服务器:
(1)软件安装
[root@NBX1 ~]# tar xvf sersync2.5_64bit_binary_stable_final.tar.gz
[root@NBX1 ~]# cd GNU-Linux-x86/
[root@NBX1 GNU-Linux-x86]# mkdir /etc/sersync2/
[root@NBX1 GNU-Linux-x86]# cp confxml.xml /etc/sersync2/
[root@NBX1 GNU-Linux-x86]# cp sersync2 /usr/bin/
(2)创建密码文件
[root@NBX1 ~]# mkdir -p /etc/rsyncd/
[root@NBX1 rsyncd]# touch /etc/rsyncd/rsyncd.secrets
[root@NBX1 rsyncd]# chmod 600 /etc/rsyncd/rsyncd.secrets
[root@NBX1 rsyncd]# cat /etc/rsyncd/rsyncd.secrets
123456
(3)配置
[root@NBX1 ~]# vi /etc/sersync2/confxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="true"/> 想看到传输信息设置为true
<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="false"/> 如果想增量同步设置为false,想实时备份设置为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="/NBX/spool/monitor"> 定义要同步的目录
<remote ip="1.1.1.7" name="luyin"/> 设置B服务器即备份服务器的地址 设置B服务器共享目录的名称
<!--<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="root" passwordfile="/etc/rsyncd/rsyncd.secrets"/> 打开密码认证 并制定密码文件
<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>
(4)开启服务
[root@NBX1 rsyncd]# sersync2 -r -d -o /etc/sersync2/confxml.xml
B 备份服务器要做的:
(1)安装rsync
yum -y install rsync
(2)配置rsync客户端
[root@backserver ~]# cat /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
[root@backserver ~]# chkconfig --list |grep rsync 开机启动
rsync: on
[root@backserver ~]# touch /etc/rsyncd.conf
[root@backserver ~]# touch /etc/rsyncd.motd
[root@backserver ~]# touch /etc/rsyncd.secrets
[root@backserver ~]# chmod 600 /etc/rsyncd.secrets 设置权限
[root@backserver ~]# cat /etc/rsyncd.secrets 设置密码
root:123456
[root@backserver ~]# ll /etc/rsyncd.secrets
-rw------- 1 root root 12 Jan 25 16:57 /etc/rsyncd.secrets
配置:
[root@backserver ~]# vi /etc/rsyncd.conf
motd file = /etc/rsyncd.motd
uid=root
gid=root
max connections = 36000
use chroot=yes
read only=no
log file=/var/log/rsyncd.log
log format = %t %a %m %f %b
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
timeout = 300
[xinshen_luyin]
path=/opt/local/luyin
list=yes
comment = backup luyin ...
hosts allow = 192.168.9.8
hosts deny = *
auth users=root
secrets file=/etc/rsyncd.secrets