Nagios基本配置的詳細攻略

   
僞技術人員的成長曆程之38-Nagios基本配置的詳細攻略
這篇整個都是用來講Nagios的localhost.cfg完整的基本功能定義配置,更重要的是要通過配置來理解Nagios的工作方式和原理。絕對詳細到掉渣= =||
 
接上一話,在安裝完Nagios主程序以及Nagios-plugins插件程序之後的配置,最重要的是Nagios的功能定義配置了,它真的可以獨立一章出來講,雖然東西較多,但其實並不難。
 
一.完成Nagios安裝完後的基本配置:
1.處理Nagios功能定義配置文件
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/localhost.cfg-sample /usr/local/nagios/etc/localhost.cfg
 
2.配置Nagios功能定義配置文件:
[root@KCentOS5C ~]# vi /usr/local/nagios/etc/localhost.cfg
----------------------------------------------------------------------------------
###############################################################################
# LOCALHOST.CFG - SAMPLE OBJECT CONFIG FILE FOR MONITORING THIS MACHINE
#
# Last Modified: 11-27-2006
#
# NOTE: This config file is intended to servce as an *extremely* simple
#       example of how you can create your object configuration file(s).
#
###############################################################################
 
第一部分:時間定義段
###############################################################################
###############################################################################
#
# TIME PERIODS
#
###############################################################################
###############################################################################
# This defines a timeperiod where all times are valid for checks,
# notifications, etc.  The classic "24x7" support nightmare. :-)
在時間定義段裏,可以自己定義好幾個指定的時間段並給與命名。Nagios應該在什麼時間內做什麼工作,對於Nagios自己來說並不是直接引用時間參數,而是引用用戶自己定義的時間段的命名,Nagios只會參考和引用用戶定義過的時間段名。
 
define timeperiod{
使用define定義關鍵字timepriod表示該定義段內定義的是時間段。段內的定義請使用兩個大括號來包括。段內的定義項一行一項,時間格式請按照以下。另外,如果要定義多個時間段的話,那麼必須要寫多個define timeperiod {} 段。
 
        timeperiod_name all_days
通過timeperiod_name來指定時間段名。這裏我定義了一個時間段名爲all_days“全天”,然後時間設定從週一到週日全天24小時。
 
        alias           24 Hours A Day, 7 Days A Week
通過alias來指定時間段的說明信息。
 
        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
以上爲時間格式。前面是星期名,後面是24小時制的時間格式。
        }
 
# 'workhours' timeperiod definition
這個是Nagios默認定義的一個時間段,名字叫做workhours“工作時段”,定義的時間也是週一到週五的早上9點到晚上的17點。多樣化的時間段可以豐富Nagios功能配置的靈活性。當Nagios在進行只在工作時間纔有必要進行的操作而休息時間沒有這種必要的時候,就可以使用該時間段進行配置參與。
 
define timeperiod{
 timeperiod_name workhours
 alias  "Normal" Working Hours
 monday  09:00-17:00
 tuesday  09:00-17:00
 wednesday 09:00-17:00
 thursday 09:00-17:00
 friday  09:00-17:00
 }
 
# 'nonworkhours' timeperiod definition
這個也是Nagios默認定義的一個時間段,名字叫做nonworkhours“非工作時段”,定義的時間爲週一到週五的晚上17到早上9點以及雙休日全天。當Nagios在進行只有在休息時間才進行的操作而在工作時間內不進行的情況下,就可以使用該時間段進行配置參與。
 
define timeperiod{
 timeperiod_name nonworkhours
 alias  Non-Work Hours
 sunday  00:00-24:00
 monday  00:00-09:00,17:00-24:00
 tuesday  00:00-09:00,17:00-24:00
 wednesday 00:00-09:00,17:00-24:00
 thursday 00:00-09:00,17:00-24:00
 friday  00:00-09:00,17:00-24:00
 saturday 00:00-24:00
 }
 
