一、NRPE的安装

nagios在监控Linux主机时会要用到NRPE这个软件,工作原理如下图所示:


nagios安装与基本配置_nagios

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_namenagios-server

aliasnagios server

address192.168.191.128

check_commandcheck-host-alive

max_check_attempts5

check_period24x7

contact_groupsadmins

notification_interval10

notification_period24x7

notification_optionsd,u,r

}

define host{

host_namewindows2003

aliaswindows2003

address192.168.191.129

check_commandcheck-host-alive

max_check_attempts5

check_period24x7

contact_groupsadmins

notification_interval10

notification_period24x7

notification_optionsd,u,r

}

define host{

host_namelinux

aliaslinux

address192.168.191.130

check_commandcheck-host-alive

max_check_attempts5

check_period24x7

contact_groupsadmins

notification_interval10

notification_period24x7

notification_optionsd,u,r

}

define hostgroup{

hostgroup_namesa-servers

aliassa servers

membersnagios-server,windows2003,linux

}


三、配置服务监控

和主机监控配置一样,服务配置也要存在一个services.cfg文件中,同样在/usr/local/nagios/etc/目录下建立services.cfg文件之后加入如下内容:

define service{

host_namenagios-server

service_descriptioncheck-host-alive

check_commandcheck-host-alive

max_check_attempts5

normal_check_interval5

retry_check_interval2

check_period24x7

notification_interval10

notification_period24x7

notification_optionsw,u,c,r

contact_groupsadmins

}

define service{

host_namenagios-server

service_descriptioncheck_tcp 80

check_period24x7

max_check_attempts4

normal_check_interval3

retry_check_interval2

contact_groupsadmins

notification_interval10

notification_period24x7

notification_optionsw,u,c,r

check_commandcheck_tcp!80

}

define service{

host_namenagios-server

service_descriptioncpu load

check_commandcheck_nrpe!check_load

check_period24x7

max_check_attempts4

normal_check_interval3

retry_check_interval2

contact_groupsadmins

notification_interval10

notification_period24x7

notification_optionsw,u,c,r

}

define service{

host_namenagios-server

service_descriptiontotal-procs

check_commandcheck_nrpe!check_total_procs

check_period24x7

max_check_attempts4

normal_check_interval3

retry_check_interval2

contact_groupsadmins

notification_interval10

notification_period24x7

notification_optionsw,u,c,r

}

define service{

host_namenagios-server

service_descriptioncheck_df

check_commandcheck_nrpe!check_df

check_period24x7

max_check_attempts4

normal_check_interval3

retry_check_interval2

contact_groupsadmins

notification_interval10

notification_period24x7

notification_optionsw,u,c,r

}

define service{

host_namenagios-server

service_descriptioncheck_ips

check_commandcheck_nrpe!check_ips

check_period24x7

max_check_attempts4

normal_check_interval3

retry_check_interval2

contact_groupsadmins

notification_interval10

notification_period24x7

notification_optionsw,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_namenagiosadmin

aliasNagios Admin

service_notification_period24x7

host_notification_period24x7

service_notification_optionsw,u,c,r

host_notification_optionsd,u,r

service_notification_commandsnotify-by-email,service-notify-by-fx

host_notification_commandshost-notify-by-email,host-notify-by-fx

email abc@mail.com

pager13800138000

}

define contactgroup{

contactgroup_nameadmins

aliasNagios Administrators

membersnagiosadmin

}


六、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.安装相关软件

useraddnagios-s /sbin/nologin

tar xvfnagios-plugins-1.4.14.tar.gz

cd nagios-plugins-1.4.14

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

make

make install

chown –Rnagios:nagios/usr/local/nagios

chown –Rnagios: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文件。

在服务里找到

nagios安装与基本配置_nagios_02

把属性中登录选项的允许服务与桌面交互前的对勾打上,如下图所示:


nagios安装与基本配置_nagios_03

之后要在监控主机的commands.cfg中加入如下内容:

#'check_nt' command definition

define command{

command_namecheck_nt

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

}

九、启动服务查看结果

这时就可以在监控主机上启动nagioshttpd服务查看结果了,如下图所示:

nagios安装与基本配置_nagios_04


nagios安装与基本配置_nagios_05


本文出自 “李勇” 博客,请务必保留此出处http://liyong0802.blog.51cto.com/2574432/625651