五、拓展使用inotify+rsync实现同时监控多台主机
1.安装inotify
- # tar xf inotify-tools-3.14.tar.gz
- # cd inotify-tools-3.14
- # ./configure && make && make install
2.配置:
192.168.158.219 ====> 192.168.158.216
219上的配置:
- # vim /root/scripts/in_rsync.sh
- #!/bin/bash
- host1=192.168.158.216
- src=/usr/local/apache/logs/web
- dst1=weblog219
- user1=root
- /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src \
- | while read files;do
- /usr/bin/rsync -zrtopg --delete --password-file=/etc/rsyncd.pass $src $user1@$host1::$dst1 >/dev/null 2>&1
- echo "${files} was rsynced" >>/tmp/rsync.log 2>&1 >/dev/null
- done
- # vim /etc/rsyncd.pass
- 123456
- # chmod 600 /etc/rsyncd.pass
- # nohup /root/scripts/in_rsync.sh &
216上的配置:
- # vim /etc/rsyncd.conf
- uid = root
- gid = root
- use chroot = no
- max connections = 36000
- strict modes = yes
- log file = /var/log/rsyncd.log
- pid file = /var/run/rsyncd.pid
- lock file = /var/run/rsync.lock
- log format = %t %a %m %f %b
- [weblog219]
- path = /www/log219/
- auth users = root
- read only = no
- hosts allow = 192.168.158.0/24
- list = no
- uid = root
- gid = root
- secrets file = /etc/rsyncd.pass
- ignore errors = yes
- # vim /etc/rsyncd.pass
- root:123456
- # chmod 600 /etc/rsyncd.pass
- # /usr/bin/rsync --daemon
六、启动新端口并验证
nohup /usr/bin/tail -f /var/log/httpd/access_log | /usr/local/bin/node /usr/local/bin/maptail -h 192.168.158.216 -p 8219 &
在浏览器中输入http://192.168.158.216:8080和http://192.168.158.216:8219查看

