nagios簡介
nagios是一款開源的電腦系統(tǒng)和網(wǎng)絡(luò)監(jiān)視工具,能有效監(jiān)控windows、linux和unix的主機(jī)狀態(tài),交換機(jī)路由器等網(wǎng)絡(luò)設(shè)置,打印機(jī)等。在系統(tǒng)或服務(wù)狀態(tài)異常時(shí)發(fā)出郵件或短信報(bào)警第一時(shí)間通知網(wǎng)站運(yùn)維人員,在狀態(tài)恢復(fù)后發(fā)出正常的郵件或短信通知。
nagios原名為netsaint,由ethan galstad開發(fā)并維護(hù)至今。nagios是一個(gè)縮寫形式: "nagios ain't gonna insist on sainthood" sainthood 翻譯為圣徒,而"agios"是"saint"的希臘表示方法。nagios被開發(fā)在linux下使用,但在unix下也工作得非常好。
主要功能
網(wǎng)絡(luò)服務(wù)監(jiān)控(smtp、pop3、http、nntp、icmp、snmp、ftp、ssh)主機(jī)資源監(jiān)控(cpu load、disk usage、system logs),也包括windows主機(jī)(使用nsclient++ plugin)可以指定自己編寫的plugin通過網(wǎng)絡(luò)收集數(shù)據(jù)來監(jiān)控任何情況(溫度、警告……)可以通過配置nagios遠(yuǎn)程執(zhí)行插件遠(yuǎn)程執(zhí)行腳本遠(yuǎn)程監(jiān)控支持ssh或ssl加通道方式進(jìn)行監(jiān)控簡單的plugin設(shè)計(jì)允許用戶很容易的開發(fā)自己需要的檢查服務(wù),支持很多開發(fā)語言(shell scripts、c++、perl、ruby、python、php、c#等)包含很多圖形化數(shù)據(jù)plugins(nagiosgraph、nagiosgrapher、pnp4nagios等)可并行服務(wù)檢查能夠定義網(wǎng)絡(luò)主機(jī)的層次,允許逐級(jí)檢查,就是從父主機(jī)開始向下檢查當(dāng)服務(wù)或主機(jī)出現(xiàn)問題時(shí)發(fā)出通告,可通過email, pager, sms 或任意用戶自定義的plugin進(jìn)行通知能夠自定義事件處理機(jī)制重新激活出問題的服務(wù)或主機(jī)自動(dòng)日志循環(huán)支持冗余監(jiān)控包括web界面可以查看當(dāng)前網(wǎng)絡(luò)狀態(tài),通知,問題歷史,日志文件等
支持短信,郵件通知
nagios官網(wǎng)
1. nagios安裝 - 服務(wù)端(192.168.0.11)
centos6默認(rèn)的yum源里沒有nagios相關(guān)的rpm包,但是我們可以安裝一個(gè)epel的擴(kuò)展源:
yum install -y epel-release
然后安裝nagios相關(guān)的包
yum install -y httpd nagios nagios-pluginsnagios-plugins-all nrpe nagios-plugins-nrpe
設(shè)置登錄nagios后臺(tái)的用戶和密碼:htpasswd -c /etc/nagios/passwd nagiosadmin
nagios -v /etc/nagios/nagios.cfg 檢測配置文件
啟動(dòng)服務(wù):service httpd start; servicenagios start
瀏覽器訪問:
vim /etc/nagios/nagios.cfg #暫時(shí)先不管
2. nagios安裝 - 客戶端(192.168.0.12)
在客戶端機(jī)器上
yum install -y epel-release
yum install -y nagios-plugins nagios-plugins-allnrpe nagios-plugins-nrpe
vim /etc/nagios/nrpe.cfg 找到“allowed_hosts=127.0.0.1” 改為“allowed_hosts=127.0.0.1,192.168.0.11” #服務(wù)器的ip
找到” dont_blame_nrpe=0” 改為 “dont_blame_nrpe=1”
啟動(dòng)客戶端 /etc/init.d/nrpe start
3. 監(jiān)控中心(192.168.0.11)添加被監(jiān)控主機(jī)(192.168.0.12)
vim /etc/nagios/conf.d/192.168.0.12.cfg
define host{
use linux-server
host_name 192.168.0.12
alias 0.12
address 192.168.0.12
}
define service{
use generic-service
host_name 192.168.0.12
service_description check_ping
check_command check_ping!100.0,20%!200.0,50% #0是ok,20是警告,50是危險(xiǎn)
max_check_attempts5 #單位是秒數(shù)
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.0.12
service_description check_ssh
check_command check_ssh
max_check_attempts 5 ;當(dāng)nagios檢測到問題時(shí),一共嘗試檢測5次都有問題才會(huì)告警,如果該數(shù)值為1,那么檢測到問題立即告警
normal_check_interval 1 ;重新檢測的時(shí)間間隔,單位是分鐘,默認(rèn)是3分鐘
notification_interval 60 ;在服務(wù)出現(xiàn)異常后,故障一直沒有解決,nagios再次對使用者發(fā)出通知的時(shí)間。單位是分鐘。如果你認(rèn)為,所有的事件只需要一次通知就夠了,可以把這里的選項(xiàng)設(shè)為0。
}
define service{
use generic-service
host_name 192.168.0.12
service_description check_http
check_command check_http
max_check_attempts 5
normal_check_interval 1
}
以上普通服務(wù)不依賴于客戶端nrpe服務(wù),我們可以想象,我們在自己電腦上可以使用ping或者telnet探測遠(yuǎn)程任何一臺(tái)機(jī)器是否存活、是否開啟某個(gè)端口或服務(wù)。而當(dāng)我們想要檢測客戶端上的某個(gè)具體特殊服務(wù)的情況時(shí),就需要借助于nrpe了,比如想知道客戶端機(jī)器的負(fù)責(zé)或磁盤使用情況。
4. 繼續(xù)添加服務(wù)
增加:
define command{
command_name check_nrpe #去對方獲得服務(wù)狀態(tài),可自定義
command_line $user1$/check_nrpe -h $hostaddress$-c $arg1$
}
繼續(xù)編輯
vim/etc/nagios/conf.d/192.168.0.12.cfg
增加如下內(nèi)容:
define service{
use generic-service
host_name 192.168.0.12
service_description check_load
check_command check_nrpe!check_load
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.0.12
service_description check_disk_hda1
check_command check_nrpe!check_hda1
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.0.12
service_description check_disk_hda2
check_command check_nrpe!check_hda2 #這個(gè)不要寫錯(cuò),是對應(yīng)客戶端的
max_check_attempts 5
normal_check_interval 1
}
說明: check_nrpe!check_load:這里的check_nrpe就是在commands.cfg剛剛定義的,check_load是遠(yuǎn)程主機(jī)上的一個(gè)檢測腳本
在客戶端上vim/etc/nagios/nrpe.cfg 搜索check_load,這行就是在服務(wù)端上要執(zhí)行的腳本了,我們可以手動(dòng)執(zhí)行這個(gè)腳本
把check_hda1更改一下:/dev/hda1 改為 /dev/sda1
再加一行command[check_hda2]=/usr/lib/nagios/plugins/check_disk-w 20% -c 10% -p /dev/sda2 # w = warnning
c = critial
crital不能比warning的值大
機(jī)制:首先在服務(wù)端定義check_nrpe命令,再通過check_nrpe后面跟的command(客戶端的nrpe.cfg里)
客戶端上重啟一下nrpe服務(wù): service nrpe restart
服務(wù)端也重啟一下nagios服務(wù): service nagios restart
5. 配置告警
vim /etc/nagios/objects/contacts.cfg //增加:
define contact{
contact_name
use generic-contact
alias aming
email @qq.com
}
define contact{
contact_name
use generic-contact
alias aaa
email wsw@.com
}
define contactgroup{ #定義聯(lián)系組
contactgroup_name common
alias common
members ,
}
然后在要需要告警的服務(wù)里面加上contactgroup
define service{
use generic-service
host_name 192.168.0.12
service_description check_load
check_command check_nrpe!check_load
max_check_attempts 5
normal_check_interval 1
contact_groups common #監(jiān)控哪個(gè)發(fā)郵件
notifications_enabled 1 ;是否開啟提醒功能。
1為開啟,0為禁用。一般,這個(gè)選項(xiàng)會(huì)在主配置文件(nagios.cfg)中定義,效果相同。
notification_period 24x7 ;發(fā)送提醒的時(shí)間段。非常重要的主機(jī)(服務(wù))我定義為7×24,一般的主機(jī)(服務(wù))就定義為上班時(shí)間。如果不在定義的時(shí)間段內(nèi),無論什么問題發(fā)生,都不會(huì)發(fā)送提醒。
notification_options:w,u,c,r ;這個(gè)是service的狀態(tài)。w為waning, u為unknown, c為critical, r為recover(恢復(fù)了),類似的還有一個(gè) host對應(yīng)的狀態(tài):d,u,r d = 狀態(tài)為down, u = 狀態(tài)為unreachable , r = 狀態(tài)恢復(fù)為ok,需要加入到host的定義配置里。
}
6. 配置圖形顯示 pnp4nagios
(1)安裝
yum install pnp4nagios rrdtool
(2)配置主配置文件
vim /etc/nagios/nagios.cfg //修改如下配置
process_performance_data=
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
enable_environment_macros=
(3)修改commands.cfg
vim/etc/nagios/objects/commands.cfg //注釋掉原有對process-host-perfdata和process-service-perfdata,重新定義
define command {
command_name process-service-perfdata
command_line /usr/bin/perl/usr/libexec/pnpnagios/process_perfdata.pl
}
define command {
command_name process-host-perfdata
command_line /usr/bin/perl/usr/libexec/pnpnagios/process_perfdata.pl -d hostperfdata
}
(4)修改配置文件templates.cfg
vim /etc/nagios/objects/templates.cfg definehost {
name hosts-pnp
register 0
action_url/pnp4nagios/index.php/graph?host=$hostname$&srv=_host_
process_perf_data 1
}
define service {
name srv-pnp
register 0
action_url/pnp4nagios/index.php/graph?host=$hostname$&srv=$servicedesc$
process_perf_data 1
}
(5)修改host和service配置
vim /etc/nagios/conf.d/192.168.0.12.cfg
把 “define host{
use linux-server”
改為:
define host{
use linux-server,hosts-pnp
修改對應(yīng)的service,比如
把
define service{
use generic-service
host_name 192.168.0.12
service_description check_disk_hda1
check_command check_nrpe!check_hda1
max_check_attempts 5
normal_check_interval 1
}
改為:
define service{
use generic-service,srv-pnp
host_name 192.168.0.12
service_description check_disk_hda1
check_command check_nrpe!check_hda1
max_check_attempts 5
normal_check_interval 1
}
(6)重啟和啟動(dòng)各個(gè)服務(wù):
service nagios restart
service httpd restart
service npcd start
(7) 訪問測試
兩種訪問方法:
ip/nagios/
ip/pnp4nagios/
以上所述是小編給大家分享的nagios的安裝與使用詳細(xì)教程,希望對大家有所幫助。