Nagios监控Linux和Windows主机(2)

五,利用插件扩展Nagios的监控功能

下面我们通过在nagios服务端和客户端安装NRPE插件来搭建一个更加完善的Nagios监控系统。

1)配置nagios客户端(即远端被监控主机192.168.1.2)

A)安装Nagios插件

登陆192.168.1.2客户端

[root@localhost ~]# cd /aaa/

[root@localhost aaa]# useradd -s /sbin/nologin nagios

[root@localhost aaa]# tar zxf nagios-plugins-1.4.14.tar.gz

[root@localhost aaa]# cd nagios-plugins-1.4.14

[root@localhost nagios-plugins-1.4.14]# ./configure ; make ;make install

[root@localhost nagios-plugins-1.4.14]# chown nagios:nagios /usr/local/nagios/

[root@localhost nagios-plugins-1.4.14]# chown -R nagios.nagios /usr/local/nagios/libexec/

B)安装NRPE插件

[root@localhost aaa]# cd /aaa/

[root@localhost aaa]# tar zxf nrpe-2.12.tar.gz

[root@localhost aaa]# cd nrpe-2.12

[root@localhost nrpe-2.12]# ./configure ; make all ; make install-plugin ; make install-daemon ; make install-daemon-config

C)修改NRPE配置文件

[root@localhost nrpe-2.12]# vi /usr/local/nagios/etc/nrpe.cfg

79 allowed_hosts=127.0.0.1,192.168.1.1

192.168.6.199:指定nagios服务器地址

D)启动NRPE

[root@localhost nrpe-2.12]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

[root@localhost nrpe-2.12]# netstat -antl |grep 5666

tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN

E)测试NRPE

[root@localhost nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1

NRPE v2.12

如果出现NRPE v2.12表明NRPE已经正常工作

定义让nagios服务器监控我本机上的内容(当前用户数,CPU,内存,硬盘等信息)

[root@localhost libexec]# vi /usr/local/nagios/etc/nrpe.cfg

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

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

201 command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10 % -p /dev/sda1

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

203 command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 1 50 -c 200

重启NRPE

[root@localhost ~]# ps -elf |grep nrpe

5 S nagios 22379 1 0 75 0 - 1243 - 17:59 ? 00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

0 R root 22586 4247 0 78 0 - 1039 - 18:09 pts/0 00:00:00 grep nrpe

[root@localhost ~]# kill -9 22379

[root@localhost ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d

2,配置nagios服务器端

登陆nagios服务器端:192.168.1.1

1)安装NRPE插件

[root@localhost etc]# cd /aaa/

[root@localhost aaa]# tar zxf nrpe-2.12.tar.gz

[root@localhost aaa]# cd nrpe-2.12

[root@localhost nrpe-2.12]# ./configure ; make ; make install-plugin

2)测试插件能否取得与客户端192.168.1.2的联系

[root@localhost nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.2

NRPE v2.12

出现NRPE v2.12就证明成功联系上客户端

3)定义一个check_nrpe监控命令

[root@localhost nrpe-2.12]# vi /usr/local/nagios/etc/commands.cfg

define command{

command_name check_nrpe

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

}

5)添加远程主机监控项

[root@localhost nrpe-2.12]# vi /usr/local/nagios/etc/services.cfg

define service{

use local-service

host_name mysql

service_description users

check_command check_nrpe!check_users

}

define service{

use local-service

host_name mysql

service_description load

check_command check_nrpe!check_load

}

define service{

use local-service

host_name mysql

service_description disk

check_command check_nrpe!check_sda1

}

define servicegroup{

servicegroup_name servergroup

alias server-group

members web,PING,web,SSH,web,SSHD,web,http,mysql,users,mysql,load,mysql,disk

}

6)测试并重新启动nagios服务

[root@localhost ~]# service nagios restart

 

Nagios监控Linux和Windows主机

 

Nagios监控Linux和Windows主机

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/e826a2e112fbaaf02b5b96ba1d4844f8.html