被监控端安装nrpe监听566端口(依赖nagios-plugins),监控端通过check_nrpe与被监控端通信。在服务端和被监控端都要安装nrpe,区别是在服务端不启动nrpe服务,被监控端要启动nrpe服务。
在被监控主机上配置:
安装开发包组:
yum groupinstall –y “Development Tools” “Development Libraries”
添加nagios用户:
useradd –s /sbin/nologin nagios
安装nagios-plugins:
tar zxf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install
安装nrpe:
tar zxf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --with-nrpe-user=nagios \
--with-nrpe-group=nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--enable-command-args \ ##启动向被监控端传递参数
--enable-ssl ##使用ssl加密
make all
make install-plugins
make install-daemon
make install-daemon-config
配置nrpe:
vim /usr/local/nagios/etc/nrpe.conf
allowed_hosts= ##允许谁发起监听请求,修改这一项
启动nrpe:
/usr/local/nagios/bin/nrpe –c /usr/local/nagios/etc/nrpe.cfg -d
为方便nrpe启动,将其写成服务:
#!/bin/bash
#chkconfig:2345 88 12
NRPE=/usr/local/nagios/bin/nrpe
NRPECONF=/usr/local/nagios/etc/nrpe.cfg
case “$1” in
start)
echo –n “Starting NRPE deamon…”
$NRPE –c $NRPECONF –d
echo “done.”
;;
stop)
echo –n “Stopping NRPE deamon…”
pkill –u nagios nrpe
echo “done.”
;;
restart)
$0 stop
sleep 2
$0 start
;;
*)
echo “Usage $0 start|stop|restart”
;;
exec
exit 0
chkconfig –add [上边文件的名字]
在服务端安装nrpe:
tar zxf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --with-nrpe-user=nagios \
--with-nrpe-group=nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--enable-command-args \
--enable-ssl
make all
make install-plugin
测试是否可以通信:
cd /usr/local/nagios/libexec
./check_nrpe –H 远程主机ip ##若返回nrpe版本则通信正常。
监控配置:
cd /etc/nagios/objects
vim commands.cfg ##加入以下内容
define command
{
command_name check_nrpe
command_line $USER1$/check_nrpe –H $HOSTADDRESS$ –c $ARG1$
}
cp windows.cfg linhost.cfg
vim linhost.cfg ##修改为以下内容
define host{
use linux-server
host_name linhost
alias My Linux Host
address 被监控ip
}
主机组 hostgroup部分注释掉
define service{
use seneric-service
host_name linhost
service_description CHECK USERS
check_command check_nrpe!check_user
}
##以此类推,在被监控端设置了监控哪些项,就在这里添加哪些,形如上边
define service{
use seneric-service
host_name linhost
service_description Load
check_command check_nrpe!check_load
}
define service{
use seneric-service
host_name linhost
service_description SDA1
check_command check_nrpe!check_sda1
}
vim nagios.cfg
cfg_file=/etc/nagios/objects/linhost.cfg ##添加这一行
检查语法正确性:
/usr/local/nagios/bin/nagios –v /etc/nagios/nagios.cfg
重启nagios:
service nagios restart
效果:
在web页面应该会出现linhost这个新的主机。