# 'none' timeperiod definition
這個是Nagios默認的最後一個時間段,名字叫做none“無時間”,也沒有定義的時間段。還不是很清楚這個時間段會用在什麼情況呢,也許一些永遠都不希望Nagios執行的操作會用此時間段參與配置吧?哈。
 
define timeperiod{
 timeperiod_name none
 alias  No Time Is A Good Time
 }
 
 
 
第二部分:命令定義段
###############################################################################
###############################################################################
#
# COMMANDS
#
###############################################################################
###############################################################################
# NOTE: Sample command definitions can now be found in the sample commands.cfg
#       file
這些命令定義被獨立歸在了commands.cfg文件中了,這裏先不多講了,放到後面。
 
 
第三部分:聯繫人定義段
###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################
# In this simple config file, a single contact will receive all alerts.
# This assumes that you have an account (or email alias) called
# "nagios-admin" on the local host.
在Nagios的諸多工作中都會涉及到聯繫人。當發生監測超出閥值,或者產程告警等情況時,Nagios都會以Email甚至更多方式來告知指定的聯繫人。聯繫人應該是系統當中存在的用戶或者是Email的別名用戶,以便於接收到重要的消息通知。
 
define contact{
使用define定義關鍵字contact表示該定義段內定義的是聯繫人段。段內的定義請使用兩個大括號來包括。段內的定義項一行一項。另外,如果要定義多個聯繫人段的話,那麼必須要寫多個define contact {} 段。
 
        contact_name                    nagios-admin
通過contact_name來指定聯繫人名,這個名應該是系統內用戶名或者是Email用戶別名(推薦後者)。同時,這個聯繫人名也將會是Nagios認可的註冊聯繫人名。(這裏我偷懶,在系統中直接useradd添加了nagios-admin這個用戶)
 
        alias                           Nagios Admin
通過alias來指定該聯繫人的說明信息。
 
        service_notification_period     all_days
設定服務事件通知時間段,後面指定時間段名。請注意,這裏後面跟的參數爲定義過的timeperiods的時間段名。
 
        host_notification_period        all_days
設定主機事件通知時間段,後面指定時間段名。請注意,這裏後面跟的參數爲定義過的timeperiods的時間段名。
 
        service_notification_options    w,u,c,r
設定觸發服務事件通知的選項,這裏後面跟上一些級別類型參數:
w代表warning告警;
u代表unknown未知;
c代表critical嚴重;
r代表recover恢復;
d代表down奔潰。
 
        host_notification_options       d,r
設定觸發主機事件通知的選項,後面也跟上級別類型參數。
 
        service_notification_commands   notify-by-email
設定服務事件通知的命令,該命令的具體內容在command.cfg裏定義。
 
        host_notification_commands      host-notify-by-email
設定主機時間通知的命令,該命令的具體內容在command.cfg裏定義。
 
        email                           nagios-admin@localhost
設定通知郵件的聯繫人的Email地址。
        }
 
 
 
第四部分:聯繫人組定義段
###############################################################################
###############################################################################
#
# CONTACT GROUPS
#
###############################################################################
###############################################################################
# We only have one contact in this simple configuration file, so there is
# no need to create more than one contact group.
聯繫人組就是將若干聯繫人聚合起來的組。
 
define contactgroup{
使用define定義關鍵字contactgroup表示該定義段內定義的是聯繫人組段。段內的定義請使用兩個大括號來包括。段內的定義項一行一項。另外,如果要定義多個聯繫人組段的話,那麼必須要寫多個define contactgroup {} 段。
 
        contactgroup_name       admins
通過contactgroup_name來指定聯繫人組名。
 
        alias                   Nagios Administrators
通過alias來指定該聯繫人組名的簡要信息。
 
        members                 nagios-admin
通過members來指定組成員,組成員必須是contect裏定義過的聯繫人。
        }
 
 
 
