nagios setup

http://www.cnblogs.com/kaituorensheng/p/4682565.html 

How toset up Nagios Remote Plugin Executor (NRPE) in Linux

Last updated on March 25,2014 Authored by Sarmed Rahman1 Comment

As far asnetwork management is concerned, Nagios is oneof the most powerful tools. Nagios can monitor the reachability of remotehosts, as well as the state of services running on them. However, what if wewant to monitor something other than network services for a remote host? Forexample, we may want to monitor the disk utilization or CPU processor load of aremote host. Nagios Remote Plugin Executor (NRPE) is a tool that can help withdoing that. NRPE allows one to execute Nagios plugins installed on remotehosts, and integrate them with an existingNagios server.

This tutorial will cover how to set up NRPE on an existing Nagiosdeployment. The tutorial is primarily divided into two parts:

  • Configure remote hosts.
  • Configure a Nagios monitoring server.

We will then finish off by defining some custom commands that can be usedwith NRPE.

Configure Remote Hosts for NRPE

Step One: Installing NRPE Service

You need to install NRPE service on every remote host that you want tomonitor using NRPE. NRPE service daemon on each remote host will thencommunicate with a Nagios monitoring server.

Necessarypackages for NRPE service can easily be installed using apt-get or yum, subject to the platform. In case ofCentOS, we will need to add Repoforge repository as NRPEis not available in CentOS repositories.

On Debian, Ubuntu or Linux Mint:

# apt-get install nagios-nrpe-server

On CentOS, Fedora or RHEL:

# yum install nagios-nrpe

Step Two: Preparing Configuration File

Theconfiguration file /etc/nagios/nrpe.cfg issimilar for Debian-based and RedHat-based systems. The configuration file isbacked up, and then updated as follows.

# vim /etc/nagios/nrpe.cfg

## NRPE service port can be customized ##

server_port=5666

 

## the nagios monitoring server is permitted ##

## NOTE: There is no space after the comma ##

allowed_hosts=127.0.0.1,X.X.X.X-IP_v4_of_Nagios_server

 

## The following examples use hard-coded commandarguments.

## These parameters can be modified as needed.

 

## NOTE: For CentOS 64 bit, use /usr/lib64 instead of/usr/lib ##

 

command[check_users]=/usr/lib/nagios/plugins/check_users-w 5 -c 10

command[check_load]=/usr/lib/nagios/plugins/check_load -w15,10,5 -c 30,25,20

command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w20% -c 10% -p /dev/hda1

command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs-w 5 -c 10 -s Z

command[check_total_procs]=/usr/lib/nagios/plugins/check_procs-w 150 -c 200

Now that the configuration file is ready, NRPE service is ready to befired up.

Step Three: Initiating NRPE Service

For RedHat-based systems, the NRPE service needs to be added as a startupservice.

On Debian, Ubuntu, Linux Mint:

# service nagios-nrpe-server restart

On CentOS, Fedora or RHEL:

# service nrpe restart
# chkconfig nrpe on

Step Four: Verifying NRPE Service Status

Informationabout NRPE daemon status can be found in the system log. For a Debian-basedsystem, the log file will be /var/log/syslog. The log file for a RedHat-basedsystem will be/var/log/messages. A samplelog is provided below for reference.

nrpe[19723]: Starting up daemon

nrpe[19723]: Listening for connections on port 5666

nrpe[19723]: Allowing connections from: 127.0.0.1,X.X.X.X

In case firewall is running, TCP port 5666 should be open, which is usedby NRPE daemon.

# netstat -tpln | grep 5666

tcp    0    0   0.0.0.0:5666      0.0.0.0:*      LISTEN   19885/nrpe

Configure Nagios Monitoring Server for NRPE

The first step in configuring an existing Nagios monitoring server forNRPE is to install NRPE plugin on the server.

Step One: Installing NRPE Plugin

In case theNagios server is running on a Debian-based system (Debian, Ubuntu or LinuxMint), a necessary package can be installed using apt-get.

# apt-get install nagios-nrpe-plugin

After theplugin is installed, the check_nrpe command,which comes with the plugin, is modified a bit.

# vim /etc/nagios-plugins/config/check_nrpe.cfg

## the default command is overwritten ##

