Nagios的安裝

來源:互聯網
上載者:User

標籤:nagios   monitor   

   監控對於對於系統管理人員的日常營運工作來說是非常重要的,而比較知名的開源監視軟體有Ganglia、Cacti、Nagios、Zabbix等等,而本次就簡單的說下Nagios的安裝部署,因為Nagios是基於web頁面查看管理的,那可以選用lamp或者是lnmp這些比較容易實現的web系統架構來實現即可,Nagios的官網是:https://www.nagios.org/downloads/,當然下載版本建議用最新的穩定版。Nagios的監控實現是由各個外掛程式來完成的它本身是沒有監控功能的,所以Nagios使用非常靈活,而在需要監控不同的平台主機、硬體時用不同的外掛程式,下面從網頁上找的一張圖能很好的說明:650) this.width=650;" src="https://s4.51cto.com/wyfs02/M02/92/19/wKioL1j7lDqDYCBXAADwVryoOFM808.jpg-wh_500x0-wm_3-wmp_4-s_2697766514.jpg" title="nagios.jpg" alt="wKioL1j7lDqDYCBXAADwVryoOFM808.jpg-wh_50" />

得知Nagios監控中的外掛程式SNMP在不同平台的主機、硬體上都有用到,而Linux中有send-nsca和NRPE一般我們常用的是NRPE,監聽的是tcp的5666連接埠;而在Windows主機上使用的是NSClient++,監聽的是12489和5666連接埠,這一點很重要做為被監控的主機上一定要開放這些連接埠。

   在安裝Nagios之前需要先安裝Nagios的監控主機(server端),然後再到被監控主機(clinet端)上安裝相應的外掛程式。

   1、server端:

在安裝之前先要檢查依賴包

[[email protected] ~]# yum -y groupinstall "Development Tools" "Development Libraries"#在配置好yum源的主機上,先檢查下開發包組是否安裝[[email protected] ~]# yum -y install httpd php php-mysql gd gd-devel sendmail openssl-devel#這裡是測試就沒有用編譯包的php和apache,一般來說建議使用編譯包

在依賴關係解決後就開始正常的Nagios安裝,先安裝Nagios的核心引擎和web頁面

[[email protected] ~]# groupadd -r nagcmd#添加nagcmd組[[email protected] ~]# useradd -M -G nagcmd -r -s /sbin/nologin nagios[[email protected] ~]# passwd nagios[[email protected] ~]# usermod -a -G nagcmd apache#把nagcmd組附屬在apache組[[email protected] ~]# cd /usr/local/src/nagios-4.3.1[[email protected] nagios-4.3.1]# ./configure --sysconfdir=/etc/nagios --prefix=/usr/local/nagios --with-command-group=nagcmd --enable-event-broker[[email protected] nagios-4.3.1]# make all && make install[[email protected] nagios-4.3.1]# make install-init && make install-commandmode && make install-config#添加相應的外掛程式[[email protected] nagios-4.3.1]# vim /etc/nagios/objects/contacts.cfg#修改郵件接收人的設定檔,在此就不做過多的說明,設定檔的注釋裡都有,主要改的就是郵箱地址[[email protected] nagios-4.3.1]# make install-webconf#配置web設定檔[[email protected] nagios-4.3.1]# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin#配置Nagios的頁面密碼New password: Re-type new password: Adding password for user nagiosadmin

到此nagios的核心引擎和基本web頁面就已經安裝完畢,在此直接啟動httpd後使用瀏覽器測試下650) this.width=650;" src="https://s1.51cto.com/wyfs02/M00/93/31/wKioL1kJPEOztm_JAABS_KZ_u8M327.png-wh_500x0-wm_3-wmp_4-s_262265194.png" title="nagios_web.png" alt="wKioL1kJPEOztm_JAABS_KZ_u8M327.png-wh_50" />

此時的Nagios是不具備任何監控功能,因為這台Nagios主機是Linux伺服器,所以監控外掛程式在這裡選比較常用的nrpe,在安裝nrpe之前要先安裝好Nagios的外掛程式plugins

