Nagios用Check-NRPE方式监控Linux主机

以下安装的软件在被监控端(客户端)
一.下载和安装
1.安装开发包
yum -y groupinstall Development tools
2.下载和安装nagios-plugins
wget  http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
tar zxfv nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
useradd -s /sbin/nologin nagios
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install
3.下载和安装nrpe
wget http://softlayer-dal.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
tar zxfv nrpe-2.15.tar.gz
cd 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
提示报错
checking for SSL headers... configure: error: Cannot find ssl headers
yum -y install openssl-devel
再重新编译一遍
make all
make install-plugin
make install-daemon
make install-daemon-config
ls /usr/local/nagios/libexec/    #如果安装成功里面有好多NRPE的插件
4.配置NRPE
vim /usr/local/nagios/etc/nrpe.cfg

log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
#server_address=127.0.0.1 #暂时先不修改
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=192.168.3.6
command_timeout=60
connection_timeout=300
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2 
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20 -c 10   #还有的话可以自己添加

5.制作启动脚本

vim /etc/init.d/nrped
chmod +x /etc/init.d/nrped

6.启动服务
service nrped start
netstat -anptu
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      31800/nrpe 
二.配置服务端(监控端)
wget http://softlayer-dal.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
tar zxf nrpe-2.15.tar.gz
cd nrpe-2.15
1.安装
./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
make all
make install-plugin
2.测试
ls /usr/local/nagios/libexec/check_nrpe   #如果安装完成会有个check_nrpe的插件
如果失败,检查被控端防火墙
cd /usr/local/nagios/libexec/
./check_nrpe -H 192.168.3.7
NRPE v2.15
2.定义配置文件
cd /usr/local/nagios/etc/objects/
vim commands.cfg

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

3.定义主机

vim linux-server.cfg

define host{
        use                     linux-server            ; Name of host template to use
        host_name               linuxserver
        alias                   my linux server
        address                 192.168.0.102
        }
 
 
 
###############################################################################
###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
###############################################################################
 
# Define an optional hostgroup for Linux machines
#        hostgroup_name  linux-servers ; The name of the hostgroup
#        alias           Linux Servers ; Long name of the group
#        }
 
 
 
###############################################################################
###############################################################################
#
###############################################################################
###############################################################################
 
 
# Define a service to "ping" the local machine
 
define service{
        host_name                       linuxserver
        service_description             users
        check_command                   check_nrpe!check_users
 
# Define a service to check the disk space of the root partition
# on the local machine.  Warning if < 20% free, critical if
# < 10% free space on partition.
 
define service{
        host_name                       linuxserver
        service_description             load
        check_command                   check_nrpe!check_load
 
 
# Define a service to check the number of currently logged in
# users on the local machine.  Warning if > 20 users, critical
# if > 50 users.
 
define service{
        host_name                       linuxserver
        }
 
 
# Define a service to check the number of currently running procs
# on the local machine.  Warning if > 250 processes, critical if
# > 400 users.
 
define service{
        host_name                       linuxserver
        }
 
 
 
# Define a service to check the load on the local machine.
 
define service{
        host_name                       linuxserver
        service_description             zombie
        check_command                   check_nrpe!check_zombie_procs
        }
 
# Define a service to check the swap usage the local machine.
define service{
        host_name                       linuxserver
        service_description             total
        check_command                   check_nrpe!check_total_procs
        }
 
 
 
# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enab
led.
 
 
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP ena
bled.
 
define service{
        use                             local-service         ; Name of service templat
e to use
        host_name                       linuxserver
        service_description             swap
        check_command                   check_nrpe!check_swap
        }

vim ../nagios.cfg

添加一行
cfg_file=/usr/local/nagios/etc/objects/linux-server.cfg
4.检查语法错误
nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart

转载于:https://my.oschina.net/f91jty/blog/168389

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值