1、监控Linux
在被监控主机上安装nagios插件和nrpe
[root@minion-122 yum.repos.d]# yum install nagios-plugins nagios-plugins-nrpe nrpe -y
配置nrpe的信息:(添加监控中心的IP)
[root@minion-122 yum.repos.d]# vim /etc/nagios/nrpe.cfg
allowed_hosts=192.168.0.124,127.0.0.1,::1
启动nrpe.nrpe端口5666.
监控中心安装Nrpe:
[root@localhost yum.repos.d]# yum install nrpe -y
检查与被监控机器通信:
[root@localhost yum.repos.d]# /usr/lib64/nagios/plugins/check_nrpe -H 192.168.0.122
NRPE v3.2.1
创建被监控的主机与服务对象的定义:
1、编辑command.cfg需要先添加check_nrpe命令
[root@localhost objects]# vim commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_urpe -H $HOSTADDRESS$ -c $ARG1$
}
上面:
$USER1$ 被监控的主机名
$HOSTADDRESS$ 被监控主机IP(一般不用输)
-c $ARG1$ 参数1
2、添加一个与监控对象有关的配置文件linux_192.168.0.122.cfg
[root@localhost objects]# vim ../nagios.cfg
# Definitions for monitoring the remote_192.168.0.122 (Linux) host
cfg_file=/etc/nagios/objects/linux_192.168.0.122.cfg
3、配置该文件:
[root@localhost objects]# cat linux_192.168.0.122.cfg
define host{
use linux-server
host_name linux_192.168.0.122
alias linux server
address 192.168.0.122
}
define service{
use generic-service
host_name linux_192.168.0.122
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name linux_192.168.0.122
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name linux_192.168.0.122
service_description check-users
check_command check_nrpe!check_users
}
上面:
use :表示使用哪个模板,在template.cfg中可以看到有哪些模板或者自己也可以自定义
hostname: 切记不可以与use名相同,否则会报错
alias:别名
address:被监控主机IP
service_description:自己定义
check_command:使用什么命令,!后面就是传递的参数。如果web界面出现某个参数命令未定义。去command中寻找是否有该命令。或者自定义脚本在command中需要给出命令路径。
4、检查配置文件语法:
[root@localhost objects]# nagios -v ../nagios.cfg
5、若没有错误,就重启nagios,web下面去观察。有时可以用命令 先测试一下
[root@localhost objects]# systemctl restart nagios
[root@localhost objects]# /usr/lib64/nagios/plugins/check_nrpe -H 192.168.0.122 -c check_swap
NRPE: Command 'check_swap' not defined
[root@localhost objects]# /usr/lib64/nagios/plugins/check_nrpe -H 192.168.0.122 -c check_load
NRPE: Unable to read output
我的nrpe下所有插件均出现“Unable to read output”,不知道该怎么处理?欢迎各为评论解惑!