[[email protected] nagios-4.3.1]# cd ../nagios-plugins-2.1.4[[email protected] nagios-plugins-2.1.4]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios[[email protected] nagios-plugins-2.1.4]# make && make install[[email protected] nagios-plugins-2.1.4]# chkconfig --add nagios#添加Nagios的服務[[email protected] nagios-plugins-2.1.4]# chkconfig nagios on#Nagios開機自啟動[[email protected] nagios-plugins-2.1.4]# /etc/init.d/nagios start[[email protected] nagios-plugins-2.1.4]# getenforce#此處要注意的是要檢查是否伺服器上有開啟selinux,如果有開啟要選擇關閉吧或者在selinux中添加nagios的相應檔案到可以執行的標籤中Enforcing[[email protected] nagios-plugins-2.1.4]# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/[[email protected] nagios-plugins-2.1.4]# chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

此時在server端上的Nagios的外掛程式就已經安裝完畢,此時便可以安裝Nagios的nrpe外掛程式

[[email protected] nagios-plugins-2.1.4]# cd ../nrpe-3.0.1/[[email protected] nrpe-3.0.1]# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl --sysconfdir=/etc/nagios[[email protected] nrpe-3.0.1]# make all && make install-plugin

這樣在server端上的Nagios就已經安裝部署完畢,此時Nagios已經可以自行監控本機。650) this.width=650;" src="https://s4.51cto.com/wyfs02/M00/93/51/wKiom1kJ_bqSAe7YAADyYaRHjR0700.png-wh_500x0-wm_3-wmp_4-s_2080015648.png" title="nagios_server.png" alt="wKiom1kJ_bqSAe7YAADyYaRHjR0700.png-wh_50" />

   2、clinet端:

此處的用戶端為了快速簡單的部署實現,在這裡就用另外一台Linux伺服器來搭建。同理,在Nagios的client端下也要添加相應的使用者。當然,也要先安裝好Nagios的外掛程式

[[email protected] ~]# useradd -M -r -s /sbin/nologin nagios[[email protected] ~]# cd /usr/local/src/[[email protected] src]# cd nagios-plugins-2.1.4[[email protected] nagios-plugins-2.1.4]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios[[email protected] nagios-plugins-2.1.4]# make all && make install

在外掛程式安裝完畢後開始安裝nrpe

[[email protected] nagios-plugins-2.1.4]# cd ../nrpe-3.0.1/[[email protected] nrpe-3.0.1]# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl --sysconfdir=/etc/nagios[[email protected] nrpe-3.0.1]# make all && make install-plugin[[email protected] nrpe-3.0.1]# make install-daemon && make install-config && make install-init && make install-inet

到這裡Nagios的nrpe部分就安裝結束了,以下做一些基本配置

[[email protected] nrpe-3.0.1]# vim /etc/nagios/nrpe.cfg…略…allowed_hosts=192.168.218.128#在這裡的ip改成server端的Nagios的監聽ip…略…command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1#此處根據磁碟的實際使用的盤符情況修改…略…[[email protected] nrpe-3.0.1]# /etc/init.d/nrpe start

在安裝好後做一些基本的驗證,這裡要注意的是這些驗證需要在監控server主機上做,被監控主機需要開啟5666連接埠

[[email protected] nrpe-3.0.1]# cd /usr/local/nagios/libexec/[[email protected] libexec]# ./check_nrpe -H 192.168.218.129#檢查被監控主機的IP,這樣有列印出版本號碼就是正常的NRPE v3.0.1

這樣Nagios的安裝就完成了,而Nagios的家目錄或檔案的含義也很簡單,如下:

目錄
解釋
bin
Nagios的二進位檔案的目錄
sbin Nagios CGI 檔案所在目錄,也就是執行外部命令所需檔案所在的目錄
share Nagios網頁檔案所在的目錄,建議這裡去找一下中文的資料便於查閱
libexec Nagios 外部外掛程式所在目錄
var Nagios 記錄檔、lock 等檔案所在的目錄
var/archives Nagios 日誌自動歸檔目錄
var/rw 用來存放外部命令檔案的目錄

當然我這裡是指定Nagios的設定檔路徑在/etc/nagios路徑下,如果沒有指定的話預設預設是在Nagios的家目錄下,而配置的一些檔案或目錄的含義也很簡單,關係如下:

