與在redhat安裝nagios相比,在ubuntu安裝nagios監(jiān)控非常簡單,直接通過
目前創(chuàng)新互聯(lián)已為上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計、金安網(wǎng)站維護(hù)等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
apt-get即可從ubuntu的服務(wù)器上下載組件自動安裝。
sudo apt-get install nagios3 nagios-nrpe-plugin
給nagiosadmin添加一個密碼:
sudo htpasswd /etc/nagios3/htpasswd.users nagiosadmin
添加一個用戶:
sudo htpasswd /etc/nagios3/htpasswd.users dragon
在被監(jiān)控主機(jī)上安裝nrpe,
sudo apt-get install nagios-nrpe-server
sudo vi /etc/nagios/nrpe.cfg
找到allowed_host添加監(jiān)控主機(jī)的ip地址:
allowed_hosts=127.0.0.1,192.168.1.112
Service nrpe restart
在server端測試
/usr/lib/nagios/plugins/check_nrpe -H 192.168.1.124,測試成功的話會輸出客戶機(jī)的NRPE版本號。
NRPE_2.1.4
在server新建監(jiān)控主機(jī)定義文件server02.cfg
sudo cp /etc/nagios3/conf.d/localhost_nagios2.cfg \/etc/nagios3/conf.d/server02.cfg
編輯 /etc/nagios3/conf.d/server02.cfg:注意修改address為被監(jiān)控主機(jī)的地址,并添加DNS,http,ssh的服務(wù)監(jiān)控。
define host{
use generic-host
host_name server02
alias server-02
address 192.168.1.124
}
define service{
use generic-service
host_name server02
service_description Disk Space
check_command check_all_disks!20%!10%
}
define service{
use generic-service
host_name server02
service_description Current Users
check_command check_users!20!50
}
define service{
use generic-service
host_name server02
service_description Total Processes
check_command check_procs!250!400
}
define service{
use generic-service
host_name server02
service_description Current Load
check_command check_load!5.0!4.0!3.0!10.0!6.0!4.0
}
define service{
use generic-service
host_name server02
service_description DNS
check_command check_dns!192.168.1.124
}
define service {
host_name server02
service_description HTTP
check_command check_http
use generic-service
notification_interval 0
}
# check that ssh services are running
define service {
host_name server02
service_description SSH
check_command check_ssh
use generic-service
notification_interval 0
}
測試nagios配置是否成功
nagios3 -v /etc/nagios3/nagios.cfg
Error in configuration file '/etc/nagios3/nagios.cfg' - Line 470 (Check result path is not a valid directory)
這個文件是nagios用于存儲監(jiān)測主機(jī)的結(jié)果和未能監(jiān)測到的服務(wù)信息
check_result_path=/var/lib/nagios3/spool/checkresults
我發(fā)現(xiàn)本機(jī)上并沒有這個文件目錄的存在,所以我新建了這個文件,可能會出現(xiàn)啟動nagios沒有報錯,但無法看到監(jiān)控信息的情況,查看日志提示“Jul 16 20:00:59 fileserver nagios: Error: Could not open check result queue directory '/var/nagios/spool/checkresults' for reading. ”.
Sudo mkdir /var/lib/nagios3/spool/checkresults
Sudo chmod nagios:nagios /var/lib/nagios3/spool/checkresults
啟動nagios
Service nagios3 start
打開在瀏覽器地址欄輸入:“ip\nagios3”
利用NSClient++監(jiān)控遠(yuǎn)程Windows上的“本地信息”
在Nagios的libexec下有check_nt這個插件,它就是用來檢查windows機(jī)器的服務(wù)的。其功能類似于check_nrpe。不過還需要搭配另外一個軟件NSClient++,它則類似于NRPE。
NSClient++的原理如下圖
可以看到NSClient與nrpe最大的區(qū)別就是:
被監(jiān)控機(jī)上安裝有nrpe,并且還有插件,最終的監(jiān)控是由這些插件來進(jìn)行的。當(dāng)監(jiān)控主機(jī)將監(jiān)控請求發(fā)給nrpe后,nrpe調(diào)用插件來完成監(jiān)控。
NSClient++則不同,被監(jiān)控機(jī)上只安裝NSClient,沒有任何的插件。當(dāng)監(jiān)控主機(jī)將監(jiān)控請求發(fā)給NSClient++后,NSClient直接完成監(jiān)控,所有的監(jiān)控是由NSClient完成的。
這也說明了NSClient++的一個很大的問題:不靈活、沒有可擴(kuò)展性。它只能完成自己本身包含的監(jiān)控操作,不能由一些插件來擴(kuò)展。好在NSClient++已經(jīng)做的不錯了,基本上可以完全滿足我們的監(jiān)控需求。
安裝NSClient++
使用check_nt可以看到winserver上nsclient++的監(jiān)控情況(注意需要指定端口為:12489)
要注意兩臺主機(jī)之間網(wǎng)絡(luò)是否聯(lián)通,使用ping測試網(wǎng)絡(luò)聯(lián)通,winserver的防火墻有可能阻斷兩臺主機(jī)之間的網(wǎng)絡(luò)通信,可以選擇關(guān)掉。
編輯nagios server端的nt.cfg里面的命令check_nt增加一些參數(shù)。
sudo vi /etc/nagios-plugins/config/nt.cfg
Sudo vi /etc/nagios3/objects/windows.cfg
define host{
use generic-host ; Inherit default values from a template
host_name Nagios-Windows ; The name we're giving to this host
alias My Windows Server ; A longer name associated with the host
address 192.168.1.139 ; IP address of the host
}
define hostgroup{
hostgroup_name windows-servers ; The name of the hostgroup
alias Windows Servers ; Long name of the group
}
define service{
use generic-service
host_name Nagios-Windows
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
define service{
use generic-service
host_name Nagios-Windows
service_description Uptime
check_command check_nt!UPTIME
}
define service{
use generic-service
host_name Nagios-Windows
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
define service{
use generic-service
host_name Nagios-Windows
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90
}
define service{
use generic-service
host_name Nagios-Windows
service_description C:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
define service{
use generic-service
host_name Nagios-Windows
service_description W3SVC
check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
}
define service{
use generic-service
host_name Nagios-Windows
service_description Explorer
check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
}
測試nagios配置是否成功
nagios3 -v /etc/nagios3/nagios.cfg
service nagios3 restart
Sudo vi /etc/nagios3/nagios.cfg把#cfg_file=/etc/nagios3/objects/windows.cfg前面的#給去掉。使用“nagios3 -v /etc/nagios3/nagios.cfg”測試是否有錯。沒有報錯的話,開啟nagios3.
用瀏覽器打開nagios的控制臺等待一段時間之后就可以看到實驗效果了。
本文允許轉(zhuǎn)載但務(wù)必保留出處:(http://dragon123.blog.51cto.com/9152073/1543915)