define command{

       command_name    check_nrpe

       command_line   /usr/lib/nagios/plugins/check_nrpe -H '$HOSTADDRESS$' -c '$ARG1$'

}

In case theNagios server is running on a RedHat-based system (CentOS, Fedora or RHEL), youcan install NRPE plugin using yum. On CentOS, adding Repoforge repository isnecessary.

# yum install nagios-plugins-nrpe

Now that the NRPE plugin is installed, proceed to configure a Nagiosserver following the rest of the steps.

Step Two: Defining Nagios Command for NRPE Plugin

First, we need to define a command in Nagios for using NRPE.

# vim /etc/nagios/objects/commands.cfg

## NOTE: For CentOS 64 bit, use /usr/lib64 instead of/usr/lib ##

define command{

       command_name    check_nrpe

       command_line   /usr/lib/nagios/plugins/check_nrpe -H '$HOSTADDRESS$' -c '$ARG1$'

}

Step Three: Adding Host and Command Definition

Next, define remote host(s) and commands to execute remotely on them.

The following shows sample definitions of a remote host a command toexecute on the host. Naturally, your configuration will be adjusted based onyour requirements. The path to the file is slightly different for Debian-basedand RedHat-based systems. But the content of the files are identical.

On Debian, Ubuntu or Linux Mint:

# vim /etc/nagios3/conf.d/nrpe.cfg

On CentOS, Fedora or RHEL:

# vim /etc/nagios/objects/nrpe.cfg

define host{

        use                     linux-server

       host_name               server-1

        alias                   server-1

       address                X.X.X.X-IPv4_address_of_remote_host

}

 

define service {

       host_name                      server-1

       service_description            Check Load

        check_command                   check_nrpe!check_load

       check_interval                  1

        use                             generic-service

}

Step Four: Restarting Nagios Service

Before restarting Nagios, updated configuration is verified with a dryrun.

On Ubuntu, Debian, or Linux Mint:

# nagios3 -v /etc/nagios3/nagios.cfg

On CentOS, Fedora or RHEL:

# nagios -v /etc/nagios/nagios.cfg

If everything goes well, Nagios service can be restarted.

# service nagios restart

Configuring Custom Commands with NRPE

Setup on Remote Servers

The followingis a list of custom commands that can be used with NRPE. These commands aredefined in the file /etc/nagios/nrpe.cfg locatedat the remote servers.

## Warning status when load average exceeds 1, 2 and 1for 1, 5, 15 minute interval, respectively.

## Critical status when load average exceeds 3, 5 and 3for 1, 5, 15 minute interval, respectively.

command[check_load]=/usr/lib/nagios/plugins/check_load -w1,2,1 -c 3,5,3

 

## Warning level 25% and critical level 10% for freespace of /home.

## Could be customized to monitor any partition (e.g./dev/sdb1, /, /var, /home)

command[check_disk]=/usr/lib/nagios/plugins/check_disk -w25% -c 10% -p /home

 

## Warn if number of instances for process_ABC exceeds10. Critical for 20 ##

command[check_process_ABC]=/usr/lib/nagios/plugins/check_procs-w 1:10 -c 1:20 -C process_ABC

 

## Critical if the number of instances for process_XYZdrops below 1 ##

command[check_process_XYZ]=/usr/lib/nagios/plugins/check_procs-w 1: -c 1: -C process_XYZ

Setup on Nagios Monitoring Server

To apply the custom commands defined above, we modify the servicedefinition at Nagios monitoring server as follows. The service definition couldgo to the file where all the services are defined (e.g., /etc/nagios/objects/nrpe.cfgor /etc/nagios3/conf.d/nrpe.cfg)

## example 1: check process XYZ ##

define service {

       host_name                      server-1

       service_description            Check Process XYZ

       check_command                   check_nrpe!check_process_XYZ

       check_interval                  1

        use                             generic-service

}

 

## example 2: check disk state ##

define service {

       host_name                      server-1

       service_description            Check Process XYZ

       check_command                  check_nrpe!check_disk

       check_interval                  1

        use                             generic-service

}

To sum up, NRPE is a powerful add-on to Nagios as it provides provisionfor monitoring a remote server in a highly configurable fashion. Using NRPE, wecan monitor server load, running processes, logged in users, disk states andother parameters.

Hope this helps.

 



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值