Nagios監控

Nagios監控

                               <Alvin-zeng-孤獨0-1 >

目錄

一、軟件版本1

1.1、主程序nagios-3.2.3.tar.gz1

1.2、插件 nagios-plugins-1.4.15.tar.gz1

1.3、插件 nrpe-2.12.tar.gz1

1.4、飛信報警庫及腳本 lib/ fetion1

二、Nagios監控服務器端/8.230,程序安裝1

2.1Yum安裝以下軟件1

2.2、創建nagios 用戶和組1

2.3、編譯安裝Nagios 主程序1

2.4、安裝nagios-plugins插件2

2.5、將apache的運行用戶加到nagios組裏面2

2.6、增加web訪問賬號2

2.7、查看cgi.cfg文件2

2.8、編譯安裝nrpe插件2

2.9nagios隨系統啓動3

三、Nagios 被監控客戶端/8.2313

3.1、增加用戶nagios3

3.2、編譯安裝nagios-plugins插件3

3.3、編譯安裝nrpe插件3

3.4、修改services配置文件,在最後末尾增加4

3.5、修改nrpe配置文件4

3.6、啓動基於xinetd nrpe服務4

3.7、測試回到8.230主監控服務器上4

四、Nagios監控服務器端/8.230 主程序配置4

4.1、配置文件分組簡介4

4.2在定義配置文件路經,這裏可以自定義配置文件.5

4.3、定義配置lxr 聯繫人新增配置文件5

4.4、定義配置lxrgroup聯繫組-新增配置文件5

4.5、定義配置host主機文件,新增配置文件6

4.6、定義配置hostgroup主機組文件,新增配置文件6

4.7、定義配置serivcegroup服務組文件,新增配置文件6

4.8、定義配置serivce服務文件,以上面所有的主機和組。在此配置文件調用。6

4.9、定義飛信短信報警機器人7

5.0、定義飛信短信報警代碼,在末行增加7

五、常用測試命令7

5.1、定義被監控端的命令比如swap7

5.2、監控服務端nrpe測試,swap命令8


一、 軟件版本

1.1、主程序nagios-3.2.3.tar.gz

下載地址:http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.3/nagios-3.2.3.tar.gz/download

1.2、插件 nagios-plugins-1.4.15.tar.gz

http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz/download

1.3、插件 nrpe-2.12.tar.gz

下載地址:http://down.51cto.com/data/165101#

1.4、飛信報警庫及腳本 lib/ fetion

下載地址:http://bbs.it-adv.net/viewthread.php?tid=1081&extra=page%3D1


二、 Nagios監控服務器端/8.230,程序安裝

2.1Yum安裝以下軟件

[root@test-1 /]# yum  -y install httpd gcc glibc glibc-common gd gd-devel php openssl-develxinetd


2.2、創建nagios 用戶和組

[root@test-1 nagios]# useradd nagios

[root@test-1 nagios]# passwd nagios

[root@test-1 nagios]# mkdir/usr/local/nagios

[root@test-1 nagios]# chown nagios.nagios /usr/local/nagios

2.3、編譯安裝Nagios 主程序

[root@test-1 nagios]# tar -xvf nagios-3.2.3.tar.gz

[root@test-1 nagios]# cd nagios-3.2.3

[root@test-1 nagios]#./configure --prefix=/usr/local/nagios --with-command-group=nagios

[root@test-1 nagios]#make all

[root@test-1 nagios]#make install

[root@test-1 nagios]# make install-init


[root@test-1 nagios]# make install-config

[root@test-1 nagios]# make install-commandmode

[root@test-1 nagios]#make install-webconf

(查看是否有/usr/local/nagios/etc、bin、sbin、share、var、libexec這六個目錄,如果有,表示安裝成功)

2.4、安裝nagios-plugins插件

[root@test-1 nagios]#tar -xvf nagios-plugins-1.4.15.tar.gz

[root@test-1 nagios]#cd nagios-plugins-1.4.15

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

[root@test-1 nagios]#make && make install

ls /usr/local/nagios/libexec(會顯示很多應用腳本)

2.5apache的運行用戶加到nagios組裏面

[root@test-1 nagios]#usermod -G nagios apache

2.6、增加web訪問賬號

[root@test-1 nagios]#cat /etc/httpd/conf.d/nagios.conf | grep  htpasswd

AuthUserFile /usr/local/nagios/etc/htpasswd.users

  AuthUserFile /usr/local/nagios/etc/htpasswd.users

