X

Nagios Core 4 於 Debian Linux Stretch 架設

Nagios 3 的設定、架設等等,可以參考此篇:Nagios 安裝設定 於 Debian、Ubuntu Linux

上述是使用 Debian、Ubuntu Linux 官方包的 APT 套件架設,此篇介紹的是直接下載 Source code 來編譯架設。

Nagios Core 4 於 Debian Linux Stretch 架設

首先先說明為何要這麼費工手動編譯 Source code...

因為 Debian Linux Stretch 的 Nagios 3 不見了,而且要裝回 jessie 版的 Nagios 3 也因為套件衝突無法安裝,所以只好手動編譯來架設 Nagios 4。

先來看看 Nagios 3 和 Nagios 4 的差異

Nagios 架設需要下述幾個套件:

  • Nagios Core
  • Nagios Plugins # 可以想成是 client,都是 check script
  • Nagios NRPE # 監控遠端機器會需要這個套件

Nagios 4 Core 下載

Nagios 4 Core 安裝架設

下述步驟參考自此篇:Nagios 4 安裝架設參考文件 PDF:Installing Nagios Core From Source

  1. wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.2.0.tar.gz # 可自行於官網下載最新版
  2. sudo apt-get install build-essential libgd-dev php-gd
  3. sudo useradd nagios
  4. sudo groupadd nagcmd
  5. sudo usermod -a -G nagcmd nagios
  6. sudo usermod -a -G nagios,nagcmd www-data
  7. tar zxvf nagios-4.2.0.tar.gz
  8. cd nagios-4.2.0
  9. ./configure --with-command-group=nagios --with-mail=/usr/sbin/sendmail --with-httpd-conf=/etc/apache2/
    • Nagios executable: nagios
    • Nagios user/group: nagios,nagios
    • Command user/group: nagios,nagios
    • Install ${prefix}: /usr/local/nagios
    • Install ${includedir}: /usr/local/nagios/include/nagios
    • Lock file: ${prefix}/var/nagios.lock
    • Check result directory: ${prefix}/var/spool/checkresults
    • Init directory: /etc/init.d
    • Apache conf.d directory: /etc/apache2/
    • Mail program: /usr/sbin/sendmail
    • IOBroker Method: epoll
    • Web Interface Options:
      • HTML URL: http://localhost/nagios/
      • CGI URL: http://localhost/nagios/cgi-bin/
      • Traceroute (used by WAP): /usr/bin/traceroute
    • config
      • /usr/local/nagios/etc
      • /etc/apache2/conf.d/nagios.conf

Nagios 4 Plugins 安裝架設

  1. wget http://nagios-plugins.org/download/nagios-plugins-2 .1.2.tar.gz # 可自行於官網下載最新版
  2. tar zxvf nagios-plugins-2.1.2.tar.gz
  3. cd nagios-plugins-2.1.2
  4. ./configure
  5. make
  6. # make check # 這個步驟可以跳過,此步驟要輸入很多東西,大概會花掉1hr
  7. sudo make install
  8. make installcheck

Nagios 4 NRPE 安裝架設

下述架設參考自下述:

NRPE 安裝步驟

  1. apt install libssl-dev # ./configure 遇到 configure: error: Cannot find ssl headers
  2. git clone https://github.com/NagiosEnterprises/nrpe/
  3. cd nrpe
  4. ./configure
  5. make all
  6. make install-groups-users
  7. make install
  8. make install-config
  9. make install-inetd
  10. make install-init
  11. systemctl enable nrpe
  12. systemctl start nrpe
  13. netstat -at | egrep "nrpe|5666"
  14. /usr/local/nagios/libexec/check_nrpe -H localhost
    NRPE v3.0
  15. cat /etc/systemd/system/multi-user.target.wants/nrpe.service # 確認 systemd 有 nrpe.service
  16. sudo systemctl restart nrpe.service # 重新啟動看看
  17. sudo ln -s /usr/local/nagios/etc /etc/nagios # 將設定檔丟到 /etc/nagios 方便 Debian 以前的設定習慣

測試

  • /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
  • /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_load

Nagios 幾個參數設定

增加 check_nrpe_1arg 的參數

  • vim /etc/nagios/object/commands.cfg # 最下面增加下述
    define command {
    command_name check_nrpe_1arg
    command_line $USER1$/check_nrpe $ARG1$
    }

設定通知人、Email (ops)

  • sudo vim /etc/nagios/objects/contacts.cfg # 找到 email 修改即可

Nagios 3 與 Nagios 4 Client V2 與 V3 版本相容的設定

  1. tail -f /var/log/syslog # 可見到下述訊息
    Sep 1 08:31:01 yotta check_nrpe: Remote 192.168.1.108 accepted a Version 2 Packet
    Sep 1 08:31:05 yotta check_nrpe: Remote 192.168.1.101 does not support Version 3 Packets
    Sep 1 08:31:05 yotta check_nrpe: Remote 192.168.1.101 accepted a Version 2 Packet
  2. 參考自:'check_nrpe' command definition
  3. vim /etc/nagios/object/commands.cfg # 最下面增加下述# Remote 192.168.1.108 does not support Version 3 Packets
    define command {
    command_name check_nrpe_v2
    command_line $USER1$/check_nrpe -2 -H $HOSTADDRESS$ -p 5666 -c $ARG1$
    }

Nagios Remote Client 的架設、設定

Nagios 要監控的機器,需要安裝下述:

  • Nagios Plugins # 可以想成是 client,都是 check script
  • Nagios NRPE # 監控遠端機器會需要這個套件
  • 這兩個套件的安裝步驟與上述都一樣(./configure、make ... 即可)
  • 其它設定可參考內部設定檔的範例,或者此篇最上面的連結(Debian、Ubuntu Linux 架設那篇)

相關網頁

Tsung: 對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.
Related Post