Nagios遠程監(jiān)控安裝與配置詳解圖文
2、增加新的配置文件
先創(chuàng)建簡單的配置文件timeperiods.cfg,其內容如下:
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
} |
第二個手動創(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 //這個命令讀配置文件miscommands.cfg
host_notification_commands host-notify-by-email,host-noti
fy-by-sms //這個命令讀配置文件miscommands.cfg
email sery@163.com
pager 13333333333 //手機號,收報警短信
} //不要把這個符號寫掉了
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
} |
緊接著的第三個手動創(chuàng)建的配置文件是contactgroups.cfg文件,這個文件是依照上一個文件contacts.cfg來的,contactgroups文件相對簡單一些,其格式如下:
define contactgroup {
contactgroup_name sagroup //不要用空格
alias system administrator group
members sa,sery //本例有2個成員
} |
關鍵的角色終于登場,這就是配置文件hosts.cfg。下面是我定義的兩個主機的基本樣式:
#define monitor host
#################################################################
# Wangjing IDC servers #
#################################################################
define host {
host_name nagios-server
alias nagios server
address 61.x..x.49
contact_groups sagroup //多個聯系組用逗號分隔, |
再一個重量級的配置文件是services.cfg,沒有這個文件,什么監(jiān)控也沒用。下面給出一個樣式文件:
#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 //檢查主機是否存活
}
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端口服務是否正常
} |
主機組配置文件hostgroups.cfg,這是一個可選的項目,它建立在文件hosts之上,其格式如下:
define hostgroup {
hostgroup_name sa-servers
alias sa servers
members nagios-server,24-25,24-26 //用逗號間隔多個主機
} |
千辛萬苦,終于把這些配置給做好保存,現在幾乎有點迫不及待了,運行程序/usr/local/nagios –v /usr/local/nagios/etc/nagios.cfg來檢查所有配置文件的正確性。如果十分幸運的話,運行完畢將在輸出尾部出現:
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 |
驗收
用瀏覽器輸入nagios所在服務器的ip及目錄,如http://61.135.X..X/nagios,再輸驗證所需的用戶名和密碼,就可點擊頁面右邊的相關連接來查看各種狀態(tài)。關掉某個被nagios監(jiān)控主機的服務或者拔掉某個服務器的網線,等幾分鐘,點擊超連接“Service Detail”觀察頁面狀態(tài)看是否有紅色的醒目的報警出現。
一會兒,就會收到報警短信和報警郵件,然后在把測試所有的服務開啟或把拔下來的網線查上去,片刻后,網頁里的紅色報警表格消失,手機短信或郵件通知故障恢復。如果你的情況也這樣,那么真正大功告成。
Nagios的功能十分強大,在我的項目里,因為我的需求不同而盡可能的簡化了nagios而沒有使用代理、多更多插件等功能,在一個不超過1000個服務器的網絡規(guī)模里,它工作得很好。如果有更多的服務器,建議使用mysql數據來管理監(jiān)控對象。在部署nagios的過程中,我多很多選項作了取舍,更詳細的情況請參照官方的文檔。



