Nagios遠(yuǎn)程監(jiān)控安裝與配置詳解圖文第3/3頁
2、增加新的配置文件
先創(chuàng)建簡單的配置文件timeperiods.cfg,其內(nèi)容如下:
define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-24:00
monday 00:00-24:00
tuesday 00:00-24:00
wednesday 00:00-24:00
thursday 00:00-24:00
friday 00:00-24:00
saturday 00:00-24:00
} |
第二個(gè)手動創(chuàng)建的配置文件是 contacts.cfg,其格式如下:
define contact {
contact_name sa //不要有空格
alias system administrator
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands service-notify-by-sms,service-
notify-by-email //這個(gè)命令讀配置文件miscommands.cfg
host_notification_commands host-notify-by-email,host-noti
fy-by-sms //這個(gè)命令讀配置文件miscommands.cfg
email sery@163.com
pager 13333333333 //手機(jī)號,收報(bào)警短信
} //不要把這個(gè)符號寫掉了
define contact {
contact_name sery
alias system administrator
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands service-notify-by-sms,service-
notify-by-email
host_notification_commands host-notify-by-email,host-noti
fy-by-sms
email sery@sohu.com
pager 13312345678
} |
緊接著的第三個(gè)手動創(chuàng)建的配置文件是contactgroups.cfg文件,這個(gè)文件是依照上一個(gè)文件contacts.cfg來的,contactgroups文件相對簡單一些,其格式如下:
define contactgroup {
contactgroup_name sagroup //不要用空格
alias system administrator group
members sa,sery //本例有2個(gè)成員
} |
關(guān)鍵的角色終于登場,這就是配置文件hosts.cfg。下面是我定義的兩個(gè)主機(jī)的基本樣式:
#define monitor host
#################################################################
# Wangjing IDC servers #
#################################################################
define host {
host_name nagios-server
alias nagios server
address 61.x..x.49
contact_groups sagroup //多個(gè)聯(lián)系組用逗號分隔, |
再一個(gè)重量級的配置文件是services.cfg,沒有這個(gè)文件,什么監(jiān)控也沒用。下面給出一個(gè)樣式文件:
#service definition
##############################################################
# Wangjing IDC servers service for host-live #
##############################################################
define service {
host_name nagios-server //來源:hosts.cfg
service_description check-host-alive
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup //來源:contactgroups.cfg
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check-host-alive //檢查主機(jī)是否存活
}
define service {
host_name 74-210
service_description check_tcp 80
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_tcp!80 //檢查tcp 80端口服務(wù)是否正常
} |
主機(jī)組配置文件hostgroups.cfg,這是一個(gè)可選的項(xiàng)目,它建立在文件hosts之上,其格式如下:
define hostgroup {
hostgroup_name sa-servers
alias sa servers
members nagios-server,24-25,24-26 //用逗號間隔多個(gè)主機(jī)
} |
千辛萬苦,終于把這些配置給做好保存,現(xiàn)在幾乎有點(diǎn)迫不及待了,運(yùn)行程序/usr/local/nagios –v /usr/local/nagios/etc/nagios.cfg來檢查所有配置文件的正確性。如果十分幸運(yùn)的話,運(yùn)行完畢將在輸出尾部出現(xiàn):
Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check |
[root@netmonitor nagios]# bin/nagios -v etc/nagios.cfg Nagios 2.5 Copyright (c) 1999-2006 Ethan Galstad (http://www.nagios.org) Last Modified: 07-13-2006 License: GPL Reading configuration data... Error: Could not find any host matching 'nagios-server' Error: Could not expand member hosts specified in hostgroup |
驗(yàn)收
用瀏覽器輸入nagios所在服務(wù)器的ip及目錄,如http://61.135.X..X/nagios,再輸驗(yàn)證所需的用戶名和密碼,就可點(diǎn)擊頁面右邊的相關(guān)連接來查看各種狀態(tài)。關(guān)掉某個(gè)被nagios監(jiān)控主機(jī)的服務(wù)或者拔掉某個(gè)服務(wù)器的網(wǎng)線,等幾分鐘,點(diǎn)擊超連接“Service Detail”觀察頁面狀態(tài)看是否有紅色的醒目的報(bào)警出現(xiàn)。
一會兒,就會收到報(bào)警短信和報(bào)警郵件,然后在把測試所有的服務(wù)開啟或把拔下來的網(wǎng)線查上去,片刻后,網(wǎng)頁里的紅色報(bào)警表格消失,手機(jī)短信或郵件通知故障恢復(fù)。如果你的情況也這樣,那么真正大功告成。
Nagios的功能十分強(qiáng)大,在我的項(xiàng)目里,因?yàn)槲业男枨蟛煌M可能的簡化了nagios而沒有使用代理、多更多插件等功能,在一個(gè)不超過1000個(gè)服務(wù)器的網(wǎng)絡(luò)規(guī)模里,它工作得很好。如果有更多的服務(wù)器,建議使用mysql數(shù)據(jù)來管理監(jiān)控對象。在部署nagios的過程中,我多很多選項(xiàng)作了取舍,更詳細(xì)的情況請參照官方的文檔。
- iOS10 適配遠(yuǎn)程推送功能實(shí)現(xiàn)代碼
- iOS實(shí)現(xiàn)遠(yuǎn)程推送原理及過程
- iOS實(shí)現(xiàn)播放遠(yuǎn)程網(wǎng)絡(luò)音樂的核心技術(shù)點(diǎn)總結(jié)
- iOS10最新實(shí)現(xiàn)遠(yuǎn)程通知的開發(fā)教程詳解
- iOS開發(fā)之運(yùn)動事件和遠(yuǎn)程控制
- 詳解iOS本地推送與遠(yuǎn)程推送
- iOS消息遠(yuǎn)程推送通知
- iOS實(shí)時(shí)監(jiān)控網(wǎng)絡(luò)狀態(tài)的改變
- iOS實(shí)現(xiàn)實(shí)時(shí)檢測網(wǎng)絡(luò)狀態(tài)的示例代碼
- iOS中的實(shí)時(shí)遠(yuǎn)程配置全紀(jì)錄
相關(guān)文章
XP與98系統(tǒng)雙網(wǎng)卡共享上網(wǎng)設(shè)置方法
XP與98系統(tǒng)雙網(wǎng)卡共享上網(wǎng)設(shè)置方法...2007-03-03
不錯(cuò)的一篇網(wǎng)絡(luò)管理員入門與基礎(chǔ)技術(shù)文章
不錯(cuò)的一篇網(wǎng)絡(luò)管理員入門與基礎(chǔ)技術(shù)文章...2007-03-03
推薦一個(gè)電信網(wǎng)絡(luò)工程師講解禁路由上網(wǎng)的破解方法
推薦一個(gè)電信網(wǎng)絡(luò)工程師講解禁路由上網(wǎng)的破解方法...2007-04-04



