天天看點

Nagios監控平台搭建--安裝篇

一、服務端安裝:

1、在服務端搭建lamp環境

Yum  install -y  httpd  php 

2、服務端安裝nagios主程式

useradd   nagios

./configure  --prefix=/usr/local/nagios  --with-command-group=nagios

./configure時如果發現perl  command not  found時要安裝 perl這個包,否則make  all時會報錯  yum install  -y  perl

make all

make install ;make  install-init;make install-config;make install-commandmode ;make install-webconf

3、服務端安裝nagios-plugins 插件,監控用

./configure  --prefix=/usr/local/nagios  --with-nagios-user=nagios --with-nagios-group=nagios

make&& make install

4、服務端安裝nrpe,與用戶端通信用

./configure  --enable-ssl --with-ssl-lib

make  install-plugin && make install-daemon && make  install-daemon-config

chown -R  nagios:nagios  /usr/local/nagios

5、nagios通路控制設定

htpasswd  -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

輸入兩次密碼即可,登入頁面的時候會用到這個密碼

6、重新開機nagios httpd服務

重新開機nagios前先用指令

/usr/local/nagios/bin/nagios  -v   /usr/local/nagios/etc/nagios.cfg,檢測下沒問題,再重新開機

/etc/init.d/nagios  restart ; /etc/init.d/httpd  restart

二、用戶端安裝:

1、安裝nagios-plugins

Useradd  -s /sbin/nologing   nagios

./configure  --prefix=/usr/local/nagios

make

make  install

2、安裝nrpe

chown -R  nagios:nagios /usr/local/nagios/

啟動用戶端nrpe指令

/usr/local/nagios/bin/nrpe  -c  /usr/local/nagios/etc/nrpe.cfg -d

3、用戶端nrpe設定

vi  /usr/local/nagios/etc/nrpe.cfg

在allowed_hosts=127.0.0.1 字段後面加上nagios伺服器端的IP位址

;Server_address=127.0.0.1  這個字段千萬不要改,保持注釋的狀态,nrpe需要在0.0.0.0:5666上開啟服務

三、nagios服務端監控用戶端的6個步驟

1、在伺服器端和用戶端都安裝nrpe,nagios-plugins

2、在用戶端定義監控的具體項目,修改allow允許的ip(服務端的ip)

3、啟動伺服器端,用戶端的nrpe,啟動指令 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d

用戶端啟動後可以在本機執行指令  /usr/local/nagios/libexec/check_nrpe  -H 127.0.0.1,來檢測,如果出現nrpe的版本,就代表本機的nrpe是OK的

/usr/local/nagios/libexec/check_nrpe  –H  對端IP,來檢測nrpe通信是不是好的

4、在伺服器端commands.cfg中定義check_nrpe指令:

define command{

command_name    check_nrpe

 command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c$ARG1$       

       }

5、在伺服器端對應IP的配置檔案中,加入需要監控的項目:

define service{

       use                               local-service              

  host_name                       192.168.1.12

       service_description               sda1_Monitor

       check_command                  check_nrpe!check_u

       notifications_enabled             1

6、在服務端的主配置檔案裡,引用某個IP對應的配置檔案,也就是在/usr/local/nagios/et/nagios.cfg裡大約35行的位置加入這樣一行:

cfg_file=/usr/local/nagios/etc/objects/192.168.223.132.cfg,或者

cfg_dir=/usr/local/nagios/etc/192.168.223.0/,上面的一行是引用一個配置檔案,下面的一行是引用一個目錄下的所有配置檔案