CentOS7安装Nagios并配置出图详解(3)

命令内容

 

命令格式

 

关闭nrpe

 

pkill nrpe

 

启动nrpe

 

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

 

启动nrpe(只适用于有编写nrpe脚本的情况)

 

systemctl start nrpe.service

 

检查nrpe是否启动

 

netstat -lnt
(通过检查5666端口是否打开)

 

配置运行环境

首先关闭防火墙:

[root@localhost ~]# systemctl stop firewalld.service

[root@localhost ~]# yum install gcc glibc glibc-common -y

[root@localhost ~]# yum install gd gd-devel openssl openssl-devel -y

[root@localhost ~]# yum install php php-gd perl net-tools -y

安装nagios-plugin

1)先添加nagios用户

[root@localhost ~]# useradd -s /sbin/nologin nagios #禁止nagios用户登录

2)NRPE依赖于nagios-plugins,因此,需要先安装之

进入到/usr/local/src目录下开始执行下面的命令

[root@localhost src]# tar zxf nagios-plugins-2.0.3.tar.gz

[root@localhost src]# cd nagios-plugins-2.0.3

[root@localhost nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

[root@localhost nagios-plugins-2.0.3]# make all

[root@localhost nagios-plugins-2.0.3]# make install

安装nrpe

进入到/usr/local/src目录下开始执行下面的命令

[root@localhost src]# tar -zxf nrpe-2.15.tar.gz

[root@localhost src]# cd nrpe-2.15

[root@localhost nrpe-2.15]# ./configure --with-nrpe-user=nagios \

--with-nrpe-group=nagios \

--with-nagios-user=nagios \

--with-nagios-group=nagios \

--enable-command-args \

--enable-ssl

CentOS7安装Nagios并配置出图详解

[root@localhost nrpe-2.15]# make all

[root@localhost nrpe-2.15]# make install-plugin

[root@localhost nrpe-2.15]# make install-daemon

[root@localhost nrpe-2.15]# make install-daemon-config

[root@localhost nrpe-2.15]# ls /usr/local/nagios/libexec/    #如果安装成功里面有好多NRPE的插件

CentOS7安装Nagios并配置出图详解

注意是否有check_nrpe这个插件(没有的话就说明了nrpe没有安装成功)

启动nrpe

方法一:用命令启动nrpe

[root@localhost ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

#这条命令启动nrpe

如果要重启nrpe,先执行命令:

[root@localhost ~]# pkill nrpe  #关闭nrpe

[root@localhost ~]# netstat -lnt  #这条命令用来检查端口,看5666端口是否已经被关闭

[root@localhost ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

#重启nrpe进程

方法二:创建启动nrpe的脚本

为了便于NRPE服务的启动,可以将如下内容定义为/etc/init.d/nrpe脚本,在/etc/init.d目录下新建一个名为nrpe的文件,把下面内容复制进去


#!/bin/bash

# chkconfig: 2345 88 12

# description: NRPE DAEMON

NRPE=/usr/local/nagios/bin/nrpe

NRPECONF=/usr/local/nagios/etc/nrpe.cfg

case "$1" in

start)

echo -n "Starting NRPE daemon..."

$NRPE -c $NRPECONF -d

echo " done."

;;

stop)

echo -n "Stopping NRPE daemon..."

pkill -u nagios nrpe

echo " done."

;;

restart)

$0 stop

sleep 2

$0 start

;;

*)

echo "Usage: $0 start|stop|restart"

;;

esac

exit 0
 

然后添加运行权限:

[root@localhost ~]# chmod +x /etc/init.d/nrpe

启动nrpe

[root@localhost ~]# systemctl start nrpe.service

检查5666端口是否成功启动

[root@localhost ~]# netstat -tnlp

CentOS7安装Nagios并配置出图详解

5666端口已经成功启动

在/usr/local/nagios/etc/nrpe.cfg文件中添加监控主机的ip地址

[root@localhost etc]# vi nrpe.cfg  +81

将allowed_hosts=127.0.0.1 修改为 allowed_hosts=127.0.0.1,192.168.1.204(这是监控主机的ip地址,本机的ip地址为192.168.1.112)

然后重启nrpe

[root@localhost ~]# pkill nrpe

[root@localhost ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

在监控主机上(ip地址为192.168.1.204)输入下面的命令来检查两个机器之间是否成功通信

[root@localhost ~]# cd /usr/local/nagios/libexec/

[root@localhost libexec]# ./check_nrpe -H 192.168.1.113

NRPE v2.15  #通信成功

至此,远程主机安装nagios完毕。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/0b4cd6eb608731b5635557fd83c0c990.html