[root@test-1]#htpasswd -c  /usr/local/nagios/etc/htpasswd.users nagiosadmin

2.7、查看cgi.cfg文件

[root@test-1 nagios]# grep nagiosadmin /usr/local/nagios/etc/cgi.cfg

authorized_for_system_information=nagiosadmin

authorized_for_configuration_information=nagiosadmin

authorized_for_system_commands=nagiosadmin

authorized_for_all_services=nagiosadmin

authorized_for_all_hosts=nagiosadmin

authorized_for_all_service_commands=nagiosadmin

authorized_for_all_host_commands=nagiosadmin

2.8、編譯安裝nrpe插件

[root@test-1 nagios]#tar -xvf nrpe-2.12.tar.gz

[root@test-1 nagios]#cd nrpe-2.12

[root@test-1 nagios]# ./configure --enable-ssl --with-ssl-lib

[root@test-1 nagios]#make all

[root@test-1 nagios]# make install-plugin

[root@test-1 nagios]# make install-daemon

[root@test-1 nagios]# make install-daemon-config

[root@test-1 nagios]#make install-xinetd

2.9nagios隨系統啓動

[root@test-1 nagios]#chkconfig --add nagios

[root@test-1 nagios]#chkconfig nagios on

[root@test-1 nagios]#/etc/init.d/httpd start

驗證配置是否配置正確:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

如果不報錯,可以啓動nagios服務:service nagios start

IE瀏覽器地址欄輸入:192.168.8.230/nagios,敲入用戶名及密碼,就可以看到如下界面了


三、 Nagios 被監控客戶端/8.231

3.1、增加用戶nagios

[root@test-2 /]# yum  -y install httpd gcc glibc glibc-common gd gd-devel php openssl-develxinetd


[root@test-2 nagios]# useradd nagios

[root@test-2 nagios]# passwd nagios


3.2、編譯安裝nagios-plugins插件

[root@test-1 nagios]#tar -xvf nagios-plugins-1.4.15.tar.gz

[root@test-1 nagios]#cd nagios-plugins-1.4.15

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

[root@test-1 nagios]#make && make install

ls /usr/local/nagios/libexec(會顯示很多應用腳本)


3.3、編譯安裝nrpe插件

[root@test-2 nagios]#tar -xvf nrpe-2.12.tar.gz

[root@test-2 nagios]#cd nrpe-2.12

[root@test-2 nagios]# ./configure --enable-ssl --with-ssl-lib

[root@test-2 nagios]#make all

[root@test-2 nagios]# make install-plugin

[root@test-2 nagios]# make install-daemon

[root@test-2 nagios]# make install-daemon-config

[root@test-2 nagios]#make install-xinetd

3.4、修改services配置文件,在最後末尾增加

[root@test-2 nagios]#cat /etc/services | grep nrpe

nrpe            5666/tcp                        # nrpe


3.5、修改nrpe配置文件

[root@test-2 nagios]#vim /etc/xinetd.d/nrpe

only_from       = 192.168.8.230à監控服務器地址

3.6、啓動基於xinetd nrpe服務

[root@test-2 nagios]#/etc/init.d/xinetd start

[root@test-2 nagios]#netstat -nap | grep 5666

tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      1284/xinetd

3.7、測試回到8.230主監控服務器上

[root@test-1 nagios]# /usr/local/nagios/libexec/check_nrpe -H 192.168.8.231

返回 “NRPE v2.12” 表示部署成功

四、 Nagios監控服務器端/8.230 主程序配置

4.1、配置文件分組簡介

cgi.cfg---à控制相關的cgi 腳本

resoure.cfg -à系統傳入參數配置文件

commands.cfg-à定義命令配置文件

timeperiods.cfgà監視時段配置文件


配置分組自定義

contacts .cfg-à 定義了故障報警的聯繫人

contactsgroup.cfg---à定義了故障報警聯繫組


hosts--à主機配置文件

hostgroups-à主機組配置文件


services-à服務配置文件

servicesgroupà服務組配置文件




4.2、 在定義配置文件路經,這裏可以自定義配置文件.

[root@test-1 nagios]#vim /usr/local/nagios/etc/nagios.cfg


cfg_file=/usr/local/nagios/etc/objects/localhost.cfg 註釋掉。

cfg_file=/usr/local/nagios/etc/objects/contacts.cfg  註釋掉

末尾增加以下內容

cfg_file=/usr/local/nagios/my/lxr

