wordpress 微软 linux 程序员 apache Ubuntu java 开源 mysql Python centos Firefox Android php Windows linux命令 nginx shell HTML5 google

使用nagios nrpe监控远程Linux主机

监控Linux本地主机时,我们可以直接更改配置文件进行监控,如果需要监控的主机与nagios不在同一机器上,即监控远程linux主机时,我们需要借助NRPE插件实现。

nrpe工作原理图:

nrpe

远程主机的操作

下载Nagios Plugins和NRPE (Nagios Plugins 最好用1.4.15  1.4.16会报错)

cd /tmp
wget http://iweb.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz
wget http://iweb.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz

创建nagios帐号

useradd nagios
passwd nagios

安装nagios-plugin

cd /tmp
tar xvfz nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
export LDFLAGS=-ldl

./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
make
make install

chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec/

安装NRPE

cd /tmp
tar xvfz nrpe-2.13.tar.gz
cd nrpe-2.13

./configure //需要安装openssl-devel
make all
make install-plugin
make install-daemon
make install-daemon-config
yum install xinetd
make install-xinetd

配置NRPE以守护进程运行

1、更改/etc/xinetd.d/nrpe文件,设置允许nagios服务器连接,如nagios服务器的ip为192.168.1.2:

only_from = 127.0.0.1 192.168.1.2

2、在/etc/services结尾增加:

nrpe 5666/tcp # NRPE

3、启动xinetd

service xinetd restart

4、验证nrpe是否监听

netstat -at | grep nrpe

5、测试nrpe是否正常运行

/usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.13

6、更改 /usr/local/nagios/etc/nrpe.cfg

nrpe.cfg文件里包含需要监控远程主机的命令,如:

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

nagios服务器的操作

首先安装nagios,参考:http://www.CentOS.bz/2012/02/centos-install-nagios/

下载安装NRPE

cd /tmp
wget http://iweb.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz
tar xvfz nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
make install-plugin
测试是否正常:

/usr/local/nagios/libexec/check_nrpe -H 192.168.1.3
NRPE v2.13

为监控远程主机定义host和service

1、定义check_nrpe命令

在文件/usr/local/nagios/etc/objects/commands.cfg后面增加:

# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$
}

2、创建/usr/local/nagios/etc/objects/remotehost.cfg

host定义示例:

define host{ 
        use     linux-server 
        host_name       master 
        alias           master-server 
        address         192.168.209.254 
} 

Service定义示例:

define service{
use generic-service
service_description Root Partition
check_command check_nrpe!check_disk
}

之后重载nagios配置文件使其生效

service nagios reload

延伸阅读

评论