nagios安裝與基本配置(二)

上一節中完成了nagios的安裝,這一節主要對nagios進行簡單的配置。

 

一、NRPE的安裝

nagios在監控Linux主機時會要用到NRPE這個軟件,工作原理如下圖所示:

tar xzf nrpe-2.12.tar.gz

cd nrpe-2.12

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

 

二、配置主機監控

一般主機監控配置都會存在一個hosts.cfg文件中,這裏先在/usr/local/nagios/etc/目錄下建立hosts.cgf文件之後寫入如下內容:

define host{

        host_name                       nagios-server

        alias                           nagios server

        address                         192.168.191.128

        check_command                   check-host-alive

        max_check_attempts              5

        check_period                    24x7

        contact_groups                  admins

        notification_interval           10

        notification_period             24x7

        notification_options            d,u,r

        }

define host{

        host_name                       windows2003

        alias                           windows2003

        address                         192.168.191.129

        check_command                   check-host-alive

        max_check_attempts              5

        check_period                    24x7

        contact_groups                  admins

        notification_interval           10

        notification_period             24x7

        notification_options            d,u,r

        }

define host{

        host_name                       linux

        alias                           linux

        address                         192.168.191.130

        check_command                   check-host-alive

        max_check_attempts              5

        check_period                    24x7

        contact_groups                  admins

        notification_interval           10

        notification_period             24x7

        notification_options            d,u,r

        }

define hostgroup{

        hostgroup_name  sa-servers

        alias           sa servers

        members         nagios-server,windows2003,linux

        }

 

三、配置服務監控

和主機監控配置一樣,服務配置也要存在一個services.cfg文件中,同樣在/usr/local/nagios/etc/目錄下建立services.cfg文件之後加入如下內容:

define service{

        host_name               nagios-server

        service_description     check-host-alive

        check_command           check-host-alive

        max_check_attempts      5

        normal_check_interval   5

        retry_check_interval    2

        check_period            24x7

        notification_interval   10

        notification_period     24x7

        notification_options    w,u,c,r

        contact_groups          admins

        }

define service{

        host_name               nagios-server

        service_description     check_tcp 80

        check_period            24x7

        max_check_attempts      4

        normal_check_interval   3

        retry_check_interval    2

        contact_groups          admins

        notification_interval   10

        notification_period     24x7

        notification_options    w,u,c,r

        check_command           check_tcp!80

        }

define service{

        host_name               nagios-server

        service_description     cpu load

        check_command           check_nrpe!check_load

        check_period            24x7

        max_check_attempts      4

        normal_check_interval   3

        retry_check_interval    2

        contact_groups          admins

        notification_interval   10

        notification_period     24x7

        notification_options    w,u,c,r

        }

define service{

        host_name               nagios-server

        service_description     total-procs

        check_command           check_nrpe!check_total_procs

        check_period            24x7

        max_check_attempts      4

        normal_check_interval   3

        retry_check_interval    2

        contact_groups          admins

        notification_interval   10

        notification_period     24x7

        notification_options    w,u,c,r

        }

define service{

        host_name               nagios-server

        service_description     check_df

        check_command           check_nrpe!check_df

        check_period            24x7

        max_check_attempts      4

        normal_check_interval   3

        retry_check_interval    2

        contact_groups          admins

        notification_interval   10

        notification_period     24x7

        notification_options    w,u,c,r

        }

define service{

        host_name               nagios-server

        service_description     check_ips

        check_command           check_nrpe!check_ips

        check_period            24x7

        max_check_attempts      4

        normal_check_interval   3

        retry_check_interval    2

        contact_groups          admins

        notification_interval   10

        notification_period     24x7

        notification_options    w,u,c,r

        }

 

      這裏只給出nagios-server主機中服務的監控配置,其他兩個被監控主機配置基本相同這裏就不再給出。

 

四、配置nagios主配置文件nagios.cfg

    這樣只給出需要改的項目:

cfg_file=/usr/local/nagios/etc/objects/commands.cfg

