Sync2 sync notify自动同步
Sync2
主存储
1、安装
tar xf sersync_64bit_binary_stable_final.tar.gz
改名(随意改)
mv GNU-Linux-x86/ /data/svr/rsyncd
2、编辑配置文件
[root@ww1 rsyncd]# vim confxml.xml
<?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>
<?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="true"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="true"/>
</inotify>
<sersync>
<localpath watch="/data/pep"> #监控的本地目录
<remote ip="192.168.122.11" name="data/pep"/> #远程的ip name:远程 rsyncd.conf 的模块名称(看颜色一样的位置)
#服务器就会去客户端的 data 模块中的路径下去找pep这个目录 这里的data不是目录名字,是服务器配置文件中的模块名字
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync> #启用rsync命令的参数(数否需要认证)
<commonParams params="-artuz"/>
<auth start="true" users="rsync" passwordfile="/data/svr/rsyncd/rsync.password"/> 用户名,和密码(如果启用上面name里面的模块,使用的用户名和密码就不用单独在系统上设置了。)
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync> #启用rsync命令的参数(数否需要认证)
<commonParams params="-artuz"/>
<auth start="true" users="rsync" passwordfile="/data/svr/rsyncd/rsync.password"/> 用户名,和密码(如果启用上面name里面的模块,使用的用户名和密码就不用单独在系统上设置了。)
#这个文件的权限要是600
#格式: ABCD (直接写密码)
<userDefinedPort start="true" port="837"/><!-- port=874 --> 对应的端口
<timeout start="false" time="900"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="true" schedule="600"><!--600mins--> #是否启用完整的rsync
<crontabfilter start="false">
#设置完整执行rsync是的过滤条件
<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>
<timeout start="false" time="900"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="true" schedule="600"><!--600mins--> #是否启用完整的rsync
<crontabfilter start="false">
#设置完整执行rsync是的过滤条件
<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>
3、启动服务器端:(先启动客户端再启动服务器端)
[root@ww2 sryncd]# ./sersync2 -d -o confxml.xml
为了防止这个进程当掉,可以写个脚本在自动任务里检查一下
#!/bin/bash
LOGFILE="/opt/syncd/check_sersync.log"
SERSYNC="/opt/syncd/sersync2"
CONF_FILE="/opt/syncd/confxml.xml"
STATUS=$(ps -ef | grep 'sersync2' | grep -v 'grep' | grep "confxml.xml" | wc -l )
if [ ${STATUS} -eq 0];
then
${SERSYNC} -d -o ${CONF_FILE} &
echo "`date "+%F %H:%M:%S"` Running confxml.xml script " >> ${LOGFILE}
else
exit 0
fi
4、备份存储
新建一个文件,这个文件不存在需要创建:
vim /etc/rsyncd.conf
use chroot = no
uid = root
gid = root
strict modes = no
port = 837 #这个端口要和主存储的链接端口对应
motd file = /data/logs/rsync/welcome.msg
pid file = /data/logs/rsync/rsync.pid
lock file = /data/logs/rsync/rsync.lock
log file = /data/logs/rsync/rsync.log
[data] #这里就对应着服务器端的红色位置,<remote ip="192.168.122.11" name="data/pep"/>
commect = data
max connections = 10
path = /data/ #主存储就会到这个目录下找 pep这个目录同步
ignore errors = yes
read only = no
write only = no
hosts allow = *
auth users = rsync
secrets file = /etc/rsync.scrt #这个文件存储这密码,要和主存储密码相同,并且权限时 600
list = true
transfer logging = yes
log format = "%a %f %l"
在创建秘钥文件
vim /etc/rsync.scrt
固定格式
rsync:ABCD
设置rsync.scrt 文件的访问权限
chown root.root rsyncd.secrets
chmod 600 rsyncd.secrets
chown root.root rsyncd.secrets
chmod 600 rsyncd.secrets
5.启动服务:
rsync --daemon --config /etc/rsyncd.conf
6.开机启动vi /etc/rc.local添加:rsync --daemon --config /etc/rsyncd.conf
客户端已经驱动,添加开机
服务端还没有启动 测试传输
6、注意
在第一次启动前,如果所同步的目录下已经有文件了,这个默认不会同步。所以要手动执行一下,随后产生的文件就会自动同步了。
[root@ww2 sryncd]# ./sersync2 -r


浙公网安备 33010602011771号