Centos 6.3 x86_64 配置rsync+inotify

Centos 6.3 x86_64 配置rsync+inotify
一,inotify简介
Inotiy是一种强大的,细粒度的,异步的文件系统事件监控机制,linux内核从2.6.13版本起,加入了对inotify的支持。通过对inotify可以监控文件系统中添加、删除、修改、移动等各种细微事件,利用这个内核接口,第三方软件可以监控文件系统下文件的各种变化情况。
目前有inotify-tools,google开源项目Openduckbill,还有一个sersync由金山周洋开发并开源的。在监控事件变化的效率比inotify-tools高,至于高多少,可以参数这个网址http://blog.johntechinfo.com/sersyncguild。
二,实验效果图

Server是一个内容发布系统,后端采用负载均衡集群部署方案,由一个负载调试节点,多台服务节点组成。内容发布系节点负责将用户发布的数据生成静态页面,同时将静态网页传输给3个服务节点,负载调试器将用户请求根据负载算法调度到到相应的web节点上,实现用户访问。
三,配置serync,rsync配置参考http://bingodeng.blog.51cto.com/1038075/1180876
这里只做一些简单的修改,rsync使用系统自带的,如果没有可以使用yum安装。
1,先对web节点配置好rsync,web节点配置都一样
# vim /etc/rsyncd.conf 
uid=nobody
gid=nobody
use chroot=no
max connections=0
strict modes=yes
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
log file=/var/log/rsyncd.log
[test]
path=/data
comment=ixdba file
ignore errors
read only=no
write only=no
hosts allow =192.168.1.0/24
hosts deny=*
list=false
uid=root
gid=root
auth users=backup
secrets file=/etc/server.pass
# vim /etc/server.pass 
backup:ixdba123
#chmod 600 /e tc/server.pass
这次使用xinetd来控制rsync服务
#yum -y install xinetd
#chkconfig rsync on
#chkconfig xinetd on
#/etc/init.d/xinetd start
#netstat -tunlp |grep 873
tcp        0      0 :::873                      :::*        LISTEN     25340/xinetd 
2,配置sersync,配置比较简单,一个xml格式的配置文件和一个可执行文件。
# vim /etc/server.pass 
ixdba123
#chmod 600 /etc/server.pass
#tar xf sersync2.5.4.tar.gz -C /usr/local
#cd /usr/localGNU-Linux-x86
#vim config.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="true">  #默认过虑是关闭的,如果想开启改为true
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
    </filter>
    <inotify>    #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="/var/www">   #对本机哪个目录监控
    <remote ip="192.168.1.28" name="test"/>   #将/var/www目录的文件同步到rsync 模块test中,可以定义多个
    <!--<remote ip="192.168.8.39" name="tongbu"/>-->
    <!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
    <commonParams params="-artuz"/>   #rsync命令同步的参数
    <auth start="true" users="backup" passwordfile="/etc/server.pass"/>  #同步的用户与密码文件
    <userDefinedPort start="false" port="874"/><!-- port=874 -->
    <timeout start="false" time="100"/><!-- timeout=100 -->
    <ssh start="false"/>
</rsync>
#错误日志记录在/tmp下
<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>
3,测试rsync配置有没有问题
# rsync -avl /etc/fstab  backup@192.168.1.28::test --password-file=/etc/server.pass
4,启动sersync
./sersync2 -d 
5,写入/etc/rc.local文件
echo "/usr/local/GNU_linux/sersync2 -d &">>/etc/rc.local
6,测试
在/var/www/目录下建立文件和文件夹,观察是否同步到web节点的/data目录下
四,Serync2命令使用
1,查看帮助
./sersync2 -help 
2,指定别的配置文件
./sersync2 -o xxx.xml
3,指定默认的线程池的线程总数
./sersync -n num
./sersync -n 5 则指定线程总数为5,如果不指定,默认启动线程池数量是10,如果cpu使用过高,可以通过这个参数调低,如果机器配置较高,可以用-n跳高线程总数。
4,不进行同步,只运行插件
./sersync2-m pluginName
例如./sersync2 -m command,则在监控到文件事件后,不对远程目标服务器进行同步,而是直接运行command插件。
5,多个参数可以配合使用
./sersync -n 8 -o abc.xml -r -d   
表示,设置线程池工作线程为8个,指定abc.xml作为配置文件,在实时监控前作一次整体同步,以守护进程方式在后台运行。 如果配置文件开启过滤的话,-r将不能使用。
6,通常情况下,对本地到远程整体同步一遍后,在后台运行实时同步。
./sersync -d









本文转自 deng304749970 51CTO博客,原文链接:http://blog.51cto.com/damondeng/1181523,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值