第五部分:主機定義段
###############################################################################
###############################################################################
#
# HOSTS
#
###############################################################################
###############################################################################
主機定義段定義了Nagios監測的主機對象,Nagios只監測的在主機定義段裏定義過的主機名。主機定義段裏面有個一個十分有趣的地方,就是他能夠定義主機類,在主機類當中定義一些公共屬性,然後定義個別主機的時候並不需要把每個屬性都一一定義出來,而只需要引用和繼承之前的主機類,就能夠繼承主機類當中的公共屬性,有趣的是類還能繼承類。事先多定義幾個不同的類,在大規模部署監測主機的時候效率將特別高。
 
## Generic host definition template - This is NOT a real host, just a template!
默認Nagios就定義了通用主機的大類generic-host。在這個類中定義了無論什麼系統和條件的所有主機都會共有的一些屬性。
 
define host{
使用define定義關鍵字host表示該定義段內定義的是主機段,也可以是主機類。段內的定義請使用兩個大括號來包括。段內的定義項一行一項。另外,如果要定義多個主機段的話,那麼必須要寫多個define host {} 段。
 
        name                            generic-host    ; The name of this host template
通過name來指定主機類名,這裏的generic-host就是一個主機類名。
 
        notifications_enabled           1        ; Host notifications are enabled
設定啓用主機事件通知
 
        event_handler_enabled           1        ; Host event handler is enabled
設定啓用主機事件處理程序
 
        flap_detection_enabled          1        ; Flap detection is enabled
設定啓用狀態抖動監測。
 
        failure_prediction_enabled      1        ; Failure prediction is enabled
設定啓用故障預測
 
        process_perf_data               1        ; Process performance data
設定啓用進程性能數據記錄
 
        retain_status_information       1        ; Retain status information across program restarts
設定啓用狀態信息保存功能。當Nagios重新啓動的時候不會是空數據,而是先顯示上次離線時最後保留的狀態數據。
 
        retain_nonstatus_information    1        ; Retain non-status information across program restarts
設定啓用非狀態信息保存功能。當Nagios重新啓動的時候不會是空數據,而是先顯示上次離線時最後保留的非狀態數據。
 
 notification_period  all_days    ; Send host notifications at any time
設定事件通知的工作時間段。後面要跟上定義過的時間段名,這裏用全天時間段。
 
        register     0        ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
設定非註冊。此項register爲0值的時候Nagios會理解到該定義段是主機類而爲實體主機的定義段。因此,在自定義主機類段的時候,記得也要加入這一個屬性,用來向Nagios表明該段爲主機類段。
        }
 
## Linux host definition template - This is NOT a real host, just a template!
以下再建立一個Linux主機類段linux-server。這個類同時也繼承了之前的通用主機類generic-host類,也就是說類也可以繼承類。這樣的關係和設定將使得主機設定進一步靈活。
 
define host{
 name    linux-server          ; The name of this host template
 use      generic-host         ; This template inherits other values from the generic-host template
通過use來指定要繼承的主機類名。類也可以繼承類。
 
 check_period   all_days                        ; By default, Linux hosts are checked round the clock
 max_check_attempts  10                     ; Check each Linux host 10 times (max)
設定監測失敗後的最大嘗試次數。
 
  check_command      check-host-alive   ; Default command to check Linux hosts
設定監測主機存活的命令。
 notification_period  workhours   ; Linux admins hate to be woken up, so we only notify during the day
                                            ; Note that the notification_period variable is being overridden from
                                            ; the value that is inherited from the generic-host template!
 notification_interval  15            ; Resend notification every 15 seconds.
設定監測主機的時間間隔,單位爲秒
 
 notification_options  d,u,r         ; Only send notifications for specific host states
設定監測指定主機產生的事件通知的條件選項。這裏後面跟上一些級別類型參數:
w代表warning告警;
u代表unknown未知;
c代表critical嚴重;
r代表recover恢復;
d代表down奔潰。
 
 contact_groups   admins   ; Notifications get sent to the admins by default
指定聯繫人組,這裏的聯繫人組名必須是定義過的。
 
 register   0   ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
設定register表明本段定義的是一個主機類,而不是實體主機。
 }
 
