声明:同步顺序,sersync向rsync同步
一.配置rsync服务端(192.168.233.202)
1.安装rsync软件
# yum installrsync
2.手动创建rsync配置文件
# vim/etc/rsyncd.conf
#---------------------全局配置------------------
uid = root
gid = root
usechroot = no
max connections= 20
timeout = 600
pid file =/var/run/rsyncd.pid
lock file =/var/run/rsync.lock
log file =/var/log/rsyncd.log
ignore errors
read only =false
writeonly =false
list =false
hosts allow = *
hosts deny =0.0.0.0/32
auth users =backuser
secrets file =/etc/rsync.password
#---------------------模块配置---------------------------
[web_log]
path =/data/web_log/
[mnt]
path = /data/mnt/
3.创建备份目录
# mkdir -p/data/web_log/
# mkdir -p/data/mnt/
4.建立 rsync 用户名和密码文件
# echo "backuser:123">> /etc/rsync.password #backuser:123前不能有空格
5.为/etc/rsync.password授权为 600(这个文件的权限必须是 600)
# chmod 600/etc/rsync.password
6.启动rsync并添加开启自动启动
# /usr/bin/rsync--daemon &
# echo "/usr/bin/rsync--daemon" >> /etc/rc.local
二.配置sersync客户端,不用安装rsync软件
1.设置 rsync 客户端的密码文件,客户端只需要设置 rsync 同步的密码即可,不用设置用户名
# echo "123" >/etc/rsync.password 配置本地连接rsync的密码,123前不能有空格
2.将密码文件的权限设置成600(这个文件的权限必须是600)
# chmod 600 /etc/rsync.password
3.安装sersync软件包
# wgethttp://sersync.googlecode.com/files/sersync2.5_32bit_binary_stable_final.tar.gz
注:若在64位平台安装则可下载64位sersync源码包,本例用32位
# wgethttp://sersync.googlecode.com/files/sersync2.5_64bit_binary_stable_final.tar.gz
# tar xvfsersync2.5_64bit_binary_stable_final.tar.gz
# mkdir /usr/local/sersync
# mv GNU-Linux-x86/*/usr/local/sersync/
# cd /usr/local/sersync/
# cp confxml.xml mntxml.xml #复制启动文件,以便启动2个模块
修改第一个模块的配置文件
# vim confxml.xml //红色部分都需要修改
<?xmlversion="1.0"encoding="ISO-8859-1"?>
<head version="2.5">
<hosthostip="localhost" port="8008"></host> #第一个配置文件端口可以不修改
<debugstart="false"/>
<fileSystemxfs="false"/>
<filterstart="false">
<excludeexpression="(.*)\.svn"></exclude>
<excludeexpression="(.*)\.gz"></exclude>
<excludeexpression="^info/*"></exclude>
<excludeexpression="^static/*"></exclude>
</filter>
<inotify>
<deletestart="true"/>
<createFolderstart="true"/>
<createFilestart="false"/>
<closeWritestart="true"/>
<moveFromstart="true"/>
<moveTostart="true"/>
<attribstart="false"/>
<modifystart="false"/>
</inotify>
<sersync>
<localpathwatch="/opt"> #本地需要同步的目录
<remoteip="192.168.233.202" name="web_log"/> #远程端服务ip,模块
<!--<remoteip="192.168.8.40" name="tongbu"/>-->
<!--<remoteip="192.168.8.40"name="tongbu"/>-->
</localpath>
<rsync>
<commonParamsparams="-artuz"/>
<authstart="ture" users="backuser" passwordfile="/etc/rsync.password"/> #修改连接的用户名和密码
<userDefinedPortstart="false"port="874"/><!-- port=874 -->
<timeoutstart="false"time="100"/><!-- timeout=100 -->
<sshstart="false"/>
</rsync>
<failLogpath="/tmp/rsync_fail_log.sh"timeToExecute="60"/><!--defaultevery 60mins execute once-->
<crontabstart="false"schedule="600"><!--600mins-->
<crontabfilterstart="false">
<excludeexpression="*.php"></exclude>
<excludeexpression=\'#\'" /*"></exclude>
</crontabfilter>
</crontab>
<pluginstart="false" name="command"/>
</sersync>
<pluginname="command">
<paramprefix="/bin/sh"suffix=""ignoreError="true"/> <!--prefix/opt/tongbu/mmm.sh suffix-->
<filterstart="false">
<includeexpression="(.*)\.php"/>
<includeexpression="(.*)\.sh"/>
</filter>
</plugin>
<pluginname="socket">
<localpathwatch="/opt/tongbu">
<deshostip="192.168.138.20"port="8009"/>
</localpath>
</plugin>
<pluginname="refreshCDN">
<localpathwatch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfodomainname="ccms.chinacache.com"port="80"username="xxxx" passwd="xxxx"/>
<sendurlbase="http://pic.xoyo.com/cms"/>
<regexurl regex="false"match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>
修改第二个模块的配置文件
# vim mntxml.xml //红色部分都需要修改
<?xmlversion="1.0"encoding="ISO-8859-1"?>
<head version="2.5">
<hosthostip="localhost" port="8009"></host> #第二个端口要修改,否则跟上一个冲突
<sersync>
<localpathwatch="/mnt"> #本地需要同步的目录
<remoteip="192.168.233.202" name="mnt"/> #远程端服务ip,模块
<!--<remoteip="192.168.8.40" name="tongbu"/>-->
<!--<remoteip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParamsparams="-artuz"/>
<authstart="ture" users="backuser" passwordfile="/etc/rsync.password"/> #修改连接的用户名和密码
<userDefinedPortstart="false"port="874"/><!-- port=874 -->
<timeoutstart="false"time="100"/><!-- timeout=100 -->
<sshstart="false"/>
</rsync>
分别启动sersync守护进程
#/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml
#/usr/local/sersync/sersync2 -d -r -o/usr/local/sersync/mntxml.xml