免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1046 | 回复: 0
打印 上一主题 下一主题

[系统安装] 为什麽Sersync不能同步 [复制链接]

求职 : Linux运维
论坛徽章:
203
拜羊年徽章
日期:2015-03-03 16:15:432015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:57:092015小元宵徽章
日期:2015-03-06 15:58:182015年亚洲杯之约旦
日期:2015-04-05 20:08:292015年亚洲杯之澳大利亚
日期:2015-04-09 09:25:552015年亚洲杯之约旦
日期:2015-04-10 17:34:102015年亚洲杯之巴勒斯坦
日期:2015-04-10 17:35:342015年亚洲杯之日本
日期:2015-04-16 16:28:552015年亚洲杯纪念徽章
日期:2015-04-27 23:29:17操作系统版块每日发帖之星
日期:2015-06-06 22:20:00操作系统版块每日发帖之星
日期:2015-06-09 22:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-02-14 08:20 |只看该作者 |倒序浏览
我按照下面的教程来做的,但是运行/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml 这句话没有反应



Sersync实现触发式文件同步 替代inotify和rsync


服务器端
1、安装rsync  两边都要做
yum install -y rsync
vi /etc/rsyncd.conf #服务器端
port=873
log file=/var/log/rsync.log
pid file=/var/run/rsyncd.pid
#address=192.168.0.10
max connections=10
timeout = 300
[webbak]
path=/tmp/www/wordpress
use chroot=true
read only=no
list=false
uid=root
gid=root
#auth users=test
#secrets file=/etc/rsyncd.passwd
hosts allow=192.168.1.109
#hosts deny = 0.0.0.0/32

echo "rsync --daemon" >>/etc/rc.local
#启动服务
rsync --daemon


2、安装Inotify-tools工具,实时触发rsync进行同步
两边机器都要做
安装inotify-tools
yum install -y make gcc gcc-c++
cd /mydata/download/
wget -c http://github.com/downloads/rvoi ... y-tools-3.14.tar.gz
tar zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
mkdir -p /usr/local/inotify
./configure --prefix=/usr/local/inotify
make
make install
设置系统环境变量,添加软连接
echo "PATH=$PATH:/usr/local/inotify/bin" >>/etc/profile.d/inotify.sh
source /etc/profile.d/inotify.sh #使设置立即生效
echo "/usr/local/inotify/lib" >/etc/ld.so.conf.d/inotify.conf && ldconfig
ln -s /usr/local/inotify/include /usr/include/inotify
修改inotify默认参数(inotify默认内核参数值太小)
vi /etc/sysctl.conf
fs.inotify.max_queued_events=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535
/sbin/sysctl -p





客户端

3、安装配置sersync
cd /download
wget -c http://files.cnblogs.com/files/M ... stable_final.tar.gz
tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
mv GNU-Linux-x86 /usr/local/sersync
vi /usr/local/sersync/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="(.*)\wp-config.php"></exclude>
<!-- <exclude expression="(.*)\.gz"></exclude>-->
<!-- <exclude expression="^info/*"></exclude>-->
</filter>
<inotify>
<delete start="true"/>
<createFolder start="true"/>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="true"/>
<modify start="true"/>
</inotify>

<sersync>
<localpath watch="/tmp/www/wordpress">
<remote ip="192.168.1.106" name="webbak"/>
<!--<remote ip="192.168.1.12" name="tongbu"/>-->
<!--<remote ip="192.168.1.13" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-az"/>
<auth start="false" users="root" 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/sersync_fail_log.sh" timeToExecute="60"/><!--default every 60min execute once-->
<crontab start="true" schedule="720"><!--720mins-->
<crontabfilter start="true">
<exclude expression="wp-config.php"></exclude>
<!--<exclude expression="*.gz"></exclude>-->
<!--<exclude expression="info/*"></exclude>-->
</crontabfilter>
</crontab>

</sersync>
</head>


将命令添加进/etc/rc.local,以后重启系统以后才能正常同步
vi /etc/rc.local
/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml

先测试一下rsync同步是否正常
rsync -av /tmp/yum_save_tx-2015-12-31-13-13x5anWV.yumtx 192.168.1.106::webbak



4、脚本监控sersync
因为有的时候sersync脚本会自动关掉,因此需要写一个脚本自动的去检测该进程是否存在,不存在就启动,脚本内容如下:
vi /root/check_sersync.sh
#!/bin/bash
#Purpose: Check sersync whether it is alive
#Author: steven
SERSYNC="/usr/local/sersync/sersync2"
CONF_FILE="/usr/local/sersync/confxml.xml"
STATUS=$(ps aux |grep 'sersync2'|grep -v 'grep'|wc -l)
if [ $STATUS -eq 0 ];
then
$SERSYNC -d -r -o $CONF_FILE &
else
exit 0;
fi

脚本写好以后,添加到计划任务中去
crontab -e
*/1 * * * * /bin/sh /root/check_sersync.sh > /dev/null 2>&1
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP