sersync类似于inotify,同样用于监控,但它克服了inotify的几个缺点。本文记录sersync相关内容。
sersync主要用于服务器同步,web镜像等功能。基于boost1.43.0,inotify api,rsync command.开发。
鉴于 inotify 存在一定问题,后开发的工具 sersync 克服了inotify的几个缺点。
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz
tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
cp -a GNU-Linux-x86 /usr/local/sersync
echo "PATH=$PATH:/usr/local/sersync" > /etc/profile.d/sersync.sh
source /etc/profile.d/sersync.sh
$ ls /usr/local/sersync/
confxml.xml sersync2
vi /etc/selinux/config
修改下面一行代码:
SELINUX=disabled
运行此命令立即生效。
setenforce 0
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT
或者关闭防火墙
service iptables stop
chkconfig iptables off
yum install rsync
yum install rsync xinetd
vi /etc/xinetd.d/rsync
修改disable的值为no:
disable = no
启动xinetd(CentOS中是以xinetd来管理Rsync服务的)
/etc/init.d/xinetd start
chkconfig xinetd on
rsync --daemon --config=/etc/rsyncd.conf
echo "rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.local
vi /etc/rsyncd.conf
log file = /var/log/rsyncd.log
pidfile = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
secrets file = /etc/rsyncd.secret
motd file = /etc/rsyncd.motd
[test]
path = /home/xyz/
comment = test
uid = root
gid = root
incoming chmod = Du=rwx,Dog=rx,Fu=rwx,Fgo=rx
port=873
use chroot = no
read only = no
list = no
max connections = 200
timeout = 600
auth users = root
hosts allow = 192.168.1.103
hosts deny = *
目录权限(如果uid和gid都是root,这里不用操作):
cd /home
chown -hR root.root xyz/ #如果xyz目录是在root下新建的,默认就是root权限。
vi /etc/rsyncd.passwd
root:123456
保存退出
chmod 600 /etc/rsyncd.conf
chmod 600 /etc/rsyncd.passwd
/etc/init.d/xinetd start
参考指令
停止:service xinetd stop
启动: service xinetd restart
vi /etc/rsyncd.passwd
123456
保存退出
chmod 600 /etc/rsyncd.passwd
rsync -avzrtopgL --progress /root/ root@192.168.1.189::test/ --password-file=/etc/rsyncd.passwd
ll /proc/sys/fs/inotify
出现下面的内容、说明服务器内核支持inotify
-rw-r--r-- 1 root root 0 Dec 25 12:03 max_queued_events
-rw-r--r-- 1 root root 0 Dec 25 15:05 max_user_instances
-rw-r--r-- 1 root root 0 Dec 25 12:03 max_user_watches
备注:centos6.9默认支持inotify
sysctl -a | grep max_queued_events
sysctl -a | grep max_user_watches
sysctl -a | grep max_user_instances
修改参数
sysctl -w fs.inotify.max_queued_events="99999999"
sysctl -w fs.inotify.max_user_watches="99999999"
sysctl -w fs.inotify.max_user_instances="65535"
生效
sysctl -p
参数说明:
vi /etc/pam.d/login
session required /lib64/security/pam_limits.so
vi /etc/security/limits.conf
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
重启服务器
cd /usr/local/src
wget https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz
如果下载不了,用github这个
wget --no-check-certificate https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz
tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
mv GNU-Linux-x86 /usr/local/sersync
cd /usr/local/sersync
cp confxml.xml confxml.xml-bak
vi confxml.xml
设置如下代码:(如果需要同步多目录,就再建一个如confxmldata.xml,port端口8008不能冲突(测试好像不改也没关系),改成其他端口。localpath watch 改下,failLog path这个脚本文件也改下,每个xml文件中只保留自己的localpath watch )
<?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="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/home/xyz">
<remote ip="192.168.1.189" name="test"/>
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="root" passwordfile="/etc/rsyncd.passwd"/>
<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>
参数说明: