实时同步服务inotify-tools+rsync+sesync

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34646546/article/details/88050463

实时监控软件安装部署:inotify-tools

实时监控软件需要依赖epel源

第一个历程:进行软件安装

yum install -y inotify-tools

第二个历程:如何实现实时监控

[root@nfs01 data]# inotifywait /data
Setting up watches.
Watches established.
/data/ CREATE oldboy.txt

实时监控事件与参数说明
需求01:进行实时监控(一直监控)
-m|–monitor Keep listening for events forever.
一直进行监控

需求02. 实现可以进行递归监控
-r|–recursive Watch directories recursively.
递归监控

-q|–quiet Print less (only print events).
只输出监控的信息

监控的事件信息:
数据创建 数据删除 数据修改 — 事件信息
inotifywait -mrq /data -e delete,close_write,create,move

如何将实时监控命令和rsync传输数据命令进行整合
1)利用脚本进行整合 忽略
2)利用sersync可以将监控命令和rsync进行整合

部署安装sersync软件

第一个历程:将软件上传到/server/tools目录中

第二个历程: 解压软件

tar xf sersync.tar.gz
sersync_installdir_64bit.zip

第三个历程:将程序目录保存到指定目录

cd sersync_installdir_64bit
cp -a sersync/ /usr/local/	

第四个历程: 编写配置文件信息

vim /usr/local/sersync/conf/confxml.xml
配置文件说明:参见绘图
在这里插入图片描述

[root@nfs01 conf]# cat confxml.xml -n
     1	<?xml version="1.0" encoding="ISO-8859-1"?>
     2	<head version="2.5">
     3	    <host hostip="localhost" port="8008"></host>
     4	    <debug start="false"/>
     5	    <fileSystem xfs="false"/>
     6	    <filter start="false">
     7		<exclude expression="(.*)\.svn"></exclude>
     8		<exclude expression="(.*)\.gz"></exclude>
     9		<exclude expression="^info/*"></exclude>
    10		<exclude expression="^static/*"></exclude>
    11	    </filter>
    12	    <inotify>
    13		<delete start="true"/>
    14		<createFolder start="true"/>
    15		<createFile start="false"/>
    16		<closeWrite start="true"/>
    17		<moveFrom start="true"/>
    18		<moveTo start="true"/>
    19		<attrib start="false"/>
    20		<modify start="false"/>
    21	    </inotify>
    22	
    23	    <sersync>
    24		<localpath watch="/data">
    25		    <remote ip="172.16.1.41" name="nfsbackup"/>
    26		    <!--<remote ip="192.168.8.39" name="tongbu"/>-->
    27		    <!--<remote ip="192.168.8.40" name="tongbu"/>-->
    28		</localpath>
    29		<rsync>
    30		    <commonParams params="-az"/>
    31		    <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
    32		    <userDefinedPort start="false" port="874"/><!-- port=874 -->
    33		    <timeout start="false" time="100"/><!-- timeout=100 -->
    34		    <ssh start="false"/>
    35		</rsync>
    36		<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
    37		<crontab start="false" schedule="600"><!--600mins-->
    38		    <crontabfilter start="false">
    39			<exclude expression="*.php"></exclude>
    40			<exclude expression="info/*"></exclude>
    41		    </crontabfilter>
    42		</crontab>
    43		<plugin start="false" name="command"/>
    44	    </sersync>
    45	
    46	    <plugin name="command">
    47		<param prefix="/bin/sh" suffix="" ignoreError="true"/>	<!--prefix /opt/tongbu/mmm.sh suffix-->
    48		<filter start="false">
    49		    <include expression="(.*)\.php"/>
    50		    <include expression="(.*)\.sh"/>
    51		</filter>
    52	    </plugin>
    53	
    54	    <plugin name="socket">
    55		<localpath watch="/opt/tongbu">
    56		    <deshost ip="192.168.138.20" port="8009"/>
    57		</localpath>
    58	    </plugin>
    59	    <plugin name="refreshCDN">
    60		<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
    61		    <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
    62		    <sendurl base="http://pic.xoyo.com/cms"/>
    63		    <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
    64		</localpath>
    65	    </plugin>
    66	</head>

第五个历程: 启动程序服务

cd /usr/local/sersync/bin
chmod +x sersync
./sersync -dro /usr/local/sersync/conf/confxml.xml

猜你喜欢

转载自blog.csdn.net/qq_34646546/article/details/88050463
今日推荐