原本maptail可以在web服务器主机上部署进行实时查看web服务的访问日志,现在有多台web都需要进行监控,有点麻烦,所以就使用一台机器同时监控多台,由于maptail的实质是tail -f的一个展示,所以结合这一点,也就是说maptail只需要有access_log即可,所以只需要把其他web机器上的访问日志同步过来即可,然后inotify+rsync讲是一个不错的选择,rsync常用方式是“分发”,这次使用的是他的“汇聚”。大致结构如下:
配置整个过程:
一、升级Python到2.6~2.7
- # mkdir /root/sourcesoft;cd !$
- # wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
- # yum install gcc*
- # tar -zxvf Python-2.7.3.tgz
- # cd Python-2.7.3
- # ./configure
- # make;make install
- # cd /usr/bin
- # mv python python.bak
- # ln -s /usr/local/bin/python python
二、安装nodeJS
- # cd /root/sourcesoft
- # wget http://nodejs.org/dist/v0.8.16/node-v0.8.16.tar.gz
- # tar -zxvf node-v0.8.16.tar.gz
- # cd node-v0.8.16
- # ./configure
- # make;make install
如果上述过程出现问题,可以有一下解决方式:
1.yum无法安装软件,提示一下错误:
注:如果升级过Python的话,此处可能会提示There was a problem importing one of the Python modules required to run yum.
- 解决方法:
- 查找yum文件,并编辑此py文件
- # which yum
- /usr/bin/yum
- # vi /usr/bin/yum
- 将
- #!/usr/bin/python
- 改为:
- whereis python出来的结果
- #!/usr/bin/python2.4
2.安装nodejs的时候提示以下错误:
ImportError: No module named bz2
- 解决方法:
- 1.
- # yum install -y bzip2*
- 2.
- # cd Python-2.7/Modules/zlib
- # ./configure ;make;make install
- 3.
- # cd Python-2.7/
- # python2.7 setup.py install
三、安装maptail模块并启动
- # npm install maptail -g
启动:
- # nohup /usr/bin/tail -f /var/log/httpd/access_log | /usr/local/bin/node /usr/local/bin/maptail -h 192.168.158.216 -p 8080 &
四、浏览:
在浏览器中输入:http://192.168.158.216:8080即可访问
五、拓展使用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查看