Nagios安装配置nrpe

2018-08-19  本文已影响0人  大简SimpleSmile

监控工具-Nagios-Nagios安装配置nrpe

参考链接1

参考文件:

远程被监控主机安装配置

  1. 用户设置

As of NRPE version 3.0, the Makefile includes targets to add the required users and groups to the computer's local accounts (usually /etc/passwd), if necessary. If you will be adding them to LDAP or some other authentication system, you will have to do it yourself.

  1. 安装Nagios Plugin
mkdir ~/downloads
cd ~/downloads
wget http://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
tar xzf nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1
./configure
make
make install

根据版本不同,有可能需要手工调整目录权限

useradd nagios
groupadd nagios
usermod -a -G nagios nagios
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec

  1. 安装xinetd
yum install xinetd

或从光盘Package目录下找到包rpm安装

  1. 安装NRPE Deamon

下载

cd ~/downloads
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz
tar xzf nrpe-3.2.1.tar.gz
cd nrpe-nrpe-3.2.1

编译

./configure
make all

如果没有手工创建组和用户

make install-groups-users

安装nrpe插件,守护进程,实例配置文件

make install
make install-config

If you want NRPE to run per-connection under inetd, xinetd, launchd, systemd, smf, etc. run the following command:

make install-inetd

Make sure nrpe 5666/tcp is in your /etc/services file, if applicable.If you want to run NRPE all the time under init, launchd, systemd, smf, etc. run the followning command:

make install-init

守护进程的控制命令

service xinetd restart
systemctl reload xinetd # systemd
systemctl enable nrpe && systemctl start nrpe # systemd

  1. 测试nrpe本地服务情况

添加nrpe到/etc/services

echo "nrpe 5666/tcp" >> /etc/services

确认nrpe在运行

netstat -at | egrep "nrpe|5666"

如果失败,检查以下几项:

• You added the nrpe entry to your /etc/services file

• The only_from directive in the /etc/xinetd.d/nrpe file contains an entry for "127.0.0.1"

• xinetd is installed and started

• The appropriate line in /etc/inetd.conf has been uncommented

• Check the system log files for references about xinetd or nrpe and fix any problems that are reported

检查nrpe是否正确的运行

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

以上检查正确的提示示例: [图片上传失败...(image-25155d-1534665580804)]

最后,以上都没问题:

add the hostname or IP address of the nagios server to the /etc/xinetd.d/nrpe file, or /etc/hosts-allow and hosts-deny.

  1. 放开防火墙规则

iptables类型

# iptables -I RH-Firewall-1-INPUT -p tcp -m tcp –dport 5666 -j ACCEPT
# service iptables save

  1. 定义npre命令

可以通过修改/usr/local/nagios/etc/nrpe.cfg,编辑命令的定义,增加新的命令。

若按本文档安装,可以有一下命令供测试:

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_users

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_load

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_hda1

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_zombie_procs

done on the remote host

服务端安装配置

假定服务端nagios已经安装完毕,还需要做以下几件事儿:

  1. 安装nrpe
cd ~/downloads
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz
tar xzf nrpe-3.2.1.tar.gz
cd nrpe-nrpe-3.2.1
./configure
make check_nrpe
make install-plugin

  1. 测试与远程nrpe daemon的通信

替换ip执行

/usr/local/nagios/libexec/check_nrpe -H 192.168.0.1
NRPE v3.2.1

If the plugin returns a timeout error, check the following:

• Make sure there isn't a firewall between the remote host and the monitoring server that is blocking communication

• Make sure that the NRPE daemon is installed properly and running on the remote host

• Make sure the remote host doesn't have local firewall rules that prevent the monitoring server from talking to the NRPE daemon

如果报以下错误:

[图片上传失败...(image-ac0032-1534665580804)]

参考如下链接修改:

link

Edit: /usr/local/nagios/etc/nrpe.cfg
line 98: allowed_hosts=x.x.x.x  #添加服务端ip
systemctl restart nrpe.service && systemctl restart xinetd.service

再次测试:

[图片上传失败...(image-82c752-1534665580804)]

  1. 创建命令定义

通常是nagios/etc/objects/commands.cfg 中添加

define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

  1. 创建主机或服务定义

先添加模板,通常是nagios/etc/objects/templates.cfg 中添加

define host{
name linux-box ; Name of this template
use generic-host ; Inherit default values
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,r
contact_groups admins
register 0 ; DONT REGISTER THIS - ITS A TEMPLATE
}

定义一个使用该模板的主机:

define host{
        use linux-box ; Inherit default values from a template
        host_name remotehost ; The name we're giving to this server
        alias centos7 ; A longer name for the server
        address 172.16.2.240 ; IP address of the server
}

定义一些服务监控远程主机

define service{
use generic-service
host_name remotehost
service_description CPU Load
check_command check_nrpe!check_load
}

define service{
use generic-service
host_name remotehost
service_description Current Users
check_command check_nrpe!check_users
}

define service{
use generic-service
host_name remotehost
service_description /dev/hda1 Free Space
check_command check_nrpe!check_hda1
}

define service{
use generic-service
host_name remotehost
service_description Total Processes
check_command check_nrpe!check_total_procs
}

define service{
use generic-service
host_name remotehost
service_description Total Processes
check_command check_nrpe!check_total_procs
}

  1. 重启nagios

检查配置文件是否正确:

 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

systemctl restart nagios

web接口查看,需要等几分钟才会有内容,开始只有

[图片上传失败...(image-b3f748-1534665580802)]

END

更多内容请查阅官方文档:

上一篇 下一篇

猜你喜欢

热点阅读