## Windows host definition template - This is NOT a real host, just a template!
這個是我自己添加的Windows的主機類windows-server,當然,它也是繼承了generic-host這個大類,但其中的參數都沒有怎麼變動過。
 
define host{
 name    windows-server
 use      generic-host
 check_period   all_days 
 max_check_attempts    10 
        check_command    check-host-alive
 notification_period        workhours
 notification_interval      15 
 notification_options      d,u,r 
 contact_groups           admins 
 register   0 
 }
 
## Since this is a simple configuration file, we only monitor one host - the
## local host (this machine).
以下爲實體主機的定義了。首先必須要有localhost本地主機的定義段,否則很多基本功能都會有問題。
 
define host{
        use                     linux-server           
通過use來繼承linux-server這個之前專爲Linux主機定義的類。
 
        host_name           localhost
通過host_name來指定主機名,這裏是localhost。另外必須要知道的是,這裏定義的主機名,和真正監測對象的主機的主機名並不一定要完全對的上,這裏定義的主機名只是一個在Naigos系統中註冊的、定義的、Nagios能夠識別的主機標示而已。
 
        alias                    localhost
通過alias寫上一些對該主機的描述。
 
        address                 127.0.0.1
通過address來指定該主機的IP地址。Nagios對監測對象的主要根據是這個IP地址。
        }
 
接下來則是我自己定義的一些主機:
 
define host{
        use                     linux-server           
        host_name            KCentOS5A
        alias                    Kane Cruise CentOS 5 Server A
        address                 192.168.1.10
        }
 
define host{
        use                     windows-server          
        host_name            KCWIN2K3A
        alias                    Kane Cruise Windows Server 2003 A
        address                 192.168.1.14
        }
 
define host{
        use                     windows-server           
        host_name            KCXP1
        alias                    Kane Cruise Windows XP Professional 1
        address                 192.168.1.9
        }
 
 
第六部分:主機組定義段
###############################################################################
###############################################################################
#
# HOST GROUPS
#
###############################################################################
###############################################################################
# We only have one host in our simple config file, so there is no need to
# create more than one hostgroup.
簡而言之就是將定義的主機歸類成主機組。
 
define hostgroup{
使用define定義關鍵字hostgroup表示該定義段內定義的是主機組段。段內的定義請使用兩個大括號來包括。段內的定義項一行一項。另外,如果要定義多個主機組段的話,那麼必須要寫多個define hostgroup {} 段。
 
        hostgroup_name  linux_hosts
通過hostgroup_name來指定主機組名。
 
        alias           Group of Linux Hosts
通過alias來進行對該主機段的描述。
 
        members         localhost,KCentOS5A
通過members來指定該主機組的成員,注意這裏的主機成員必須要是在host裏定義過的主機。
        }
 
define hostgroup{
        hostgroup_name  windows_hosts
        alias                  Group of Windows Hosts
        members            KCXP1,KCWIN2K3A
        }
 
 
 
第七部分:定義服務段
###############################################################################
###############################################################################
#
# SERVICES
#
###############################################################################
###############################################################################
這裏的服務並不是指被監測主機上運行的服務,而是指Nagios所進行的“各種不同功能的監測”工作,一個監測工作就是一個服務。服務定義段就是要定義Nagios將進行什麼樣的監測工作的配置段。而且服務當中也能夠定義服務的類,並且類也能繼承類,運用比較靈活。
 
全部的服務大致可以分爲3大種:第一種是“本地系統監測服務”,就是監測主機Nagios所在主機對自己本地的一些情況的監測,比如本地磁盤佔用情況,本地CPU使用情況等等。第二種是“遠程系統監測服務”,就是遠程主機系統的內部情況,比如被監測主機的磁盤佔用情況,遠程主機的CPU使用情況等等,但是要實現遠程系統監測服務,還必須要再安裝NRPE核心代理的C/S擴展插件程序(這個以後講)。第三種服務是“連通檢測服務”,就是Nagios主機到被監測的遠程主機當中的一些連通性的監測,比如Ping操作,指定端口的TCP/UDP監控,這些服務不需要NRPE也能夠實現。
 
