源服务器上安装sersync工具,实时触发rsync进行同步

Sersync 工具实时检测源服务器上指定目录下文件的变化,只要指定目录下文件或者目录的变化,就促发同步到目标服务器指定的目录

 

2.4.1查看服务器内核是否支持inotify

ll /proc/sys/fs/inotify   #列出文件目录,出现下面的内容,说明服务器内核支持inotify

 

[root@maven01 ceshi]# ll /proc/sys/fs/inotify

total 0

-rw-r--r-- 1 root root 0 Aug  5 13:39 max_queued_events

-rw-r--r-- 1 root root 0 Aug  5 13:39 max_user_instances

-rw-r--r-- 1 root root 0 Aug  5 13:39 max_user_watches

备注:Linux下支持inotify的内核最小为2.6.13,可以输入命令:uname -a查看内核

CentOS 5.X内核为2.6.18,默认已经支持inotify

2.4.2修改inotify默认参数(inotify默认内核参数值太小)

查看系统默认参数值:

[root@maven01 ceshi]# sysctl -a | egrep"max_queued_events|max_user_watches|max_user_instances"

fs.inotify.max_user_instances = 128

fs.inotify.max_user_watches = 8192

fs.inotify.max_queued_events = 16384

fs.epoll.max_user_watches = 203960

 

修改参数:

[root@maven01 ceshi]# sysctl -wfs.inotify.max_queued_events="800000"

fs.inotify.max_queued_events = 800000

[root@maven01 ceshi]# sysctl -wfs.inotify.max_user_watches="800000"

fs.inotify.max_user_watches = 800000

[root@maven01 ceshi]# sysctl -wfs.inotify.max_user_instances="65535"

fs.inotify.max_user_instances = 65535

 

[root@maven01 ceshi]# sysctl -a | egrep"max_queued_events|max_user_watches|max_user_instances"

fs.inotify.max_user_instances = 65535

fs.inotify.max_user_watches = 800000

fs.inotify.max_queued_events = 800000

 

vi /etc/sysctl.conf #添加以下代码

fs.inotify.max_queued_events=99999999

fs.inotify.max_user_watches=99999999

fs.inotify.max_user_instances=65535

:wq! #保存退出

参数说明:

max_queued_events

inotify队列最大长度,如果值太小,会出现"**Event Queue Overflow **"错误,导致监控文件不准确

max_user_watches

要同步的文件包含多少目录,可以用:find /home/www.osyunwei.com -type d | wc -l 统计,必须保证max_user_watches值大于统计结果(这里/home/www.osyunwei.com为同步文件目录)

max_user_instances

每个用户创建inotify实例最大值

2.4.3安装sersync

tar zxvfsersync2.5.4_64bit_binary_stable_final.tar.gz

mv GNU-Linux-x86 /usr/local/sersync 

[root@mantu_hw ~]# ll /usr/local/sersync/*

-rwxr-xr-x 1 root root    2239 2  13 16:09 /usr/local/sersync/confxml-1.xml

-rwxr-xr-x 1 root root    2231 2  13 16:10 /usr/local/sersync/confxml-2.xml

-rwxr-xr-x 1 root root    2214 2  13 15:29 /usr/local/sersync/confxml.xml.bak

-rwxr-xr-x 1 root root 1617440 6  29 2010 /usr/local/sersync/sersync2

2.4.4配置sersync

4.1参数说明:

localpath watch="/home/www.osyunwei.com"#源服务器同步目录

10.0.1.254#目标服务器IP地址

name=" mhttongbu1" #目标服务器rsync同步目录模块名称

users=" tongbu_user" #目标服务器rsync同步用户名

passwordfile="/etc/passwd.txt" #目标服务器rsync同步用户的密码在源服务器的存放路径

remote ip="10.0.1.254": #目标服务器ip,每行一个

remote ip="10.0.1.254": #目标服务器ip,每行一个

failLogpath="/tmp/rsync_fail_log.sh"  #脚本运行失败日志记录

start="true"  #设置为true,每隔600分钟执行一次全盘同步

 

[root@mantu_hw sersync]# cat -n confxml-1.xml|sed-n '23,38p'

    23        <sersync>

    24              <localpathwatch="/data/matula/pic/cover">监测源服务器的目录

    25                 <remote ip="10.0.1.254"name="mhttongbu1"/>目标服务器ip

    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="-artuz"/>

    31                 <authstart="true" users="tongbu_user" passwordfile="/etc/passwd.txt"/>

    32                  <userDefinedPort start="false"port="874"/><!-- port=874 -->

    33                 <timeout start="false" time="100"/><!--timeout=100 -->

    34                 <ssh start="false"/>

    35              </rsync>

    36              <failLogpath="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--defaultevery 60mins execute once-->

    37              <crontabstart="false" schedule="600"><!--600mins-->

38                  <crontabfilterstart="false">


启动两个配置文件监测两个不同的同步目录

/usr/local/sersync/sersync2 -d -r -o/usr/local/sersync/confxml-1.xml

/usr/local/sersync/sersync2 -d -r -o/usr/local/sersync/confxml-2.xml

默认是10个进程

下面的-n参数可以指定进程的:

/usr/local/sersync/sersync2 -n 20 -d -r -o/usr/local/sersync/confxml-1.xml