配置nagios用户
# useradd nagios
# passwd nagios
配置防火墙开放5666端口Vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT
Vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT
安装Nagios 插件
# tar zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure --prefix=/usr/local/nagios
# make && make install
修改目录权限
# tar zxvf nrpe-2.15.tar.gz
# cd nrpe-2.15
# ./configure
# make all
# tar zxvf nrpe-2.15.tar.gz
# cd nrpe-2.15
# ./configure
# make all
接下来安装NPRE插件,daemon和示例配置文件。
安装check_nrpe 这个插件
# make install-plugin
监控机需要安装check_nrpe 这个插件,被监控机并不需要,我们在这里安装它只是为了测试目的。
安装deamon
# make install-daemon
安装配置文件
# make install-daemon-config
安装在监控主机(Nagios-Server)上 脚本
# make install-xinetd
访问vi /etc/xinetd.d/nrpe
在only_from 后增加监控主机的IP地址(以空格区分)
如: only_from = 127.0.0.1 192.168.113.150安装xinetd
yum install -y xinetd
编辑/etc/services文件,增加NRPE服务
vi /etc/services
增加如下
# Local services
nrpe 5666/tcp # nrpe
重启xinetd服务
service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
查看NRPE是否已经启动
netstat -at|grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
netstat -an|grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
可以看到5666端口已经在监听了
5.测试NRPE是否则正常工作
之前我们在安装了check_nrpe这个插件用于测试,现在就是用的时候.执行
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
会返回当前NRPE的版本
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.15
也就是在本地用check_nrpe连接nrpe daemon是正常的
注:为了后面工作的顺利进行,注意本地防火墙要打开5666能让外部的监控机访问
监控主机(Server端)上配置
安装check_nrpe 插件
# tar zxvf nrpe-2.15.tar.gz
# cd nrpe-2.15
# ./configure
# make all
# make install-plugin
只运行这一步就行了,因为只需要check_nrpe插件
测试一下监控机使用check_nrpe 与被监控机运行的nrpe daemon之间的通信。
/usr/local/nagios/libexec/check_nrpe -H 192.168.113.137
NRPE v2.15
看到已经正确返回了NRPE的版本信息,说明一切正常。
在commands.cfg中增加对check_nrpe的定义
# vi/usr/local/nagios/etc/objects/commands.cfg
在最后面增加如下内容(根据自身需要增加):
# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe-H $HOSTADDRESS$ -c $ARG1$
}
定义对Nagios-Linux 主机的监控
下面就可以在services.cfg 中定义对Nagios-Linux 主机的监控了。
define service{
use local-service
host_name nginx1
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service
host_name nginx1
service_description Current Load
check_command check_nrpe!check_load
}
define service{
use local-service
host_name nginx1
service_description Total Processes
check_command check_nrpe!check_total_procs
}
define service{
use local-service
host_name nginx1
service_description Current Users
check_command check_nrpe!check_users
}
所有的配置文件已经修改好了,现在重启Nagios。
# service nagios restart