# Generic service definition template - This is NOT a real service, just a template!
默認Nagios已經定義了一個通用服務大類generic-service,這個類當中定義的屬性是無論什麼服務都必須的屬性。
 
define service{
使用define定義關鍵字service表示該定義段內定義的是服務段,也可以是服務類。段內的定義請使用兩個大括號來包括。段內的定義項一行一項。另外,如果要定義多個服務段的話,那麼必須要寫多個define service {} 段。
 
        name                            generic-service  ; The 'name' of this service template
通過name來指定服務類名,這裏的generice-service是一個類名。
 
        active_checks_enabled           1         ; Active service checks are enabled
設定啓用活動監測服務。
 
        passive_checks_enabled          1          ; Passive service checks are enabled/accepted
設定啓用被動監測服務。
 
        parallelize_check               1         ; Active service checks should be parallelized (disabling this can lead to major performance problems)
設定啓用併發活動監測服務。
 
        obsess_over_service             1         ; We should obsess over this service (if necessary)
設定啓用服務防停滯。
 
        check_freshness                 0         ; Default is to NOT check service 'freshness'
設定關閉更新監測。
 
        notifications_enabled           1         ; Service notifications are enabled
設定啓用事件通知。
 
        event_handler_enabled           1         ; Service event handler is enabled
設定啓用事件處理程序。
 
        flap_detection_enabled          1         ; Flap detection is enabled
設定啓用狀態抖動監測。
 
        failure_prediction_enabled      1         ; Failure prediction is enabled
設定啓用故障預測。
 
        process_perf_data               1         ; Process performance data
設定啓用進程性能數據記錄。
 
        retain_status_information       1         ; Retain status information across program restarts
設定啓用狀態信息保存功能。當Nagios重新啓動的時候不會是空數據,而是先顯示上次離線時最後保留的狀態數據。
 
        retain_nonstatus_information    1         ; Retain non-status information across program restarts
設定啓用非狀態信息保存功能。當Nagios重新啓動的時候不會是空數據,而是先顯示上次離線時最後保留的非狀態數據。
 
        is_volatile                     0         ; The service is not volatile
設定服務非易失。
 
        register                        0         ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
設定非註冊。此項register爲0值的時候Nagios會理解到該定義段是主機類而爲實體主機的定義段。因此,在自定義主機類段的時候,記得也要加入這一個屬性,用來向Nagios表明該段爲主機類段。
        }
 
# Local service definition template - This is NOT a real service, just a template!
這裏Nagios還默認定義了一個針對“本地系統監測服務”的類。
 
define service{
        name    local-service     ; The name of this service template
        use    generic-service    ; Inherit default values from the generic-service definition
通過use來繼承generic-service這個類。類也是能夠繼承類的。
 
        check_period              all_days         ; The service can be checked at any time of the day
        max_check_attempts           2   ; Re-check the service up to 4 times in order to determine its final (hard) state
設定監測失敗後最嘗試次數。
 
        normal_check_interval          5   ; Check the service every 5 minutes under normal conditions
設定正常監測服務的間隔,單位秒。
 
        retry_check_interval            1   ; Re-check the service every minute until a hard state can be determined
設定監測失敗後嘗試的間隔,單位秒。
 
        contact_groups            admins   ; Notifications get sent out to everyone in the 'admins' group
設定聯繫組。
 
 notification_options         w,u,c,r   ; Send notifications about warning, unknown, critical, and recovery events
設定監測指定服務產生的事件通知的條件選項。這裏後面跟上一些級別類型參數:
w代表warning告警;
u代表unknown未知;
c代表critical嚴重;
r代表recover恢復;
d代表down奔潰。
 
        notification_interval           15   ; Re-notify about service problems every hour
設定服務通知的間隔。
 
        notification_period        all_days   ; Notifications can be sent out at any time
設定服務通知運行時間。
 
        register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
設定register表明本段定義的是一個服務類,而不是具體的服務。
 }
 