cfg_file=/usr/local/nagios/etc/objects/contacts.cfg

cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg

cfg_file=/usr/local/nagios//etc/objects/templates.cfg

cfg_file=/usr/local/nagios/etc/hosts.cfg

cfg_file=/usr/local/nagios/etc/services.cfg

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

 

五、配置聯繫人文件contacts.cfg

define contact{

        contact_name                    nagiosadmin

        alias                           Nagios Admin

        service_notification_period     24x7

        host_notification_period        24x7

        service_notification_options    w,u,c,r

        host_notification_options       d,u,r

        service_notification_commands   notify-by-email,service-notify-by-fx

        host_notification_commands      host-notify-by-email,host-notify-by-fx

       email                           [email protected]

       pager                           13800138000

        }

define contactgroup{

        contactgroup_name       admins

        alias                   Nagios Administrators

        members                 nagiosadmin

        }

 

六、NRPE配置

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

server_address=192.168.191.128

allowed_hosts=127.0.0.1,192.168.191.128

command[check_users]=/usr/local/nrpe/libexec/check_users -w 5 -c 10

command[check_load]=/usr/local/nrpe/libexec/check_load -w 15,10,5 -c 30,25,20

#command[check_hda1]=/usr/local/nrpe/libexec/check_disk -w 20 -c 10 -p /dev/hda1   //註釋掉

command[check_df]=/usr/local/nrpe/libexec/check_disk -w 20 -c 10             //添加這一行,監控整個磁盤利用率

command[check_zombie_procs]=/usr/local/nrpe/libexec/check_procs -w 5 -c 10 -s z

command[check_total_procs]=/usr/local/nrpe/libexec/check_procs -w 150 -c 200

command[check_ips]=/usr/local/nrpe/libexec/ip_conn.sh 8000 10000     //監控ip連接數

啓動nrpe服務

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

 

七、被監控Linux主機配置

1.安裝相關軟件

useradd  nagios  -s /sbin/nologin

 

tar xvf  nagios-plugins-1.4.14.tar.gz

cd nagios-plugins-1.4.14

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

make

make install

 

chown –R  nagios:nagios  /usr/local/nagios

chown –R  nagios:nagios  /usr/local/nagios/libexec

tar xzf nrpe-2.12.tar.gz

cd nrpe-2.12

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

 

2. 修改nrpe.cfg配置文件

allowed_hosts=127.0.0.1,192.168.191.128   //允許監控服務器訪問,中間用逗號隔開;

# 修改NRPE的監控命令,添加相應的命令;

# The following examples use hardcoded command arguments...

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10

command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

#command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

command[check_df]=/usr/local/nagios/libexec/check_disk -w 20 -c 10

command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z

command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%

command[check_tcp]=/usr/local/nagios/libexec/check_tcp -p 80

 

3. 啓動nrpe服務

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

 

八、windows2003配置

http://sourceforge.net/projects/nscplus/裏下載nsclient++-0.3.8-win32.msi進行安裝。

進安裝目錄修改NSC.ini文件,在 [modules]部分的所在模塊前面的註釋“;”去掉,只保留CheckWMI.dllRemoteConfiguration.dll這兩個不用去掉註釋;在 [Settings] 部分找到”allowed_hosts”選項,將前面的 “;”註釋去掉,並在後面加上監控服務器的IP;在 [NSClient] 部分找到“port=12489”這一行,並把前面的註釋去掉,這是NSClinet的默認監聽端口。

運行安裝目錄下的nsclient++.exetnstray.exe文件。

在服務裏找到

把屬性中登錄選項的允許服務與桌面交互前的對勾打上,如下圖所示:

 

之後要在監控主機的commands.cfg中加入如下內容:

#'check_nt' command definition

define command{

        command_name    check_nt

        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$

        }

 

九、啓動服務查看結果

這時就可以在監控主機上啓動nagioshttpd服務查看結果了,如下圖所示:

 

 

 

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