CentOS環境Nagios的安裝與配置
CentOS環境Nagios的安裝與配置其實挺簡單,來隨我看看!
在上文中講到有關cacti的安裝與配置,它在網絡流量性能監控以及圖表繪制等方面非常的強大。但是服務器和服務本身狀態的監控以及錯誤報警機制,則需要本文介紹的Nagios神器來實現。Nagios的功能是監控服務和主機,根據配置在服務器異常的時候提供報警功能,并提供友好的WEB界面查看當前的網絡狀態、通知和故障歷史、日志文件……但是他自身并不包括這部分功能的代碼,所有的監控、檢測功能都是有插件來完成的。
一、安裝環境:CentOS5.4 + Apache2 + PHP5.2,請確保已安裝PHP+Apache,可參看本博有關Apache與PHP的安裝教程;
二、創建Nagios用戶及用戶組,命令如下:
#useradd -m nagios
--創建nagcmd組用來運行通過web接口傳輸過來的命令,同時添加nagios和apache
- #groupadd nagcmd
- #usermod -a -G nagcmd nagios
- #usermod -a -G nagcmd apache
#p#
三、下載安裝Nagios及Nagios插件,過程如下:
——下載Nagios
#wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
——下載Nagios插件
#wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz
——解壓Nagios
#tar -zvxf nagios-3.2.1.tar.gz
#cd nagios-3.2.1
——編譯
#./configure --with-command-group=nagcmd #make all
——安裝Nagios,初始化腳本及配置文件,Nagios將會被安裝至/usr/local/nagios #make install #make install-init #make install-config #make install-commandmode
——安裝WEB界面,界面將會安裝到 /usr/local/nagios/share ( http 配置文件默認添加到 /etc/httpd/conf.d/nagios.conf,如果沒有則執行:#cp sample-config/httpd.conf /etc/apache2/conf.d/nagios.conf )
#make install-webconf
——創建HTTP認證用戶登錄Nagios,用戶名nagiosadmin,密碼123456
#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
——重啟apache
#service httpd restart
——安裝Nagios插件
#tar -zvxf nagios-plugins-1.4.14.tar.gz
#cd nagios-plugins-1.4.14
#./configure --with-nagios-user=nagios --with-nagios-group=nagios #make && make install
——配置Nagios管理員接受告警信息的郵箱,寫入管理員郵箱 #vim /usr/local/nagios/etc/objects/contacts.cfg email admin@admin.com ; ——校驗Nagios配置文件,驗證配置是否有誤 #/usr/local/nagios/bin/nagios -v
——啟動Nagios,配置在系統啟動時運行Nagios
- #chkconfig --add nagios
- #chkconfig nagios on
- #chkconfig httpd on
——運行Nagios
#service nagios start
#p#
四、登陸到Web界面,輸入用戶名密碼:nagiosadmin 123456,http://localhost/nagios/
五、錯誤處理
1、本機監控HTTP SSH的Notifications顯示警告錯誤,解決方法:
#vim /usr/local/nagios/etc/objects/localhost.cfg
define service{
use local-service ; Name of service template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 1 #改為1,即可
}
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
use local-service ; Name of service template to use
host_name localhost
service_description HTTP
check_command check_http
notifications_enabled 1 #改為1,即可
}
2、Nagios顯示類似錯誤:HTTP WARNING: HTTP/1.1 403 Forbidden - 5240 bytes in 0.002 second response time。
該錯誤表明在apache web根目錄沒有index.html文件。解決方法:在web根目錄(如:/var/www/html/目錄)建立index.html文件,重啟apache和nagios即可。
通過文章我們清楚的知道了CentOS環境Nagios的安裝與配置的詳細過程!
【編輯推薦】