天天看點

Monitor Linux machine

-------------------------------Monitoring Client-------------------------------

Add username for nagios system:

# useradd -s /sbin/nologin nagios

Install the necessary plug-ins:

# tar -xzf nagios-plugins-1.4.16.tar.gz

# cd nagios-plugins-1.4.16

# ./configure --sysconfdir=/etc/nagios \

# --with-nagios-user=nagios \

# --with-nagios-group=nagios \

# --prefix=/usr/local/nagios

# make

# make install

Install the NRPE plugin:

# tar -xzf nrpe-2.12.tar.gz

# cd nrpe-2.12

# ./configure --sysconfdir=/etc/nrpe \

# --with-nrpe-user=nagios \

# --with-nrpe-group=nagios \

# --enable-command-args \

# --enable-ssl

# make all

# make install-daemon-config

Configure the service port number file:

# vi /etc/services

#Add by Kingcraft
nrpe    5666/tcp        # NRPE      

Check the disk number:

# fdisk -l

Device Boot   Start     End    Blocks   Id   System
/dev/sda1  *         1      39    307200   83   Linux
/dev/sda2           39    2589  20480000   83   Linux
/dev/sda3         2589    3863  10240000   83   Linux
/dev/sda4         3863    5222  10914816   83   Linux      

Configuring the NRPE configuration file:

# vi /etc/nrpe/nrpe.cfg

server_address=192.168.174.130      ;Monitoring client IP
allowed_hosts=192.168.174.131       ;Monitoring server IP
#Add by Kingcraft
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_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2
command[check_sda3]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda3
command[check_sda4]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda4
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      

Start the nrpe service:

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

Additional nrped services:

# vi /etc/init.d/nrped

#!/bin/sh
nrpe_num=`ps aux | grep /bin/nrpe | grep -v grep | wc -l`
case $1 in
   start)
    if [ $nrpe_num -eq 1 ]
    then
        echo "Error:nrpe is running."
    else
        /usr/local/nagios/bin/nrpe -c /etc/nrpe/nrpe.cfg -d
        echo "nrpe started successfully."
    fi
    ;;
   stop)
    if [ $nrpe_num -eq 1 ]
    then
            nrpe_pid=`ps aux | grep /bin/nrpe | grep -v grep | awk '{print $2}'`
            kill -9 $nrpe_pid
            echo "nrpe stoped successfully."
        else
            echo "Error:nrpe is stoping."
        fi
    ;;
   restart)
    if [ $nrpe_num -eq 1 ]
    then
        nrpe_pid=`ps aux | grep /bin/nrpe | grep -v grep | awk '{print $2}'`
        kill -9 $nrpe_pid
            echo "nrpe stoped successfully."
            /usr/local/nagios/bin/nrpe -c /etc/nrpe/nrpe.cfg -d
            echo "nrpe started successfully."
        else
            echo "Error:nrpe is stoping"
            /usr/local/nagios/bin/nrpe -c /etc/nrpe/nrpe.cfg -d
            echo "nrpe started successfully."
        fi
   esac      

-------------------------------Monitoring Server-------------------------------

# make install-plugin

Define the monitoring command:

# cd /etc/nagios/objects/

# vi commands.cfg

#Add by Kingcraft
define command{
    command_name    check_nrpe
    command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}      

Definition monitor file:

# vi Linuxhost.cfg

#Add by Kingcraft
define host{
    use         linux-server,host-pnp
    host_name   Linuxhost
    alias       Linuxhost
    address     192.168.174.130
    }
define service{
    use                     local-service,srv-pnp
    host_name               Linuxhost
    service_description     users
    check_command           check_nrpe!check_users
    }
define service{
    use                     local-service,srv-pnp
    host_name               Linuxhost
    service_description     load
    check_command           check_nrpe!check_load
    }
define service{
    use                     local-service,srv-pnp
    host_name               Linuxhost
    service_description     sda1
    check_command           check_nrpe!check_sda1
    }
define service{
    use                     local-service,srv-pnp
    host_name               Linuxhost
    service_description     sda2
    check_command           check_nrpe!check_sda2
    }
define service{
    use                     local-service,srv-pnp
    host_name               Linuxhost
    service_description     sda3
    check_command           check_nrpe!check_sda3
    }
define service{
    use                     local-service,srv-pnp
    host_name               Linuxhost
    service_description     sda4
    check_command           check_nrpe!check_sda4
    }
define service{
    use                     local-service,srv-pnp
    host_name               Linuxhost
    service_description     zombie_procs
    check_command           check_nrpe!check_zombie_procs
    }
define service{
    use                     local-service,srv-pnp
    host_name               Linuxhost
    service_description     total_procs
    check_command           check_nrpe!check_total_procs
    }      

Empowering for monitoring files:

# chown nagios:nagios /etc/nagios/objects/Linuxhost.cfg

Modify the nagios configuration file:

# vi ../nagios.cfg

#Add by Kingcraft
cfg_file=/etc/nagios/objects/Linuxhost.cfg      

Syntax checking:

# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg

restart httpd&nagios:

# service httpd restart

# service nagios restart

------------------------------------------Note--------------------------------------------

  • Required packages address:http://down.51cto.com/data/751797
  • nrped can not join chkconfig, I hope the experts can give pointers

繼續閱讀