檔案名稱或目錄名 用途
cgi.cfg 控制CGI訪問的設定檔
nagios.cfg Nagios 主設定檔
resource.cfg 變數定義檔案,又稱為資源檔,在些檔案中定義變數,以便由其他設定檔引用,如$USER1$
objects objects 是一個目錄,在此目錄下有很多設定檔範本,用於定義Nagios 對象
objects/commands.cfg 命令定義設定檔,其中定義的命令可以被其他設定檔引用
objects/contacts.cfg
定義連絡人和連絡人群組的設定檔
objects/localhost.cfg 定義監控本地主機的設定檔
objects/printer.cfg 定義監控印表機的一個設定檔範本,預設沒有啟用此檔案
objects/switch.cfg 定義監控路由器的一個設定檔範本,預設沒有啟用此檔案
objects/templates.cfg 定義主機和服務的一個模板設定檔,可以在其他設定檔中引用
objects/timeperiods.cfg 定義Nagios 監控時間段的設定檔
objects/windows.cfg 監控Windows 主機的一個設定檔範本,預設沒有啟用此檔案

在此時Nagios還是不能用的還有一些基礎配置需要修改才能正常的使用,在server端進入sysconfigdir目錄,先要根據實際情況修改一下commandss.cfg檔案,添加以下內容:

[[email protected] nagios]# vim objects/commands.cfgdefine command{        command_name    check_nrpe        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$        }

在Nagios的預設設定檔下是沒有Linux的設定檔所以如果是用於監控Linux主機,需要自行定義寫設定檔,在此就用簡單的寫了一個Linux下使用的模板:

[[email protected] nagios]# vim objects/linux.cfgdefine host{        use             linux-server        host_name       linuxhost        alias           My linux Server        address         192.168.218.129    ;這裡填被監控主機的IP        }define service{        use                     generic-service        host_name               linuxhost        service_description     CHECK_USERS        check_command           check_nrpe!check_users        }define service{        use                     generic-service        host_name               linuxhost        service_description     CHECK_LOAD        check_command           check_nrpe!check_load        }define service{        use                     generic-service        host_name               linuxhost        service_description     CHECK_SDA1        check_command           check_nrpe!check_sda1        }define service{        use                     generic-service        host_name               linuxhost        service_description     CHECK_ZOMBIE_PROCS        check_command           check_nrpe!check_zombie_procs        }define service{        use                     generic-service        host_name               linuxhost        service_description     CHECK_TOTAL_PROCS        check_command           check_nrpe!check_total_procs        }[[email protected] nagios]# chown nagios:nagios linux.cfg#修改下設定檔的屬組

在linux.cfg設定檔修改好後還需要 在nagios.cfg添加環境變數:

[[email protected] nagios]# vim nagios.cfg…略…cfg_file=/etc/nagios/objects/linux.cfg…略…

正在修改後可以用Nagios的設定檔驗證檢查

[[email protected] nagios]# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfgNagios Core 4.3.1Copyright (c) 2009-present Nagios Core Development Team and Community ContributorsCopyright (c) 1999-2009 Ethan GalstadLast Modified: 02-23-2017License: GPLWebsite: https://www.nagios.orgReading configuration data...   Read main config file okay...   Read object config files okay...Running pre-flight check on configuration data...Checking objects...        Checked 13 services.        Checked 2 hosts.        Checked 1 host groups.        Checked 0 service groups.        Checked 1 contacts.        Checked 1 contact groups.        Checked 25 commands.        Checked 5 time periods.        Checked 0 host escalations.        Checked 0 service escalations.Checking for circular paths...        Checked 2 hosts        Checked 0 service dependencies        Checked 0 host dependencies        Checked 5 timeperiodsChecking global event handlers...Checking obsessive compulsive processor commands...Checking misc settings...Total Warnings: 0Total Errors:   0Things look okay - No serious problems were detected during the pre-flight check[[email protected] nagios]# /etc/init.d/nagios restart

像這樣就是沒有報錯的,再重啟下Nagios就可以了,這樣基本的Nagios的安裝就完畢了,這裡需要注意的是在Nagios的server端需要開啟80、443連接埠用於Web管理頁面的正常瀏覽,當然這也是一些基本的配置部署,如果要實現更多的功能還需要進一步的修改設定檔。

本文出自 “技術隨筆” 部落格,謝絕轉載!

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.