# Remote service definition template - This is NOT a real service, just a template!
我這裏定義了一個針對“遠程系統監測服務”的類,雖然現在沒有加上NRPE,所以暫時遠程系統的檢測目前還無法實現,但是這個服務類卻應該先規劃出來。
 
define service{
 name    remote-service   ; The name of this service template
 use    generic-service     ; Inherit default values from the generic-service definition
        check_period                    all_days   ; The service can be checked at any time of the day
        max_check_attempts              2   ; Re-check the service up to 4 times in order to determine its final (hard) state
        normal_check_interval           5   ; Check the service every 5 minutes under normal conditions
        retry_check_interval            1   ; Re-check the service every minute until a hard state can be determined
        contact_groups             admins   ; Notifications get sent out to everyone in the 'admins' group
       notification_options    w,u,c,r   ; Send notifications about warning, unknown, critical, and recovery events
        notification_interval          20     ; Re-notify about service problems every hour
        notification_period      all_days    ; Notifications can be sent out at any time
        register                        0     ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
 }
 
# Connection service definition template - This is NOT a real service, just a template!
我再定義了一個針對“遠程系統監測服務”的類。
 
define service{
 name    connection-service   ; The name of this service template
 use    generic-service        ; Inherit default values from the generic-service definition
        check_period                    all_days   ; The service can be checked at any time of the day
        max_check_attempts              2   ; Re-check the service up to 4 times in order to determine its final (hard) state
        normal_check_interval           5   ; Check the service every 5 minutes under normal conditions
        retry_check_interval            1   ; Re-check the service every minute until a hard state can be determined
        contact_groups             admins   ; Notifications get sent out to everyone in the 'admins' group
 notification_options          w,u,c,r   ; Send notifications about warning, unknown, critical, and recovery events
        notification_interval          20   ; Re-notify about service problems every hour
        notification_period      all_days   ; Notifications can be sent out at any time
        register                        0     ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
 }
 
以下爲具體服務的定義部分了:
定義服務的本質是選擇爲一個服務指定使用在command.cfg中定義的命令,並且還要給與參數,參數和參數之間通過感嘆號“!”來分隔,參數當中的子參數之間通過逗號“,”來分隔。。而command.cfg裏定義的命令其實就是調用Nagios主路徑/usr/local/nagios/下libexec/目錄中的插件程序。至於他們之間的對應關係我將放到後面獨立一篇詳細展開。
# Define a service to "ping" the local and remote machine
首先定義一個Ping本地主機以及遠程主機的服務,這個服務是屬於“連通類檢測服務”。
 
define service{
        use                             connection-service         ; Name of service template to use
        host_name                       localhost,KCentOS5A,KCWIN2K3A,KCXP1
通過host_name來指定該服務監測的主機,後面跟的必須是在host中定義過的主機名。
 
        service_description             PING
通過service_descripion來對該服務進行簡要描述。
 
 check_command   check_ping!100.0,20%!500.0,60%
通過check_command來指定該服務使用到在command.cfg定義的那個命令,並且後面要給與這個命令的參數,參數和參數之間通過感嘆號“!”來分隔,參數當中的子參數之間通過逗號“,”來分隔。
        }
 
接下來要定義一些“本地系統監測服務”
# Define a service to check the disk space of the root partition
# on the local machine.  Warning if < 20% free, critical if
# < 10% free space on partition.
定義一個服務來監測Nagios本地系統的磁盤使用情況,當剩餘可用空間<20%的時候產生提醒,當剩餘可用空間<10%的時候產生告警。
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Root Partition
 check_command   check_local_disk!20%!10%!/
        }
 
