Nagios監控基礎安裝與監控項部署(下)

來源:互聯網
上載者:User

標籤:nrpe snmp

上文總結了nagios監控的基礎安裝配置,現在來總結一下Nagios監控項部署


一、Nagios服務端監控部署


1、Nagios服務端目錄與相關設定檔說明

Nagios 安裝完成後,/usr/local/nagios/目錄下會產生 nagios 相關目錄及設定檔,預設的的設定檔在/usr/local/nagios/etc 目錄下。詳細的描述如下:


a)nagios安裝後的目錄結構

[[email protected] ~]# ll /usr/local/nagios/              # Nagios 安裝後的目錄結構total 32drwxrwxr-x.  2 nagios nagios 4096 Jun  6 15:53 bin      # Nagios 相關命令drwxrwxr-x.  3 nagios nagios 4096 Jun  6 15:53 etc      # Nagios 設定檔drwxr-xr-x.  2 root   root   4096 Jun  6 15:52 include  # Nagios 引用檔案drwxrwxr-x.  2 nagios nagios 4096 Jun  6 15:53 libexec     # Nagios 外掛程式目錄drwxrwxr-x.  2 nagios nagios 4096 Jun  6 15:40 sbin      # Nagios 外部命令drwxrwxr-x. 11 nagios nagios 4096 Jun  6 15:52 share      # Nagios Web 頁面展示相關目錄drwxrwxr-x.  5 nagios nagios 4096 Jun  6 18:41 var      # Nagios 資料及日誌目錄

       所有用戶端本地的監控都是通過執行libexec目錄下的外掛程式來實現的,另外,如果開啟了snmp,nagios服務端也可以主動抓取


b)nagios核心設定檔說明

    Nagios主設定檔為nagios.cfg,預設在/usr/local/nagios/etc/下,另外,在/usr/local/nagios/etc/下有個objects目錄(類似nginx中的extra目錄),裡面存放的是主設定檔nagios.cfg包含的其他nagios設定檔:如下:

[[email protected] ~]# tree /usr/local/nagios/etc/    # Nagios 設定檔目錄/usr/local/nagios/etc/|-- cgi.cfg|-- htpasswd.users # 登入 Nagios Web 頁面時的使用者名稱密碼認證|-- nagios.cfg         ##主設定檔|-- nrpe.cfg          # 用戶端設定檔|-- objects          # 主設定檔包含的設定檔目錄,用於定義nagios對象|   |-- commands.cfg    # 存放 Nagios 自己定義的命令(與linux裡的外掛程式命令關聯)|   |-- contacts.cfg    # 用於配置警示連絡人|   |-- hosts.cfg      # 用於配置被監控的主機|   |-- localhost.cfg    # 用於定義對原生監控條目|   |-- printer.cfg     # 用於定義對印表機的監控條目|   |-- services.cfg    # 用於配置被監控的服務|   |-- switch.cfg     # 用於定義對交換器的監控條目|   |-- templates.cfg    # 模板設定檔|   |-- timeperiods.cfg   # 用於配置警示周期時間|   `-- windows.cfg     # 用於定義對 Windows 的監控條目`-- resource.cfg

    主配置nagios.cfg中可以指定單獨包含一個cfg檔案,也可以指定包含一個目錄,而這個被包含目錄下所有的cfg檔案也都會被nagios.cfg包含:


2、主設定檔nagios.cfg配置過程

[[email protected] ~]# cd /usr/local/nagios/etc/ 

[[email protected] etc]# ls

cgi.cfg  htpasswd.users  nagios.cfg  nrpe.cfg  objects  resource.cfg


a)增加主機和服務的設定檔

[[email protected] etc]# vim nagios.cfg +34#20170605cfg_file=/usr/local/nagios/etc/objects/hosts.cfgcfg_file=/usr/local/nagios/etc/objects/services.cfgcfg_dir=/usr/local/nagios/etc/objects/services

#---cfg_dir是為備用增加的一個service目錄,作用:在目錄下的檔案只要符合*.cfg就可以被nagios載入。使用指令碼批量部署時,可以非常方便的隨機命名設定檔。

#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

#---localhost.cfg為服務端本地設定檔,注釋掉,然後進行統一監控


b)根據已有資料產生hosts.cfg主機檔案

[[email protected] etc]# cd /usr/local/nagios/etc/objects/[[email protected] objects]# head -51 localhost.cfg > hosts.cfg[[email protected] objects]# chown nagios.nagios /usr/local/nagios/etc/objects/hosts.cfg


c)產生services.cfg服務檔案

[[email protected] objects]# touch services.cfg    #---預留[[email protected] objects]# chown nagios.nagios services.cfg


