歡迎您光臨本站 註冊首頁

Nagios 札記之二:配置

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

Nagios 札記之二:配置

Nagios 札記之二:配置




主配置文件 nagios.cfg 需要更改的地方:
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
interval_length=1 ; 間隔時間基準由 60s 改為 1s
command_check_interval=10s ; 命令檢查時間間隔,-1 表示儘可能頻繁的進行檢查
date_format=iso8601 ; 日期格式

objects/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 notify-service-by-email
host_notification_commands notify-host-by-email
email admin@test.com
}再定義聯繫人組define contactgroup {
contactgroup_name admins
alias Administrator Group
members sa    ; 添加其它聯繫人用 "," 分隔
}主機監控的配置
define host {
host_name host_name    ; 簡短的主機名稱。
alias alias    ; 別名,可以更詳細的說明主機。
address address    ; IP 地址,也可以寫主機名。如果不定義這個值, nagio 將會用 host_name 去尋找主機。
parents host_names    ; 上一節點的名稱,也就是指從 nagios 伺服器到被監控主機之間經過的節點,可以是路由器、交換機、主機等等。
hostgroups hostgroup_names    ; 簡短的主機組名稱。
check_command command_name    ; 檢查命令的簡短名稱,如果此項留空, nagios 將不會去判斷主機是否 alive 。
max_check_attempts 整數    ; 當檢查命令的返回值不是 "OK" 時,重試的次數。
check_interval 數字    ; 循環檢查的間隔時間。
active_checks_enabled     ; 是否啟用 "active_checks"
passive_checks_enabled     ; 是否啟用 "passive_checks" ,及「被動檢查」
check_period timeperiod_name    ; 檢測時間段簡短名稱,這只是個名稱,具體的時間段要寫在其他的配置文件中。
obsess_over_host     ; 是否啟用主機操作系統探測。
check_freshness     ; 是否啟用 freshness 檢查。freshness 檢查是對於啟用被動檢查模式的主機而言的,其作用是定期檢查主機報告的狀態信息,如果該狀態信息已經過期,freshness 將會強製做主機檢查。
freshness_threshold 數字     ; fressness 的臨界值,單位為秒。 如果定義為 "0" ,則為自動定義。
event_handler command_name    ; 當主機發生狀態改變時,採用的處理命令的簡短的名字(可以在 commands.cfg 中對其定義)
event_handler_enabled     ; 是否啟用 event_handler
low_flap_threshold 數字    ; 抖動的下限值。抖動,即在一段時間內,主機(或服務)的狀態值頻繁的發生變化。
high_flap_threshold 數字   ; 抖動的上限值。
flap_detection_enabled     ; 是否啟用抖動檢查。
process_perf_data     ; 是否啟用 processing of performance data
retain_status_information     ; 程序重啟時,是否保持主機狀態相關的信息。
retain_nonstatus_information     ; 程序重啟時,是否保持主機狀態無關的信息。
contact_groups contact_groups    ; 聯繫人組,在此組中的聯繫人都會收到主機的提醒信息。
notification_interval 整數    ; 重複發送提醒信息的最短間隔時間。默認間隔時間是 "60" 分鐘。如果這個值設置為 "0" ,將不會發送重複提醒。
notification_period timeperiod_name   ; 發送提醒的時間段。非常重要的主機(服務)定義為 24x7 ,一般的主機(服務)就定義為上班時間。如果不在定義的時間段內,無論發生什麼問題,都不會發送提醒。
notification_options     ; 發送提醒包括的情況: d = 狀態為 DOWN , u = 狀態為 UNREACHABLE , r = 狀態恢復為 OK , f = flapping
notifications_enabled     ; 是否開啟提醒功能。"1" 為開啟,"0" 為禁用。一般,這個選項會在主配置文件 (nagios.cfg) 中定義,效果相同。
stalking_options     ; 持續狀態檢測參數,o = 持續的 UP 狀態 , d = 持續的 DOWN 狀態 , u = 持續的 UNREACHABLE 狀態
}服務監控的配置define service {
host_name host_name
service_description service_description
servicegroups servicegroup_names
is_volatile
check_command command_name
max_check_attempts
normal_check_interval
retry_check_interval
active_checks_enabled
passive_checks_enabled
check_period timeperiod_name
parallelize_check
obsess_over_service
check_freshness
freshness_threshold
event_handler command_name
event_handler_enabled
low_flap_threshold
high_flap_threshold
flap_detection_enabled
process_perf_data
retain_status_information
retain_nonstatus_information
notification_interval
notification_period timeperiod_name n
otification_options
notifications_enabled
contact_groups contact_groups
stalking_options
}服務監控的配置和主機監控的配置較為相似,就不一一說明了。

間隔時間的計算方法為:
normal_check_interval x interval_length 秒
retry_check_interval x interval_length 秒
notification_interval x interval_length 秒

主機監控配置的例子define host {
host_name web1
alias web1
address 192.168.0.101
contact_groups admins
check_command check-host-alive
max_check_attempts 5
notification_interval 0
notification_period 24x7
notification_options d,u,r
}對主機 web1 進行 24x7 的監控,默認會每 10 秒檢查一次狀態,累計五次失敗就發送提醒,並且不再重複發送提醒。

服務監控配置的例子define service {
host_name web1
service_description check_http
check_period 24x7
max_check_attempts 3
normal_check_interval 30
contact_groups admins
retry_check_interval 15
notification_interval 3600
notification_period 24x7
notification_options w,u,c,r
check_command check_http
}配置解釋: 24x7 監控 web1 主機上的 HTTP 服務,檢查間隔為 30 秒, 檢查失敗后每 15 秒再進行一次檢查,累計三次失敗就認定是故障併發送提醒。
聯繫人組是 admins 。提醒后恢復到 30 秒一次的 normal_check_interval 檢查。如果服務仍然沒有被恢復,每個小時發送一次提醒。

如果要檢測其他服務,例如,要檢查 ssh 服務是否開啟,更改如下兩行:service_description check_ssh
check_command check_ssh為方便管理,對配置文件的分佈做了如下修改:
nagios.cfg 中增加了:cfg_dir=/usr/local/nagios/etc/hosts
cfg_dir=/usr/local/nagios/etc/services在 hosts 目錄中,為不同類型的主機創建了配置文件,如: app.cfg cache.cfg mysql.cfg web.cfg
並創建了 hostgroup.cfg 文件對主機進行分組,如:define hostgroup {
hostgroup_name app-hosts
alias APP Hosts
members app1,app2
}在 services 目錄中創建了各種服務的配置文件,如: disk.cfg http.cfg load.cfg mysql.cfg
並創建了 servicegroup.cfg 文件對服務進行分組,如:define servicegroup {
servicegroup_name disk
alias DISK
members cache1,check_disk,cache2,check_disk
}作者:Bluedata 來源: http://blog.bluedata.org/nagios-setup/

[火星人 ] Nagios 札記之二:配置已經有388次圍觀

http://coctec.com/docs/service/show-post-2348.html