# Define a service to check the number of currently logged in
# users on the local machine.  Warning if > 20 users, critical
# if > 50 users.
定義一個服務來監測Nagios本地系統的當前系統登錄用戶數量,當登錄用戶數量>20的時候產生提醒,當登錄用戶數量>50的時候產生告警。
 
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Current Users
 check_command   check_local_users!20!50
        }
 
# Define a service to check the number of currently running procs
# on the local machine.  Warning if > 250 processes, critical if
# > 400 users.
定義一個服務來監測Nagios本地系統當前運行的進程數量,當進程數>250的時候產生提醒,當進程數>400的時候產生告警。
 
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Total Processes
 check_command   check_local_procs!250!400!RSZDT
        }
 
# Define a service to check the load on the local machine.
定義一個服務來監測Nagios本地系統當前的系統負載狀況。
 
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Current Load
 check_command   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
        }
----------------------------------------------------------------------------------
 
 
二.測試啓動:
1.檢查無誤後啓動Nagios
[root@KCentOS5C ~]# service nagios start
Starting nagios: done.
 
2.檢查Nagios的進程
[root@KCentOS5C ~]# ps aux | grep nagios
----------------------------------------------------------------------------------
nagios    9617  0.1  0.3  22888   892 ?        Ssl  21:30   0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
root      9622  0.0  0.2   3880   660 pts/1    R+   21:30   0:00 grep nagios
----------------------------------------------------------------------------------
 
3.檢查Nagios的日誌
[root@KCentOS5C ~]# cat /usr/local/nagios/var/nagios.log
----------------------------------------------------------------------------------
[1191591001] Nagios 2.9 starting... (PID=9616)
[1191591001] LOG VERSION: 2.0
[1191591001] Finished daemonizing... (New PID=9617)
----------------------------------------------------------------------------------
 
4.通過瀏覽器訪問Nagios的情況
首先會彈出一個對話框,請你輸入訪問Nagios的用戶名和密碼,這裏我輸入之前註冊的kanecruise用戶,口令爲123456。
接着就會彈出Nagios的主界面,這裏文本我沒有辦法表現圖,但是我稍微把一些監測結果複製粘貼上來好了。
----------------------------------------------------------------------------------
Host 
 Service  Status  Last Check  Duration  Attempt  Status Information
 
KCWIN2K3A
 PING
  CRITICAL 10-05-2007 21:32:31 0d 2h 39m 24s 1/2 CRITICAL - Host Unreachable (192.168.1.14) 
 
KCXP1
 PING
  OK 10-05-2007 21:28:44 0d 1h 56m 16s 1/2 PING OK - Packet loss = 0%, RTA = 1.19 ms 
 
KCentOS5A
 PING
 CRITICAL 10-05-2007 21:33:08 0d 2h 38m 47s 1/2 CRITICAL - Host Unreachable (192.168.1.10) 
 
localhost
 Current Load
  OK 10-05-2007 21:29:21 0d 1h 55m 39s 1/2 OK - load average: 0.08, 0.02, 0.00 
 Current Users
  OK 10-05-2007 21:33:46 0d 1h 57m 31s 1/2 USERS OK - 2 users currently logged in 
 PING
  OK 10-05-2007 21:24:59 0d 1h 55m 1s 1/2 PING OK - Packet loss = 0%, RTA = 0.06 ms 
 Root Partition
  OK 10-05-2007 21:28:06 0d 1h 56m 54s 1/2 DISK OK - free space: / 4872 MB (75% inode=96%): 
 Total Processes
  OK 10-05-2007 21:25:36 0d 1h 54m 24s 1/2 PROCS OK: 20 processes with STATE = RSZDT 
----------------------------------------------------------------------------------
 
到這裏,已經比較詳細交代了Nagios的功能定義配置了。但是這樣的程度還是隻是一個基礎,接下去主要講服務的定義,在localhost.cfg當中定義的服務與command.cfg當中定義的命令,以及/usr/local/nagios/libexec/下的插件程序有什麼樣的關係呢?又是對Nagios理解的非常重要的一章
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章