nagios nrpe监控远程主机

更新时间:2023-07-26 22:33:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Nagios NRPE监控远程主机具体步骤如下。

1. 监控机的软件的安装

监控机安装NRPE wget /sourceforge/nagios/nrpe-2.12.tar.gz tar zxvf nrpe-2.12.tar.gz cd nrpe-2.12 ./configure --prefix=/usr/local/nagios make all make install-plugin

#监控机只需安装到这步

2. 被监控机的软件的安装

被监控机添加用户

groupadd nagios

useradd -g nagios -d /usr/local/nagios -s /sbin/nologin nagios

被监控机安装plugin

wget /sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz

tar zxf nagios-plugins-1.4.13.tar.gz

cd nagios-plugins-1.4.13

./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios --with-ping-command="/bin/ping" --with-mysql=/opt/mysql

make

make install

#查看播件文件是否已安装在这个目录

ls /usr/local/nagios/libexec

被监控机安装NRPE

wget /sourceforge/nagios/nrpe-2.12.tar.gz tar zxvf nrpe-2.12.tar.gz

cd nrpe-2.12

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

make all

make install-plugin

make install-daemon

make install-daemon-config

cp init-script /etc/init.d/nagios-nrpe

chown -R nagios:nagios /usr/local/nagios

3. 被监控机的配置

配置 NRPE:

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

allowed_hosts=127.0.0.1,192.168.1.91

#Nagios监控机的地址或域名

修改/etc/hosts.allow增加监控机ip

echo 'nrpe:192.168.1.91' >> /etc/hosts.allow

启动 NRPE 守护进程:

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

可以将此命令加入 /etc/rc.local ,以便开机自动启动。

echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local

检查 NRPE 是否正常:

/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1

查看相应的端口:netstat -an |grep 5666

防火墙开启5666 允许局域网IP或固定IP连接

在监控主机上

/usr/local/nagios/libexec/check_nrpe -H $目标主机地址

都应该可以输出 NRPE 的版本: NRPE v2.12

检查可监控的服务

在被监控端的 nrpe.cfg 文件中,可以看到这样的配置:

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

这是用来检查 CPU 负载的。

如果需要自定参数则使用下面命令

command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$ 并开启dont_blame_nrpe =1

开启参数将会带来一定的安全风险

被监控机重启nrpe

ps aux|grep nrpe

kill $pid

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

4. 监控机设置

在监控机commands.cfg 添加nrpe的定义 # 'check_nrpe ' command definition define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } 增加hostA.cfg 在/usr/local/nagios/etc/objects/ 目录下新建文件:hostA.cfg 把A.cfg添加到nagios主机:

echo "cfg_file=/usr/local/nagios/etc/objects/hostA.cfg" >> /usr/local/nagios/etc/nagios.cfg

如果要再添加B机器方法炮制就可以了

hostA.cfg

define host{

use generic-server

host_name A

alias A

address A 的IP

}

define service{

use generic-service

host_name A

service_description load

check_command check_nrpe!check_load

#使用自定参数

#check_command check_nrpe!check_load!6.0,5.0,4.0!15.0,8.0,6.0

}

重启监控机nagios

service nagios reload

访问http://localhost/nagios就可以看到新增的机器了

如何修改nrpe端口

被监控机nrpe.cfg修改server_port为15666

server_port=15666

重启nrpe

监控机commands.cfg增加-p 15666

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 15666 -c $ARG1$ }

重启nagios就可以了

Connection refused or timed out

检查nrpe 端口

检查nrpe.cfg中allowed_hosts是否包含监控机ip地址

检查/etc/hosts.allow文件中监控机ip地址nrpe:192.168.1.91

检查iptables

开放5666端口

iptables -L

iptables -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 5666 -j ACCEPT

#注意顺序

iptables -L

service iptables save

service iptables restart

通过文章,我们不难发现Nagios NRPE监控远程主机操作非常简单!

Question 1: When I execute check_nrpe command with some arguments, I get the message

“CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.”. How do I fix this issue?

Answer 1: The issue is very straight forward. check_nrpe doesn’t take any arguments by default. You should enable the command line arguments for check_nrpe as shown below.

1. Configure NRPE with –enable-command-args

2. Modify nrpe.cfg and set dont_blame_nrpe

本文来源:https://www.bwwdw.com/article/jo1m.html

Top