原本maptail可以在web服务器主机上部署进行实时查看web服务的访问日志,现在有多台web都需要进行监控,有点麻烦,所以就使用一台机器同时监控多台,由于maptail的实质是tail -f的一个展示,所以结合这一点,也就是说maptail只需要有access_log即可,所以只需要把其他web机器上的访问日志同步过来即可,然后inotify+rsync讲是一个不错的选择,rsync常用方式是“分发”,这次使用的是他的“汇聚”。大致结构如下:

 

配置整个过程:

一、升级Python到2.6~2.7

 
  
  1. # mkdir /root/sourcesoft;cd !$ 
  2. # wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz   
  3. # yum install gcc* 
  4. # tar -zxvf Python-2.7.3.tgz   
  5. # cd Python-2.7.3   
  6. # ./configure   
  7. # make;make install   
  8. # cd /usr/bin   
  9. # mv python python.bak   
  10. # ln -s /usr/local/bin/python python   

二、安装nodeJS 

 
  
  1. # cd /root/sourcesoft 
  2. # wget http://nodejs.org/dist/v0.8.16/node-v0.8.16.tar.gz   
  3. # tar -zxvf node-v0.8.16.tar.gz   
  4. # cd node-v0.8.16   
  5. # ./configure   
  6. # make;make install   

如果上述过程出现问题,可以有一下解决方式:

1.yum无法安装软件,提示一下错误:

注:如果升级过Python的话,此处可能会提示There was a problem importing one of the Python modules required to run yum.  

 
  
  1. 解决方法: 
  2.  
  3. 查找yum文件,并编辑此py文件 
  4. # which yum 
  5. /usr/bin/yum 
  6. # vi /usr/bin/yum 
  7. 将 
  8. #!/usr/bin/python 
  9. 改为: 
  10. whereis python出来的结果 
  11. #!/usr/bin/python2.4 

2.安装nodejs的时候提示以下错误:

ImportError: No module named bz2

 
  
  1. 解决方法: 
  2. 1. 
  3. # yum install -y bzip2*  
  4. 2. 
  5. # cd Python-2.7/Modules/zlib   
  6. # ./configure ;make;make install  
  7. 3. 
  8. # cd Python-2.7/   
  9. # python2.7 setup.py install  

三、安装maptail模块并启动

 
  
  1. # npm install maptail -g   

启动:

 
  
  1. # 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

 
  
  1. # tar xf inotify-tools-3.14.tar.gz 
  2. # cd inotify-tools-3.14 
  3. # ./configure && make && make install 

2.配置:

192.168.158.219 ====>  192.168.158.216

219上的配置:

 
  
  1. # vim /root/scripts/in_rsync.sh 
  2. #!/bin/bash 
  3. host1=192.168.158.216 
  4. src=/usr/local/apache/logs/web 
  5. dst1=weblog219 
  6. user1=root 
  7. /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib  $src \ 
  8. | while read files;do 
  9. /usr/bin/rsync -zrtopg   --delete --password-file=/etc/rsyncd.pass $src  $user1@$host1::$dst1 >/dev/null 2>&1 
  10.   echo "${files} was rsynced" >>/tmp/rsync.log 2>&1 >/dev/null 
  11. done 
  12.  
  13. # vim /etc/rsyncd.pass  
  14. 123456 
  15. # chmod 600 /etc/rsyncd.pass  
  16. # nohup /root/scripts/in_rsync.sh & 

216上的配置:

 
  
  1. # vim /etc/rsyncd.conf  
  2. uid = root 
  3. gid = root 
  4. use chroot = no 
  5. max connections = 36000 
  6. strict modes = yes 
  7. log file = /var/log/rsyncd.log 
  8. pid file = /var/run/rsyncd.pid 
  9. lock file = /var/run/rsync.lock 
  10. log format = %t %a %m %f %b 
  11. [weblog219] 
  12. path = /www/log219/ 
  13. auth users = root 
  14. read only = no 
  15. hosts allow = 192.168.158.0/24 
  16. list = no 
  17. uid = root 
  18. gid = root 
  19. secrets file = /etc/rsyncd.pass 
  20. ignore errors = yes 
  21.  
  22. # vim /etc/rsyncd.pass  
  23. root:123456 
  24. # chmod 600 /etc/rsyncd.pass  
  25. # /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查看