d)產生服務的設定檔目錄,此目錄下所有的*.cfg設定檔,都會被自動被包含到主設定檔中生效!

[[email protected] objects]# mkdir services [[email protected] objects]# chown nagios.nagios services


3、配置nagios服務端監控項

1)hosts.cfg設定檔說明

#---hosts.cfg是用來存放nagios要監控的主機的相關配置

#---hosts.cfg主機定義部分的參數說明:

define host{                           #此為定義被監控主機的設定檔 

 use                linux-server      #引用類,定義主機使用的模板,在templates.cfg中預定義 

 host_name          web01          #指定主機名稱,並不是實際機器的主機名稱,自己定義,方便以後在定義服務時調用 

alias               web01           #別名 

address             10.0.0.8           #指定被監控主機的地址 

check_command       check-host-alive   #檢查主機存活命令,來自commands.cfg

max_check_attempts      3              #故障後,最大嘗試檢測次數

normal_check_interval   2              #正常檢查時間間隔,單位分鐘

retry_check_interval    2              #故障後,重試的檢查間隔,單位分鐘

check_period            24x7           #檢查周期,參見timeperiods.cfg

notification_interval   300            #故障後兩次警示的時間間隔,單位分鐘

notification_period     24x7           #一天內通知的周期。一天或半天,參見timeperiods.cfg

notification_options    d,u,r          #主機狀態通知選項,down,unreacheable,recovery

contact_groups          admins         #警示到admins    使用者組。在contacts.cfg中定義

}                                     


2)配置hosts.cfg,添加你想要監控的用戶端主機及主機群組(HOST GROUP)。

以用戶端web01、web02主機為例:

[[email protected] ~]# cd /usr/local/nagios/etc/objects    #---nagios.cfg包含的輔助設定檔目錄[[email protected] objects]# cat hosts.cfg#client_host# Define a host for the local machinedefine host{    use             linux-server    host_name       web01    alias           web01    address         10.0.0.8}define host{    use             linux-server    host_name       web02    alias           web02    address         10.0.0.7}define host{    use             linux-server    host_name       nagios01    alias           nagios01    address         10.0.0.71}# Define an optional hostgroup for Linux machinesdefine hostgroup{    hostgroup_name  linux-servers    alias           Linux Servers    members         web01,web02,nagios01}


3)配置services.cfg,定義要監控的主機資源

    services.cfg檔案是配置監控服務的,是nagios核心的設定檔之一,(伺服器在50台以內時)自己想要監控的多半服務配置都能添加在這裡

註:該檔案需要手動添加

services.cfg配置參數:

define service {

    use                 generic-service

    host_name           web01

    service_description Current Load

    check_command       check_nrpe!check_load

    max_check_attempts      2

    normal_check_interval   4

    retry_check_interval    4

    check_period            24x7

    retry_interval          1

    notification_interval   1440

    notification_period     24x7

    notification_options    w,c,u,r

    contact_groups          admins

    process_perf_data       1

#retain_nonstatus_information 0

}


*對監控用戶端本地資源的配置:

[[email protected] objects]# cat services.cfg###################################           被動監控             ####################################磁碟分割define service {    use                 generic-service    host_name           web01,web02,nagios01    service_description Disk Partition    check_command       check_nrpe!check_disk}#swapdefine service {    use                 generic-service    host_name           web01,web02,nagios01    service_description Swap Useage    check_command       check_nrpe!check_swap}#記憶體define service {    use                 generic-service    host_name           web01,web02,nagios01    service_description Mem Useage    check_command       check_nrpe!check_mem}#以上監控項,可以通過templates.cfg簡寫成如下配置:#系統負載define service {    use                 generic-service    host_name           web01,web02,nagios01    service_description Current Load    check_command       check_nrpe!check_load}#磁碟I/Odefine service {    use                 generic-service    host_name           web01,web02,nagios01    service_description Disk I/O stat    check_command       check_nrpe!check_iostat!5!11}###################    主動式監控    ####################PING監控define service {    use                 generic-service    host_name           web01,web02,nagios01    service_description PING    check_command       check_ping!100.2,20%!500.0,60%}


4)調試hosts.cfg和service.cfg的所有配置

[[email protected] etc]# /etc/init.d/nagios checkconfig    #---檢查文法Running configuration check... OK.



二、小結 

    在nagios監控項部署過程中,有很多問題出現,本人也正在對nagios進行仔細研究。關於nagios及zabbix的博文會持續更新









本文出自 “Linuxgao” 部落格,謝絕轉載!

Nagios監控基礎安裝與監控項部署(下)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.