[root@Monitor nginx]# ll /proc/sys/fs/inotify
总用量 0
-rw-r--r-- 1 root root 0 1月 17 20:20 max_queued_events
-rw-r--r-- 1 root root 0 1月 17 20:20 max_user_instances
-rw-r--r-- 1 root root 0 1月 17 20:20 max_user_watches
2,安装编译工具和inotify-tools
[root@Monitor nginx]# yum install make gcc gcc-c++
已加载插件:fastestmirror
设置安装进程
Loading mirror speeds from cached hostfile
* epel: mirrors.tuna.tsinghua.edu.cn
包 1:make-3.81-23.el6.x86_64 已安装并且是最新版本
包 gcc-4.4.7-17.el6.x86_64 已安装并且是最新版本
包 gcc-c++-4.4.7-17.el6.x86_64 已安装并且是最新版本
无须任何处理
[root@Monitor nginx]# wget
--2017-01-17 20:55:41--
正在解析主机 github.com... 192.30.253.113, 192.30.253.112
正在连接 github.com|192.30.253.113|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz [跟随至新的 URL]
--2017-01-17 20:55:41-- https://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
正在连接 github.com|192.30.253.113|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz [跟随至新的 URL]
--2017-01-17 20:55:43-- https://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
正在解析主机 cloud.github.com... 54.192.127.169, 54.192.127.35, 54.192.127.201, ...
正在连接 cloud.github.com|54.192.127.169|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:358772 (350K) [null]
正在保存至: “inotify-tools-3.14.tar.gz”
86% [=====================================================================> ] 310,532 91.0K/s eta(英国中部时95% [============================================================================> ] 343,300 87.8K/s eta(英国中部时100%[================================================================================>] 358,772 83.0K/s eta(英国中部时100%[================================================================================>] 358,772 83.0K/s in 4.2s
2017-01-17 20:56:00 (83.0 KB/s) - 已保存 “inotify-tools-3.14.tar.gz” [358772/358772])
[root@Monitor nginx]# tar xf inotify-tools-3.14.tar.gz
[root@Monitor nginx]# cd inotify-tools-3.14
[root@Monitor inotify-tools-3.14]# ./configure --prefix=/usr/local//inotify
[root@Monitor inotify-tools-3.14]#make && make install
3,设置系统环境变量,添加软连接。
[root@Monitor inotify-tools-3.14]# echo "PATH=/usr/local/inotify/bin:$PATH" >>/etc/profile.d/inotify.sh
[root@Monitor inotify-tools-3.14]# source /etc/profile.d/inotify.sh
[root@Monitor inotify-tools-3.14]# echo "/usr/local/inotify/lib" >/etc/ld.so.conf.d/inotify.conf
[root@Monitor inotify-tools-3.14]# ln -s /usr/local/inotify/include /usr/include/inotify
[root@Monitor inotify-tools-3.14]# sysctl -a | grep max_queued_events
4,修改inotify默认参数
[root@Monitor inotify-tools-3.14]# sysctl -a | grep max_queued_events
fs.inotify.max_queued_events = 99999999
[root@Monitor inotify-tools-3.14]# sysctl -a | grep max_user_watches
fs.inotify.max_user_watches = 99999999
fs.epoll.max_user_watches = 797306
[root@Monitor inotify-tools-3.14]# sysctl -a | grep max_user_instances
fs.inotify.max_user_instances = 65535
[root@Monitor inotify-tools-3.14]#
修改添加如下参数:
[root@Monitor inotify-tools-3.14]# vim /etc/sysctl.conf
fs.inotify.max_queued_events=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535
5,创建脚步,实时触发rsync进行同步
[root@Monitor inotify-tools-3.14]# vim /usr/local/inotify/rsync.sh
#!/bin/sh
#date:2017-01-17
#author:lqb
srcdir=/data/nginx
dstdir=backup
excludedir=/usr/local/inotify/exclude.list
rsyncuser=rsync
rsyncpassdir=/etc/rsyncd.passwd
dstip="192.168.180.3"
#for ip in $dstip
#do
rsync -avH --port=873 --progress --delete --exclude-from=$excludedir $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir
#done
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move $srcdir | while read file
do
for ip in $dstip
do
rsync -avH --port=873 --progress --delete --exclude-from=$excludedir $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir
echo " ${file} was rsynced" >> /tmp/rsync.log 2>&1
done
done
[root@Monitor inotify-tools-3.14]#chmod +x /usr/local/inotify/rsync.sh
[root@Monitor inotify-tools-3.14]# /usr/local/inotify/rsync.sh
rsync: getaddrinfo: 873: No address associated with hostname
rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]
sending incremental file list
nginx/
nginx/inotify-tools-3.14.tar.gz
358772 100% 34.54MB/s 0:00:00 (xfer#1, to-check=54/58)
nginx/nginx.access.log
40824576 14% 38.93MB/s 0:00:05
至此,数据进行同步。