linux系统安装rsync和sersync实现数据实时同步详细步骤(rsync实时同步)(3)
sysctl -w fs.inotify.max_queued_events="99999999"
sysctl -w fs.inotify.max_user_watches="99999999"
sysctl -w fs.inotify.max_user_instances="65535"
参数说明:
max_queued_events:
inotify队列最大长度,如果值太小,会出现"** Event Queue Overflow **"错误,导致监控文件不准确
max_user_watches:
要同步的文件包含多少目录,可以用:find /home/www.jb51.net -type d | wc -l 统计,必须保证max_user_watches值大于统计结果(这里/home/www.jb51.net为同步文件目录)
max_user_instances:
每个用户创建inotify实例最大值
3、安装sersync
sersync下载地址:https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz
上传sersync2.5.4_64bit_binary_stable_final.tar.gz到/usr/local/src目录下
cd /usr/local/src
tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz #解压
mv GNU-Linux-x86 /usr/local/sersync #移动目录到/usr/local/sersync
4、配置sersync
cd /usr/local/sersync #进入sersync安装目录
cp confxml.xml confxml.xml-bak #备份原文件
vi 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>
<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/www.jb51.com">
<remote ip="192.168.21.127" name="home_www.jb51.net"/>
<remote ip="192.168.21.128" name="home_www.jb51.net"/>
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="home_www.jb51.net_user" passwordfile="/etc/rsync.pas"/>
<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="true" 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="<a href="http://pic.xoyo.com/cms"/">http://pic.xoyo.com/cms"/</a>>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>
:wq! #保存退出
参数说明:
localpath watch="/home/www.jb51.net":#源服务器同步目录
192.168.21.127,192.168.21.128:#目标服务器IP地址
name="home_www.jb51.net": #目标服务器rsync同步目录模块名称
users="home_www.jb51.net_user": #目标服务器rsync同步用户名
passwordfile="/etc/passwd.txt": #目标服务器rsync同步用户的密码在源服务器的存放路径
remote ip="192.168.21.127": #目标服务器ip,每行一个
remote ip="192.168.21.128": #目标服务器ip,每行一个
failLog path="/tmp/rsync_fail_log.sh" #脚本运行失败日志记录
start="true" #设置为true,每隔600分钟执行一次全盘同步
5、设置sersync监控开机自动执行
vi /etc/rc.d/rc.local #编辑,在最后添加一行