maptail同時監控多臺web訪問日誌

  原本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查看

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章