cfg_file=/usr/local/nagios/my/lxrgroup

cfg_file=/usr/local/nagios/my/host

cfg_file=/usr/local/nagios/my/hostgroup

cfg_file=/usr/local/nagios/my/serivcegroup

cfg_file=/usr/local/nagios/my/service


4.3、定義配置lxr 聯繫人新增配置文件

[root@test-1 nagios]# mkdir /usr/local/nagios/my

[root@test-1 nagios]# cd /usr/local/nagios/my

[root@test-1my]# vim lxr

define contact{

               contact_name       Alvin-zeng

               use                generic-contact

               alias              Alvin-zeng-admin

               service_notification_commands    notify-service-by-email,service-notify-by-fetion

               host_notification_commands        notify-host-by-email,host-notify-by-fetion

               email                           [email protected]

               pager                           136xxxxxxx  }





4.4、定義配置lxrgroup聯繫組-新增配置文件

[root@test-1my]# vim lxrgroup

define contactgroup{

              contactgroup_name             lxrgp    #:組名隨便定義

              alias                          zeng    #:別名隨便定義

           members                        Alvin-zeng     #這裏將上面的聯繫人成員。加到這個組裏面

 }





4.5、定義配置host主機文件,新增配置文件

[root@test-1my]# vim host

define host{

         host_name                        test-2   #被監空端真實的主機名,主要不要留空格。

         alias                              test

         max_check_attempts                 5

         address                            192.168.8.231 }  #:被監客戶端IP地址

4.6、定義配置hostgroup主機組文件,新增配置文件

[root@test-1my]# vim hostgroup

define hostgroup{

         hostgroup_name        group1   #:組名

         alias                   group

         members              test-2    #:test-2 加到這個組裏面來

}

4.7、定義配置serivcegroup服務組文件,新增配置文件

[root@test-1my]# vim serivcegroup

define servicegroup{

       servicegroup_name    tt    #:組名

       alias                TT    #:別名

}

4.8、定義配置serivce服務文件,以上面所有的主機和組。在此配置文件調用。

[root@test-1my]# vim service

define service{

             hostgroup_name           group1    #這裏調用主機組或者單個主機

             servicegroups               tt        #這裏調用服務組或者單個服務

             service_description           check_swap #檢查swap

             check_period                24x7      #檢查24小時

             max_check_attempts          1

             normal_check_interval         1

             retry_check_interval           1

             notification_options           w,u,c,r

             notification_interval           1

             notification_period            24x7

             check_command              check_nrpe!check_swap

             contact_groups                lxrgp #這裏調用聯繫人組或者單個聯繫人

}

4.9、定義飛信短信報警機器人

先解壓,解壓完後。找到lib 目錄庫和fetion腳本

[root@test-1my]#mkdir /usr/local/fetion/

[root@test-1my]#mkdir /usr/local/fetion/

[root@test-1my]# cp lib/  /usr/local/fetion/

[root@test-1my]# cp fetion  /usr/local/fetion/


5.0、定義飛信短信報警代碼,在末行增加

[root@test-1my]#vim /usr/local/nagios/etc/objects/commands.cfg


define command {

            command_name            host-notify-by-fetion ;

            command_line  LD_LIBRARY_PATH=/usr/local/fetion/lib /usr/local/fetion/fetion --mobile=13692216****  --pwd=feishu8 --to=13692216****  --msg-utf8="Host $HOSTSTATE$ alert for $HOSTNAME$! on '$LONGDATETIME$'" $CONTACTPAGER$

            }


# 'notify-service-by-fetion' command definition

define command {

            command_name         service-notify-by-fetion

            command_line         LD_LIBRARY_PATH=/usr/local/fetion/lib /usr/local/fetion/fetion --mobile=13692216****  --pwd=feishu8 --to=13692216****  --msg-utf8="$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$" $CONTACTPAGER$

               }

# ' check_nrpe ' command definition

define command{

       command_name check_nrpe

       command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

五、 常用測試命令

5.1、定義被 監控端的命令比如swap

[root@test-2 nagios]#vim /usr/local/nagios/etc/nrpe.cfg
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 50% -c 20%

5.2、監控服務端nrpe測試,swap命令

[root@test-1 nagios]#cd /usr/local/nagios/libexec/

[root@test-1 libexec]#./check_nrpe -H 192.168.8.231 -c check_swap

SWAP OK - 100% free (1983 MB out of 1983 MB) |swap=1983MB;991;396;0;1983



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章