本來maptail能夠在web服務器主機上部署進行實時查看web服務的訪問日誌,如今有多臺web都須要進行監控,有點麻煩,因此就使用一臺機器同時監控多臺,因爲maptail的實質是tail -f的一個展現,因此結合這一點,也就是說maptail只須要有access_log便可,因此只須要把其餘web機器上的訪問日誌同步過來便可,而後inotify+rsync講是一個不錯的選擇,rsync經常使用方式是「分發」,此次使用的是他的「匯聚」。大體結構以下:node
配置整個過程:python
1、升級Python到2.6~2.7web
- # 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
2、安裝nodeJS apache
- # 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
若是上述過程出現問題,能夠有一下解決方式:npm
1.yum沒法安裝軟件,提示一下錯誤:vim
注:若是升級過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的時候提示如下錯誤:bash
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
3、安裝maptail模塊並啓動python2.7
- # 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 &
4、瀏覽:
在瀏覽器中輸入:http://192.168.158.216:8080便可訪問
5、拓展使用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
6、啓動新端口並驗證
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查看