标签:监控远程linux release 防火墙 creat nagios安装 使用 generic sed tin
1 安装环境:监控段IP: 192.168.4.34 主机名:nagios.com 操作系统:CentOS release 6.8 (Final)
软件:nagios-4.2.0,nagios-plugins-2.1.2,nrpe-2.15
被监控端IP:192.168.4.111 主机名:client.com操作系统:CentOS release 6.8 (Final)
软件:nagios-plugins-2.1.2,nrpe-2.15
NRPE是Nagios的一个功能扩展,它可在远程Linux/Unix主机上执行插件程序。通过在远程服务器上安装NRPE插件及Nagios插件程序来向Nagios监控平台提供该服务器的本地情况,如CPU负载,内存使用,磁盘使用等。
Nagios监控端称为Nagios服务器端,而将远程被监控的主机称为Nagios客户端。
NRPE进程,运行于远程主机(Linux/UNIX),也就是被监控端。 当nagios需要监控远程主机(Linux/UNIX)的服务时,NRPE具体的工作流程如下:
Nagios会执行check_nrpe插件,并告诉它需要监控的服务项;
check_nrpe插件通过SSL方式与被监控端的nrpe进程连接;
nrpe进程运行对应的nagios插件来执行服务或资源的监测;
NRPE 进程将监测的结果返回给check_nrpe 插件,check_nrpe插件又将结果传递给nagios进程做后续处理。
注意:NRPE进程能够进行服务与资源监控的前提是:远程主机(Linux/UNIX)必须装有nagios插件。
[root@client ~]# useradd -s /sbin/nologin nagios
[root@client ~]# id nagios
uid=500(nagios) gid=500(nagios) groups=500(nagios)
[root@client ~]# tar xf nagios-plugins-2.1.2.tar.gz
[root@client ~]# cd nagios-plugins-2.1.2
[root@client nagios-plugins-2.1.2]# ./configure
--with-nagios-user=nagios --with-nagios-group=nagios
注意:要监控MySQL需要添加 –with-mysql
config.status: creating po/Makefile
--with-apt-get-command:
--with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
--with-ping-command: /bin/ping -n -U -w %d -c %d %s
--with-ipv6: yes
--with-mysql: no
--with-openssl: yes
--with-gnutls: no
--enable-extra-opts: yes
--with-perl: /usr/bin/perl
--enable-perl-modules: no
--with-cgiurl: /nagios/cgi-bin
--with-trusted-path: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
--enable-libtap: no
[root@client ~]# tar xf nrpe-2.15.tar.gz
[root@client ~]# cd nrpe-2.15
[root@client 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
[root@client nrpe-2.15]# make all
[root@client nrpe-2.15]# make install-plugin
[root@client nrpe-2.15]# make install-daemon
[root@client nrpe-2.15]# make install-daemon-config
如果需要打开5666端口,则需要下列命令(本案例默认关闭的防火墙)
[root@kk nrpe-3.0.1]#vim /usr/local/nagios/etc/nrpe.cfg
修改allowed_hosts=192.168.4.34,允许Nagios服务器端访问;
在命令行测试如下的监测命令,这里根据自己的监测需求对命令进行修改,并写入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_sda1
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_zombie_procs
[root@client ~]# grep -v ‘^#‘ /usr/local/nagios/etc/nrpe.cfg |sed ‘/^$/d‘
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=192.168.4.34 #允许Nagios服务器端访问
dont_blame_nrpe=0
allow_bash_command_substitution=0
debug=0
command_timeout=60
connection_timeout=300
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
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
root@client ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
1、 查看启动服务
2、 [root@client ~]# netstat -tnlp | grep 5666
3、 tcp 0 0 0.0.0.0:5666 0.0.0.0: LISTEN 32301/nrpe
tcp 0 0 :::5666 ::: LISTEN 32301/nrpe
有两种方式用于管理nrpe服务,nrpe有两种运行模式:
-i # Run as a service under inetd or xinetd
-d # Run as a standalone daemon 可以为nrpe编写启动脚本,使得nrpe以standard alone方式运行
4、 配置NRPE启动服务脚本
[root@client ~]# vim /etc/init.d/nrped
#!/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@client ~]# vim /etc/init.d/nrped
[root@client ~]# chmod +x /etc/init.d/nrped
[root@client ~]# chkconfig --add nrped
[root@client ~]# chkconfig nrped on
[root@client ~]# service nrped restart
Stopping NRPE daemon... done.
Starting NRPE daemon... done.
[root@client ~]#yum -y install openssl openssl-devel
[root@nagios ~]# tar xf nrpe-2.15.tar.gz
[root@nagios ~]# cd nrpe-2.15
[root@nagios nrpe-2.15]# ./configure --with-nrpe-user=nagios --with-nagios-group=nagios \
--with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
[root@nagios nrpe-2.15]# make all
[root@nagios nrpe-2.15]# make install-plugin
安装完成后,会在Nagios安装目录的libexec下生成check_nrpe的插件,如下所示:
[root@nagios ~]# ls -l /usr/local/nagios/libexec/check_nrpe
-rwxrwxr-x. 1 nagios nagios 76777 Nov 21 19:06 /usr/local/nagios/libexec/check_nrpe
[root@nagios ~]# cd /usr/local/nagios/libexec/
[root@nagios libexec]# ./check_nrpe -H 192.168.4.111
NRPE v2.15
[root@nagios nagios]# cd etc/objects/
[root@nagios objects]# vim commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H "$HOSTADDRESS$" -c "$ARG1$"
}
[root@nagios objects]# more linuxserver.cfg
define host {
use linux-server
host_name linuxhost
alias My Linux Host
address 192.168.4.111
}
define host {
use linux-server
host_name linuxhost
alias My Linux Host
address 192.168.4.111
}
define service{
use generic-service
host_name linuxhost
service_description CHECK USERS
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name linuxhost
service_description CHECK Load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name linuxhost
service_description CHECK sda1
check_command check_nrpe!check_sda1
}
define service{
use generic-service
host_name linuxhost
service_description CHECK Zombie
check_command check_nrpe!check_procs
}
define service{
use generic-service
host_name linuxhost
service_description CHECK procs
check_command check_nrpe!check_total_procs
}
[root@nagios etc]# vim nagios.cfg
#增加一行
cfg_file=/usr/local/nagios/etc/objects/linuxserver.cfg
[root@nagios etc]# service nagios configtest
[root@nagios etc]# service nagios restart
标签:监控远程linux release 防火墙 creat nagios安装 使用 generic sed tin
原文地址:http://blog.51cto.com/437549/2320275