Introduction to the

Nagios is an automated operations tool that helps operations personnel monitor server health and has alarm capabilities. This article will introduce the installation method and detailed configuration method.

Nagios Monitoring Service Application Guide Local resources: load, CPU, disk, memory. IO, RAID, temperature, passwd file changes, all local files Fingerprint identification Network services: port, URL, packet loss, process, network traffic Other devices: switch, printer, Windows, etc. Business data: the number of login failures, the number of login failures, the number of verification code input failures, the concurrent traffic of an API interface, orders on e-commerce websites, and the number of payment transactions

Nagios members: main program nagios, plugins nagios-plugins, and some optional clients nrpe, NSClient++,NSCA, and NDOUtils

  • NRPE– semi-passive mode Storage location: installed on the client NRPE function: execute the relevant script plug-in on the client to obtain data, to achieve the monitoring of the client host resources. Existence mode: Agent mode, enabled on port 5666
  • NSClient++ : semi-passive mode, equivalent to nrpe for Linux
  • NDOUtils (not recommended) Location: Server function: It is used to store nagios configuration information and data generated by each event in the database, so as to realize the retrieval and processing of these data.
  • NSCA: Purely passive mode –> Used in distributed monitoring environment Location: NSCA needs to be installed on both nagios server and client

Software version

Nagios version: 4.3.1 Nagios-plugins version: 2.2.1 NRPE version: 3.1.0

Implement environment

Nagios runs in a LAMP environment (if LAMP is not installed, please refer to my article on installing LNMP, because I have compiled and installed PHP and Mysql, this article directly uses the yum installation of Apache, of course, you can also compile and install Apache. Depends on personal preference and company needs)

Centos Linux Release 7.3.1611 (Core) 64-bit Apache Nginx 1.12.0 Mysql version 5.7.18 PHP version 7.1.4

Download nagios software and add-on packages

Download slow words can go to my network disk download

[root@nagios ~]# cd /software/
[root@nagios software]Wget # https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.1.tar.gz
[root@nagios software]Wget # https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
[root@nagios software]Wget # https://sourceforge.net/projects/nagios/files/nrpe-3.x/nrpe-3.1.0.tar.gz
[root@nagios software]# ll-rw-r--r-- 1 root root 11095797 April 21 15:57 nagios-4.3.1.tar.gz -rw-r--r-- 1 root root 2728818 April 20 00:04 Nagios-plugins-2.2.1.tar. gz -rw-r--r-- 1 root root 501028 4月 17 22:36 nrPE-3.2.0.tar. gzCopy the code

Install the Nagios-server server

Installing dependency packages

[root@nagios software]# yum -y install httpd httpd-devel gcc glibc glibc-common gd gd-devel perl-devel perl-CPAN fcgi perl-FCGI perl-FCGI-ProcManager
Copy the code

Unzip the Nagios source package

[root@nagios software]# tar ZXVF nagios - 4.3.1. Tar. Gz
Copy the code

The decompressed directory is displayed

[root@nagios software]# CD nagios - 4.3.1 /
Copy the code

Create ngaiOS user and group (add nginx startup user WWW to nagios related group)

[root @ nagios nagios - 4.3.1]# useradd nagios -s /sbin/nologin [root @ nagios nagios - 4.3.1]# id www[root @ nagios nagios - 4.3.1]# groupadd nagcmd[root @ nagios nagios - 4.3.1]# usermod -a -G nagcmd nagios [root @ nagios nagios - 4.3.1]# usermod -a -G nagcmd www[root @ nagios nagios - 4.3.1]# id -n -G nagios[root @ nagios nagios - 4.3.1]# id -n -G www
Copy the code

Configure nagios

[root @ client1 nagios - 4.3.1]# ./configure --with-command-group=nagcmd
Copy the code

Compilation and installation

[root @ nagios nagios - 4.3.1]# make all[root @ nagios nagios - 4.3.1]# make install-init[root @ nagios nagios - 4.3.1]# make install-commandmode[root @ nagios nagios - 4.3.1]# make install-config[root @ nagios nagios - 4.3.1]# make install	[root @ nagios nagios - 4.3.1]# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/[root @ nagios nagios - 4.3.1]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers[root @ nagios nagios - 4.3.1]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Copy the code

Generate the Apache configuration file

[root @ nagios nagios - 4.3.1]# make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
if[0-eq1];then \
	ln -s /etc/httpd/conf.d/nagios.conf /etc/apache2/sites-enabled/nagios.conf; \
fi

*** Nagios/Apache conf file installed ***
Copy the code

Generate authentication information for the Nagios Web interface

[root @ nagios nagios - 4.3.1]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosNew password: ==> Enter the password, here I enter the password is nagios, remember this password re-type New password: ==> confirm the password Adding passwordfor user nagios
Copy the code

Modify the apache configuration file vi/etc/HTTPD/conf/HTTPD. Conf

Listen 80 ===> Change it to Listen 8080 User apache ===> Change it to User WWW Group apache ===> Change it to Group WWW DirectoryIndex index.html HTML AddType Application/x-gz.gz. TGZ ===> Add the following line of AddHandler application/x-httpd-php .php# LoadModule foo_module modules/mod_foo.so ===> Add a line below
 LoadModule php7_module        modules/libphp7.so
Copy the code

Apache configuration file reference

[root@nagios httpd]# grep -v '^$' /etc/httpd/conf/httpd.conf|grep -v '#'
ServerRoot "/etc/httpd"
Listen 8080
LoadModule php7_module        modules/libphp7.so
Include conf.modules.d/*.conf
User www
Group www
ServerAdmin root@localhost
<Directory />
    AllowOverride none
    Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
    AllowOverride None
    Require all granted
</Directory>
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
<Files ".ht*">
    Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>
<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddHandler application/x-httpd-php .php
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
Copy the code

Recompile PHP to make it directly Apache (i.e., with –with-apxs2)

[root @ nagios nagios - 4.3.1]# CD/software/PHP - 7.1.4 /[root @ nagios PHP - 7.1.4]# ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo -enable-tokenizer --enable-zip --with-apxs2[root @ nagios PHP - 7.1.4]# make && make install[root @ nagios PHP - 7.1.4]# cd /etc/httpd/
[root@nagios httpd]# ll /etc/httpd/modules/libphp7.so - rwxr-xr-x mto 1 root root on April 24, 38908880 joyfully the/etc/HTTPD/modules/libphp7 so = = = > can see the module has been generatedCopy the code

Start the apache

[root@nagios httpd]# systemctl start httpd
[root@nagios httpd]# systemctl enable httpd
Copy the code

Start nagios

chkconfig nagios on
/etc/init.d/nagios start
Copy the code

Type IP :8080/nagios in your browser to test whether the Nagios-Web page can open


Go to the decompressed directory for configuration

[root@nagios software]Nagios plugins - 2.2.1 / # CD[root @ nagios nagios plugins - 2.2.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --enable-perl-modules
Copy the code

Compilation and installation

[root @ nagios nagios plugins - 2.2.1]# make && make install
Copy the code


Go to the decompressed directory for configuration

[root@nagios software]# CD nrpe - 3.1.0 /[root @ nagios nrpe - 3.1.0]# ./configure 
Copy the code

Compilation and installation

[root @ nagios nrpe - 3.1.0]# make all[root @ nagios nrpe - 3.1.0]# make install-plugin[root @ nagios nrpe - 3.1.0]# make install-daemon[root @ nagios nrpe - 3.1.0]# make install-daemon-config[root @ nagios nrpe - 3.1.0]# cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg 
Copy the code

After the installation is complete, check to see if there are plug-ins under Libexec

[root @ nagios nrpe - 3.1.0]# ls /usr/local/nagios/libexec/
check_apt       check_flexlm        check_log          check_ntp_peer  check_smtp    disable_active_service_checks
check_breeze    check_fping         check_mailq        check_ntp_time  check_spop    disable_notifications
check_by_ssh    check_ftp           check_mrtg         check_nwstat    check_ssh     distributed-monitoring
check_clamd     check_http          check_mrtgtraf     check_oracle    check_ssmtp   enable_active_service_checks
check_cluster   check_icmp          check_mysql        check_overcr    check_swap    enable_notifications
check_dhcp      check_ide_smart     check_mysql_query  check_ping      check_tcp     eventhandlers
check_dig       check_ifoperstatus  check_nagios       check_pop       check_time    negate
check_disk      check_ifstatus      check_nntp         check_procs     check_udp     redundancy-scenario1
check_disk_smb  check_imap          check_nntps        check_real      check_ups     submit_check_result
check_dns       check_ircd          check_nrpe         check_rpc       check_uptime  urlize
check_dummy     check_jabber        check_nt           check_sensors   check_users   utils.pm
check_file_age  check_load          check_ntp          check_simap     check_wave    utils.sh
Copy the code

Start NRPE and test whether the server can connect locally

[root @ nagios nrpe - 3.1.0]# /usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg [root @ nagios nrpe - 3.1.0]# echo "/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg" >> /etc/rc.local[root @ nagios nrpe - 3.1.0]/etc/rc.local = /etc/rc.local = /etc/rc.local = /etc/rc.[root @ nagios nrpe - 3.1.0]# netstat -lnput|grep 5666TCP 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 67176/nrpe tcp6 0 0: ::5666 ::* LISTEN 67176/nrpe [root@nagios nrPE-3.1.0]# /usr/local/nagios/libexec/check_nrpe -H localhost NRPE v3.1.0 - rc1Copy the code


Install nagios-plugin install dependencies

[root@client1 software]# yum install perl-devel perl-CPAN -y
Copy the code

Create a user

[root@client1 software]# useradd nagios -M -s /sbin/nologin
Copy the code

Unzip the nagios-plugin source package

[root@client1 software]# tar ZXVF nagios plugins - 2.2.1. Tar. Gz
Copy the code

Go to the decompressed directory for configuration

[root@client1 software]Nagios plugins - 2.2.1 / # CD[root @ client1 nagios plugins - 2.2.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
Copy the code

Compilation and installation

[root @ client1 nagios plugins - 2.2.1]# make && make install
Copy the code


Go to the decompressed directory for configuration

[root@client1 software]# CD nrpe - 3.1.0 /[root @ client1 nrpe - 3.1.0]# ./configure
Copy the code

Compilation and installation

[root @ client1 nrpe - 3.1.0]# make all[root @ client1 nrpe - 3.1.0]# make install-plugin[root @ client1 nrpe - 3.1.0]# make install-daemon[root @ client1 nrpe - 3.1.0]# make install-daemon-config[root @ client1 nrpe - 3.1.0]# mkdir /usr/local/nagios/etc/[root @ client1 nrpe - 3.1.0]# cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg
Copy the code

After the installation is complete, check to see if there are plug-ins under Libexec

[root @ client1 nrpe - 3.1.0]# ls /usr/local/nagios/libexec/
check_apt       check_dummy         check_imap         check_nagios    check_overcr   check_ssh     negate
check_breeze    check_file_age      check_ircd         check_nntp      check_ping     check_ssmtp   urlize
check_by_ssh    check_flexlm        check_jabber       check_nntps     check_pop      check_swap    utils.pm
check_clamd     check_fping         check_load         check_nrpe      check_procs    check_tcp     utils.sh
check_cluster   check_ftp           check_log          check_nt        check_real     check_time
check_dhcp      check_http          check_mailq        check_ntp       check_rpc      check_udp
check_dig       check_icmp          check_mrtg         check_ntp_peer  check_sensors  check_ups
check_disk      check_ide_smart     check_mrtgtraf     check_ntp_time  check_simap    check_uptime
check_disk_smb  check_ifoperstatus  check_mysql        check_nwstat    check_smtp     check_users
check_dns       check_ifstatus      check_mysql_query  check_oracle    check_spop     check_wave
Copy the code

Start NRPE and test whether the server can connect locally

[root @ client1 nrpe - 3.1.0]# /usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg [root @ client1 nrpe - 3.1.0]# echo "/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg" >> /etc/rc.local[root @ client1 nrpe - 3.1.0]/etc/rc.local = /etc/rc.local = /etc/rc.local = /etc/rc.[root @ client1 nrpe - 3.1.0]# netstat -lnput|grep 5666TCP 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 28296/nrpe tcp6 0 0: ::5666 ::* LISTEN 28296/nrpe [root@client1 nrPE-3.1.0]# /usr/local/nagios/libexec/check_nrpe -H localhostNRPE v3.1.0 - rc1Copy the code

Modifying a Configuration File

[root @ client1 nrpe - 3.1.0]# cd /usr/local/nagios/etc/
Copy the code

vi nrpe.cfg

Allow server IP and local access. 172.16.0.18 is the NAGios server IP address

Allowed_hosts = 127.0.0.1, : : 1 = = = > modify for allowed_hosts = 127.0.0.1, : : 1172.16. 0.18Copy the code

Comment out the following lines

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -r -w .15,.10,.05 -c .30,.25,.20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
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
Copy the code

Add the following lines to the end of the nrpe. CFG file

# my custom monitor items
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -r -w .15,.10,.05 -c .30,.25,.20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_mem]=/usr/local/nagios/libexec/check_mem.pl -w 90% -c 95%
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
Copy the code

Create a Perl script that monitors memory

[root@client1 etc]# vi /usr/local/nagios/libexec/check_mem.pl
Copy the code

Add the following

#! /usr/bin/perl -w
#
# $Id: check_mem.pl 8 2008-08-23 08:59:52Z rhomann $
#
# check_mem v1.7 plugin for nagios
#
# uses the output of `free` to find the percentage of memory used
#
# Copyright Notice: GPL
#
# History:
# v1.8 Rouven Homann - [email protected]
# + added findbin patch from Duane Toler
# + added backward compatibility patch from Timour Ezeev
#
# v1.7 Ingo Lantschner - ingo AT boxbe DOT com
# + adapted for systems with no swap (avoiding divison through 0)
#
# v1.6 Cedric Temple - cedric DOT temple AT cedrictemple DOT info
# + add swap monitoring
# + if warning and critical threshold are 0, exit with OK
# + add a directive to exclude/include buffers
#
# v1.5 Rouven Homann - [email protected]
# + perfomance tweak with free -mt (just one sub process started instead of 7)
# + more code cleanup
#
# v1.4 Garrett Honeycutt - [email protected]
# + Fixed PerfData output to adhere to standards and show crit/warn values
#
# v1.3 Rouven Homann - [email protected]
# + Memory installed, used and free displayed in verbose mode
# + Bit Code Cleanup
#
# v1.2 Rouven Homann - [email protected]
# + Bug fixed where verbose output was required (nrpe2)
# + Bug fixed where perfomance data was not displayed at verbose output
# + FindBin Module used for the nagios plugin path of the utils.pm
#
# v1.1 Rouven Homann - [email protected]
# + Status Support (-c, -w)
# + Syntax Help Informations (-h)
# + Version Informations Output (-V)
# + Verbose Output (-v)
# + Better Error Code Output (as described in plugin guideline)
#
# v1.0 Garrett Honeycutt - [email protected]
# + Initial Release
#
use strict;
use FindBin;
FindBin::again();
use lib $FindBin::Bin;
use utils qw($TIMEOUT %ERRORS &print_revision &support);
use vars qw($PROGNAME $PROGVER);
use Getopt::Long;
use vars qw($opt_V $opt_h $verbose $opt_w $opt_c);

$PROGNAME = "check_mem";
$PROGVER = "1.8";

# add a directive to exclude buffers:
my $DONT_INCLUDE_BUFFERS = 0;

sub print_help ();
sub print_usage ();

Getopt::Long::Configure('bundling');
GetOptions ("V"= > \$opt_V."version"= > \$opt_V."h"= > \$opt_h."help"= > \$opt_h."v"= > \$verbose."verbose"= > \$verbose."w=s"= > \$opt_w."warning=s"= > \$opt_w."c=s"= > \$opt_c."critical=s"= > \$opt_c);

if ($opt_V) {
  print_revision($PROGNAME.'$Revision: '.$PROGVER.'$');
  exit $ERRORS{'UNKNOWN'};
}

if ($opt_h) {
  print_help();
  exit $ERRORS{'UNKNOWN'};
}

print_usage() unless (($opt_c) && ($opt_w));

my ($mem_critical.$swap_critical);
my ($mem_warning.$swap_warning);
($mem_critical.$swap_critical) = (The $1.$2) if ($opt_c= ~ ([0-9] +) / [%]? (? : ([0-9] +) [%]?) ? /); ($mem_warning.$swap_warning)   = (The $1.$2) if ($opt_w= ~ ([0-9] +) / [%]? (? : ([0-9] +) [%]?) ? /);# Check if swap params were supplied
$swap_critical| | = 100;$swap_warning| | = 100;# print threshold in output message
my $mem_threshold_output = "(";
my $swap_threshold_output = "(";

if ( $mem_warning > 0 && $mem_critical > 0) {
  $mem_threshold_output. ="W> $mem_warning, C> $mem_critical";
}
elsif ( $mem_warning> 0) {$mem_threshold_output. ="W> $mem_warning";
}
elsif ( $mem_critical> 0) {$mem_threshold_output. ="C> $mem_critical";
}

if ( $swap_warning > 0 && $swap_critical > 0) {
  $swap_threshold_output. ="W> $swap_warning, C> $swap_critical";
}
elsif ( $swap_warning> 0) {$swap_threshold_output. ="W> $swap_warning";
}
elsif ( $swap_critical> 0) {$swap_threshold_output. ="C> $swap_critical";
}

$mem_threshold_output. =")";
$swap_threshold_output. =")";

my $verbose = $verbose;

my ($mem_percent.$mem_total.$mem_used.$swap_percent.$swap_total.$swap_used) = &sys_stats();
my $free_mem = $mem_total - $mem_used;
my $free_swap = $swap_total - $swap_used;

# set output message
my $output = "Memory Usage".$mem_threshold_output.":". $mem_percent.'% <br>';
$output. ="Swap Usage".$swap_threshold_output.":". $swap_percent.The '%';

# set verbose output message
my $verbose_output = "Memory Usage:".$mem_threshold_output.":". $mem_percent.The '%'."- Total: $mem_total MB, used: $mem_used MB, free: $free_mem MB<br>";
$verbose_output. ="Swap Usage:".$swap_threshold_output.":". $swap_percent.The '%'."- Total: $swap_total MB, used: $swap_used MB, free: $free_swap MB<br>";

# set perfdata message
my $perfdata_output = "MemUsed=$mem_percent\ %;$mem_warning;$mem_critical";
$perfdata_output. =" SwapUsed=$swap_percent\ %;$swap_warning;$swap_critical";


# if threshold are 0, exit with OK
if ( $mem_warning == 0 ) { $mem_warning= 101};if ( $swap_warning == 0 ) { $swap_warning= 101};if ( $mem_critical == 0 ) { $mem_critical= 101};if ( $swap_critical == 0 ) { $swap_critical= 101};if ($mem_percent>$mem_critical || $swap_percent>$swap_critical) {
    if ($verbose) { print "<b>CRITICAL: ".$verbose_output."</b>|".$perfdata_output."\n"; }else { print "<b>CRITICAL: ".$output."</b>|".$perfdata_output."\n"; }exit $ERRORS{'CRITICAL'};
} elsif ($mem_percent>$mem_warning || $swap_percent>$swap_warning) {
    if ($verbose) { print "<b>WARNING: ".$verbose_output."</b>|".$perfdata_output."\n"; }else { print "<b>WARNING: ".$output."</b>|".$perfdata_output."\n"; }exit $ERRORS{'WARNING'};
} else {
    if ($verbose) { print "OK: ".$verbose_output."|".$perfdata_output."\n"; }else { print "OK: ".$output."|".$perfdata_output."\n"; }exit $ERRORS{'OK'};
}

sub sys_stats {
    my @memory = split("", `free -mt`);
    my $mem_total = $memory[7];
    my $mem_used;
    if ( $DONT_INCLUDE_BUFFERS) { $mem_used = $memory[15]; }
    else { $mem_used = $memory[8]. } my$swap_total = $memory[18];
    my $swap_used = $memory[19];
    my $mem_percent = ($mem_used / $mem_total) * 100;
    my $swap_percent;
    if ($swap_total= = 0) {$swap_percent = 0;
    } else {
  $swap_percent = ($swap_used / $swap_total) * 100;
    }
    return (sprintf("%.0f".$mem_percent),$mem_total.$mem_used, sprintf("%.0f".$swap_percent),$swap_total.$swap_used);
}

sub print_usage () {
    print "Usage: $PROGNAME -w <warn> -c <crit> [-v] [-h]\n";
    exit $ERRORS{'UNKNOWN'} unless ($opt_h);
}

sub print_help () {
    print_revision($PROGNAME.'$Revision: '.$PROGVER.'$');
    print "Copyright (c) 2005 Garrett Honeycutt/Rouven Homann/Cedric Temple\n";
    print "\n";
    print_usage();
    print "\n";
    print "-w 
      
       ,
       
         = Memory and Swap usage to activate a warning message (eg: -w 90,25).\n"
       
      ;
    print "-c 
      
       ,
       
         = Memory and Swap usage to activate a critical message (eg: -c 95,50).\n"
       
      ;
    print "-v = Verbose Output.\n";
    print "-h = This screen.\n\n";
    support();
}
Copy the code

Add execution permission to a script

[root@client1 etc]# chmod 755 /usr/local/nagios/libexec/check_mem.pl
Copy the code

Restart the NRPE service

Method a #
[root@client1 etc]# killall nrpe               
[root@client1 etc]# /usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg
Method # 2
[root@client1 etc]# kill -HUP `ps -ef|grep nrpe|awk 'NR==1{print $2}'`
Copy the code

Execute two commands on the machine to see the effect

[root@client1 etc]# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_mem<b>CRITICAL: Memory Usage (W> 10, C> 3): 29% <br>Swap Usage (W> 100, C> 100): 12%</b>|MemUsed=29%; 10; 3 SwapUsed=12%; 100; 100 [root@client1 etc]# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_diskDISK ok-free space: / 4201 MB (24.15% inode=97%); | /=13192MB; 13915; 15654; 0; 17394Copy the code


Because nagios grants full permissions to nagiosadmin by default, you can change the file to /usr/local/nagios/etc to grant nagios permissions

[root @ nagios nrpe - 3.1.0]# cd /usr/local/nagios/etc
[root@nagios etc]# llTotal usage 144-rw-rw-r -- 1 nagios nagios 12999 4月 21 17:00 cgi. cfg-rw-r --r-- 1 root root 45 4月 24 09:28 htpasswd.users -rw-rw-r-- 1 nagios nagios 44831 April 21 17:00 nagios. CFG -rw-r--r-- 1 root root 10765 April 24 12:32 nrpe. CFG drwxrwxr-x 2 Nagios nagios 336 4月 21 17:00 objects-rw-rw ---- 1 nagios nagios 1312 4月 21 17:00 resource. CFG [root@nagios etc]# grep nagiosadmin cgi.cfg
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
[root@nagios etc]# sed -i 's/nagiosadmin/nagiosadmin,nagios/g' cgi.cfg
[root@nagios etc]# grep nagiosadmin cgi.cfg
authorized_for_system_information=nagiosadmin,nagios
authorized_for_configuration_information=nagiosadmin,nagios
authorized_for_system_commands=nagiosadmin,nagios
authorized_for_all_services=nagiosadmin,nagios
authorized_for_all_hosts=nagiosadmin,nagios
authorized_for_all_service_commands=nagiosadmin,nagios
authorized_for_all_host_commands=nagiosadmin,nagios
Copy the code

Modify nagios. CFG (customize some configurations)

[root@nagios etc]# vi nagios.cfg +34
# Comment out the following line
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
# Add the following two lines
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
Copy the code

CFG and services. CFG files are created

[root@nagios etc]# cd objects/
[root@nagios objects]# pwd
/usr/local/nagios/etc/objects
[root@nagios objects]# touch services.cfg
[root@nagios objects]# head -51 localhost.cfg > hosts.cfg
[root@nagios objects]# chown -R nagios.nagios *
Copy the code

Modify Nagios check syntax script

[root@nagios objects]# vim /etc/init.d/nagios +181
#check_config
$NagiosBin -v $NagiosCfgFile;
Copy the code

Vi commands.cfg enter and press Shift + G to cut to the end to add the following.

# 'check_nrpe' command definition
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$}# 'check_ping' command definition
define command{
        command_name    check-ping
        command_line    $USER1$/check_ping -H $HOSTADDRESS$-w 100.0,20% -c 200.0,50% -p 3 -t 2} $-w 100.0,20% -c 200.0,50% -p 3 -t 2}# 'check_http' command definition
define command{
        command_name    check-weburl
        command_line    $USER1$/check_http -H $HOSTADDRESS$ $ARG1$ -w 5 -c 10
        }

# 'check_tcp' command definition
define command{
        command_name    check-tcp
        command_line    $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$-w 0.02 -c 0.1}Copy the code

Check the CFG files

[root@nagios objects]# pwd
/usr/local/nagios/etc/objects
[root@nagios objects]# llCFG -rw-rw-r-- 1 nagios nagios 7860 4月 24 16:53 commands. CFG -rw-rw-r-- 1 nagios nagios 2138 4月 21 17:00 Contacts.cfg-rw-r --r-- 1 nagios nagios 1843 April 24 16:46 hosts. Cfg-rw-rw-r -- 1 nagios nagios 5379 April 21 17:00 Cfg-rw-rw-r -- 1 nagios nagios 3070 4月 21 17:00 printer. Cfg-rw-r --r-- 1 nagios nagios 0 4月 24 16:46 Services. Cfg-rw-rw-r -- 1 nagios nagios 3252 4月 21 17:00 switch. Cfg-rw-rw-r -- 1 nagios nagios 10595 4月 21 17:00 Cfg-rw-rw-r -- 1 timeperiods. Cfg-rw-rw-r -- 1 nagios nagios 3991 4月 21 17:00 windows.cfgCopy the code

Introduction to Common Objects

  • Who should I report if there is a problem with contact? Generally, of course, is the system administrator
  • Monitoring period timeperiod 7X24 hours continuous from Monday to Friday, or a user-defined timeperiod
  • Monitored host Host Specifies the server to be monitored
  • Monitor command Which command nagios issues to perform a monitor is also self-defined
  • Service To be monitored, such as whether the host is alive, whether port 80 is enabled, disk usage, and user-defined services

Contacts. CFG file introduction

  • Service_notification_period 24×7 The period for which the service is notified of its condition, as defined above in timeperiods.
  • Host_notification_period 24×7 The period for which a host is notified of its condition, as defined above in timeperiods
  • Service_notification_options W,u, C,r Notifies the contact when a service has w – warning, U – unknown, C – critical, or r – recovery from an exception.
  • Host_notification_options D,u,r Notifies the contact when the host is d – Down,u – unreachable, and r – Recovered from an abnormal condition
  • Service_notification_commands notify-service-by-email Notifies the notify-by-email command when the service is faulty. This command is defined in commands. CFG and is used to send emails to contacts. Commands.cfg will be covered later
  • Host_notification_commands host-notify-by-email notify-host –by-email Similarly, when a host is faulty, it notifies the contact by email
  • Pager 1338757XXXX contact phone, this is useful if SMS notification is supported.
  • Alias is the alias of a contact, and address is the address.

Contactgroups. CFG file

Copy the code

Define contactgroup{contactgroup_name group name // contactgroup name alias alias // alias members user name // group member from the contacts.cfg defined above. If there are multiple contacts, separate them with commas }

Host template introduction (hosts.cfg) > ' '# host Define Host {host_name Host name // The name of the monitored host, preferably without space nagios-serveraliasAlias address IP // IP address of the monitored host check_command check-host-alive // Monitoring command check-host-alive. This command is from commands. CFG and is used to check whether the host is alive Max_check_attempts 5 // Number of retries after a check failure check_period 24x7 // Check period 24x7, also from the contact_groups group name defined in timeperiods // Notification_interval 10 Notification_period notification_period 24x7 // Notification_period 24x7 // Notification_period 24x7 // 24x7, also from the notification_options we defined earlier in timeperiods. CFG,u,r // specifies what notification_options should be, as described earlier in the contacts.cfg section}Copy the code

Host Group template (hosts.cfg)

Copy the code

Define hostgroup{hostgroup_name hostgroup name alias alias members host name // member hosts in a group. Multiple hosts are separated by commas (,) and must be defined in hosts.cfg.

Service template description (services.cfg) > ' '# service definitionDefine Service {host_name Host name // The monitored host,hosts. CFG defines service_description check-host-alive Check_command check-host-alive // Commands.cfg specifies the command used to check whether the host is alive Max_check_attempts 5 normal_check_interval 3 retry_check_interval 2 check_period 24x7 // The period monitored, which is defined in timeperiods. CFG Notification_interval 10 Notification_period 24x7 // Notification_period, CFG notification_options w,u,c,r // Notify the contact when the result of monitoring is wUCR. Contact_groups Group name // contactgroups, as defined in contactgroups.cfg}Copy the code

Host Template Configuration

[root@nagios objects]# vi hosts.cfg +21Delete the following 11 lines and add the following# Define some hosts

# # # # # # # # # # # 172.16.0.18 # # # # # # # # # # # # # # # # # #

define host {
        use                      linux-server
        host_name                nagios
        aliasNagios address 172.16.0.18 check_command check-host-alive max_check_attempts 3 normal_check_interval 2 retry_check_interval 2 check_period 24x7 notification_interval 300 notification_period 24x7 notification_options d,u,r contact_groups admins process_perf_data 1 }# # # # # # # # # # # 172.16.0.18 # # # # # # # # # # # # # # # # # #

define host {
        use                      linux-server
        host_name                client1
        aliasClient1 address 172.16.0.20 check_command check-host-alive max_check_attempts 3 normal_check_interval 2 retry_check_interval 2 check_period 24x7 notification_interval 300 notification_period 24x7 notification_options d,u,r Contact_groups admins process_perf_data 1} Add the monitored host to the host group [root@nagios objects]# vi hosts.cfg +76
define hostgroup{
        hostgroup_name  linux-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         nagios,client1     ; Comma separated list of hosts that belong to this group
        }
Copy the code

Service Template Configuration

[root@nagios objects]# pwd
/usr/local/nagios/etc/objects
[root@nagios objects]# vi services.cfg Add the following# # # # # # # # # # # 172.16.0.18 # # # # # # # # # # # # # # # # # #define service{ use generic-service host_name nagios service_description Load check_command check_nrpe! check_load# check_nrpe here are not the server/usr/local/nagios/libexec/check_nrpe, but command. Defined in the CFG command} define service{ use generic-service host_name nagios service_description Disk check_command check_nrpe! check_disk } define service{ use generic-service host_name nagios service_description memory check_command check_nrpe! check_mem } define service{ use generic-service host_name nagios service_description Ping check_command check-ping! 172.16.0.18} define service{use generic-service host_name nagios service_description port_3306 check_command check-tcp! 3306}# # # # # # # # # # # 172.16.0.20 # # # # # # # # # # # # # # # # # #define service{ use generic-service host_name client1 service_description Load check_command check_nrpe! check_load } define service{ use generic-service host_name client1 service_description Disk check_command check_nrpe! check_disk } define service{ use generic-service host_name client1 service_description memory check_command check_nrpe! check_mem } define service{ use generic-service host_name client1 service_description Ping check_command check-ping! 172.16.0.20} define service{use generic-service host_name client1 service_description port_3306 check_command check-tcp! 3306}Copy the code

Restart the Nagios service

[root@nagios objects]# /etc/init.d/nagios restart
Copy the code

Open a browser

Ok, that’s the end of our configuration.

Download the pNp4Nagios source package in the figure section

[root@nagios objects]# cd /software/
[root@nagios software]Wget # https://jaist.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.25.tar.gz
Copy the code

Installing dependency packages

[root@nagios software]# yum install cairo pango perl-rrdtool rrdtool librrds-perl zlib zlib-devel freetype freetype-devel gd gd-devel -y
Copy the code

Unzip the pnp4Nagios source package

[root@nagios software]# tar ZXF pnp4nagios - 0.6.25. Tar. Gz
Copy the code

Go to the decompressed directory and configure PNG

[root @ nagios pnp4nagios - 0.6.25]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
Copy the code

Compilation and installation

[root @ nagios pnp4nagios - 0.6.25]# make all[root @ nagios pnp4nagios - 0.6.25]# make install[root @ nagios pnp4nagios - 0.6.25]# make install-webconf[root @ nagios pnp4nagios - 0.6.25]# make install-config[root @ nagios pnp4nagios - 0.6.25]# make install-init[root @ nagios pnp4nagios - 0.6.25]# cd sample-config/
[root@nagios sample-config]# make install-webconf
Copy the code

Configuration pnp4nagios

[root@nagios sample-config]# cd /usr/local/pnp4nagios/etc/
[root@nagios etc]# mv misccommands.cfg-sample misccommands.cfg
[root@nagios etc]# mv rra.cfg-sample rra.cfg
[root@nagios etc]# mv nagios.cfg-sample nagios.cfg
[root@nagios etc]# cd pages/
[root@nagios pages]# mv web_traffic.cfg-sample web_traffic.cfg
[root@nagios pages]#  cd ../check_commands/
[root@nagios check_commands]# mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
[root@nagios check_commands]# mv check_nrpe.cfg-sample check_nrpe.cfg
[root@nagios check_commands]# mv check_nwstat.cfg-sample check_nwstat.cfg
[root@nagios check_commands]# systemctl enable npcd
[root@nagios check_commands]# systemctl start npcd
Copy the code

Configure the Nagios data output interface (run in BULK mode). For details, see docs.pnp4nagios.org/pnp-0.6/con… :

[root@nagios check_commands]# vi /usr/local/nagios/etc/nagios.cfg
process_performance_data=1 Change the default value to 1Add the following to the file#

# service performance data

#

service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata

service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$

service_perfdata_file_mode=a

service_perfdata_file_processing_interval=15

service_perfdata_file_processing_command=process-service-perfdata-file

#

# host performance data starting with Nagios 

#

host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata

host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$

host_perfdata_file_mode=a

host_perfdata_file_processing_interval=15

host_perfdata_file_processing_command=process-host-perfdata-file
Copy the code

The configuration command. CFG

[root@nagios check_commands]# vi /usr/local/nagios/etc/objects/commands.cfgAdd the following content define to the filecommand{
      command_name    process-service-perfdata-file
      command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/service-perfdata

}

define command{
      command_name    process-host-perfdata-file
      command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/host-perfdata

}
Copy the code

Add a chart icon template to the template configuration file:

[root@nagios check_commands]# vi /usr/local/nagios/etc/objects/templates.cfgIn the file to add the following define the host {name host - PNP action_url/pnp4nagios/index. The PHP/graph? host=$HOSTNAME$&srv=_HOST_ register 0 } define service { name service-pnp action_url /pnp4nagios/index.php/graph? host=$HOSTNAME$&srv=$SERVICEDESC$
  register  0

}
Copy the code

Invoke the chart template in monitor hosts and services (add a new template after hosts and services) :

[root@nagios check_commands]# vi /usr/local/nagios/etc/objects/hosts.cfg The host information is modified as follows# # # # # # # # # # # 172.16.0.18 # # # # # # # # # # # # # # # # # #

define host {
        use                      linux-server,host-pnp
        host_name                nagios
        aliasNagios address 172.16.0.18 check_command check-host-alive max_check_attempts 3 normal_check_interval 2 retry_check_interval 2 check_period 24x7 notification_interval 300 notification_period 24x7 notification_options d,u,r contact_groups admins process_perf_data 1 }# # # # # # # # # # # 172.16.0.18 # # # # # # # # # # # # # # # # # #

define host {
        use                      linux-server,host-pnp
        host_name                client1
        aliasClient1 address 172.16.0.20 check_command check-host-alive max_check_attempts 3 normal_check_interval 2 retry_check_interval 2 check_period 24x7 notification_interval 300 notification_period 24x7 notification_options d,u,r contact_groups admins process_perf_data 1 } [root@nagios check_commands]# vi /usr/local/nagios/etc/objects/services.cfg The service content is modified as follows# # # # # # # # # # # 172.16.0.18 # # # # # # # # # # # # # # # # # #define service{ use generic-service,service-pnp host_name nagios service_description Load check_command check_nrpe! check_load# check_nrpe here are not the server/usr/local/nagios/libexec/check_nrpe, but command. Defined in the CFG command} define service{ use generic-service,service-pnp host_name nagios service_description Disk check_command check_nrpe! check_disk } define service{ use generic-service,service-pnp host_name nagios service_description memory check_command check_nrpe! check_mem } define service{ use generic-service,service-pnp host_name nagios service_description Ping check_command check-ping! 172.16.0.18} define service{use generic-service,service-pnp host_name nagios service_description port_3306 check_command check-tcp! 3306}# # # # # # # # # # # 172.16.0.20 # # # # # # # # # # # # # # # # # #define service{ use generic-service,service-pnp host_name client1 service_description Load check_command check_nrpe! check_load } define service{ use generic-service,service-pnp host_name client1 service_description Disk check_command check_nrpe! check_disk } define service{ use generic-service,service-pnp host_name client1 service_description memory check_command check_nrpe! check_mem } define service{ use generic-service,service-pnp host_name client1 service_description Ping check_command check-ping! 172.16.0.20} define service{use generics-service,service-pnp host_name client1 service_description port_3306 check_command check-tcp! 3306}Copy the code

The diagram shows restarting Nagios and Apache

[root@nagios check_commands]# /etc/init.d/nagios checkconfig 
[root@nagios check_commands]# /etc/init.d/nagios restart
[root@nagios check_commands]# systemctl restart httpd
Copy the code

Visit the Nagios interface to see the diagram icon:

Click the icon to display the pNP4Nagios test page:

[root@nagios ~]# rm -rf /usr/local/pnp4nagios/share/install.php
Copy the code

Clicking the icon again will show the current monitoring service chart generated by pNP4Nagios

Mail alarm configuration

Check whether the Sendmail mail system is installed

[root@nagios ~]# rpm -qa|grep sendmail
Copy the code

If not, yum can install it

[root@nagios ~]# yum -y install sendmail
Copy the code

To start the sendmail

[root@nagios ~]# systemctl enable sendmail
[root@nagios ~]# systemctl start sendmail
Copy the code

Test sending email:

[root@nagios ~]# echo "test" | mail [email protected]
Copy the code

When sending external mail, the sender and sender address in this local form can easily be mistaken for spam and rejected. Here we define mail to send SMTP messages. First, install Mailx12.5

Wget http://fossies.org/linux/misc/old/mailx-12.5.tar.gz tar ZXF mailx 12.5. Tar. GzcdMailx-12.5 make make install UCBINSTALL=/usr/bin/install mv /bin/mail/bin/mail_old ln-s /usr/local/bin/mailx /bin/mail
mail -V
Copy the code

Next configure the external SMTP sender information

Vi /etc/nail.rc add the following contents:set bsdcompat
set [email protected]
set smtp=smtp.yasn.com.cn
set [email protected]
set smtp-auth-password=123456
set smtp-auth=login
Copy the code

Test Email sending

echo 'mail content'|mail -s test [email protected]
Copy the code

Send a message test, you can see that the sender is the external message sender we set

Edit contacts.cfg to define mail contacts and groups

[root@nagios ~]# cd /usr/local/nagios/etc/objects/
[root@nagios objects]# ls
commands.cfg  localhost.cfg~  services.cfg  templates.cfg    hosts.cfg    printer.cfg     
switch.cfg   windows.cfg contacts.cfg   localhost.cfg  timeperiods.cfg  
[root@nagios objects]# vi contacts.cfg //
define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user

        #email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        email                           [email protected],[email protected]
        }


define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin
        }
Copy the code

Edit commands. CFG file to define mail sending commands

[root@nagios objects]CFG // Check to see if the following content exists, add if it does not
# 'notify-host-by-email' command definition
define command{ &emsp; &emsp; command_name notify-host-by-email &emsp; &emsp; command_line /usr/bin/printf "%b" "***** Nagios ***** Notification Type: $NOTIFICATIONTYPE$ Host: $HOSTNAME$ State: $HOSTSTATE$ Address: $HOSTADDRESS$ Info: $HOSTOUTPUT$ Date/Time: $LONGDATETIME$" | /bin/mail -s "* *$NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ &emsp; &emsp; }# 'notify-service-by-email' command definition
define command{ &emsp; &emsp; command_name notify-service-by-email &emsp; &emsp; command_line /usr/bin/printf "%b" "***** Nagios ***** Notification Type: $NOTIFICATIONTYPE$ Service: $SERVICEDESC$ Host: $HOSTALIAS$ Address: $HOSTADDRESS$ State: $SERVICESTATE$ Date/Time: $LONGDATETIME$ Additional Info: $SERVICEOUTPUT$" | /bin/mail -s "* *$NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ &emsp; &emsp; }Copy the code

Modify the monitoring threshold, simulate the alarm.

[root@nagios ~]# systemctl restart nagios
[root@nagios ~]# systemctl stop sendmail
[root@nagios ~]# ps -ef|grep sendmail
[root@nagios ~]# systemctl start sendmail
[root@nagios ~]# ps -ef|grep sendmail
Copy the code

Check the alarm email for a few pictures:

Here is the email after the alarm was recovered:

Ok, we’re done.

Common mail sending error:

Error 1

[root@nagios objects]# cat /etc/hosts
172.16.0.18 nagios nagios.com 
Copy the code







cd /etc/httpd/ ll /etc/httpd/modules/libphp7.so systemctl start httpd systemctl enable httpd chkconfig nagios on /etc/init.d/nagios start CD /software/ tar ZXVF nagios-plugins-2.2.1.tar.gz CD nagios-plugins-2.2.1/./configure –with-nagios-user=nagios –with-nagios-group=nagcmd –enable-perl-modules make && make install

CD /software/ tar ZXVF nrpe-3.2.0.tar. gz CD nrpe-3.1.0/./configure make all make install-plugin make install-daemon make install-daemon-config cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg ls /usr/local/nagios/libexec/ /usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg echo “/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg” >> /etc/rc.local chmod +x /etc/rc.d/rc.local netstat -lnput|grep 5666 /usr/local/nagios/libexec/check_nrpe -H localhost

#######################nagios-client-install########################### mkdir /software/

The mv nagios plugins – 2.2.1. Tar. Gz nrpe – 3.1.0. Tar. Gz/software /

CD/software/wget nagios-plugins.org/download/na… Wget sourceforge.net/projects/na… Yum install perl-devel perl-cpan -y useradd nagios-m -s /sbin/nologin tar ZXVF nagios-plugins-2.2.1.tar.gz CD Nagios-plugins-2.2.1 /./configure –with-nagios-user=nagios –with-nagios-group=nagios –enable-perl-modules make && make install sleep 1 cd .. Tar ZXVF nrpe-3.2.0.tar. gz CD nrpe-3.1.0/./configure make all make install-plugin make install-daemon make install-daemon-config mkdir /usr/local/nagios/etc/ cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg ls /usr/local/nagios/libexec/ /usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg echo “/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg” >> /etc/rc.local chmod +x /etc/rc.d/rc.local netstat 5666 sed – lnput | grep -i ‘s/allowed_hosts = 127.0.0.1, : : 1 / allowed_hosts = 127.0.0.1, : : 1172.16. 0.1 / g’ /usr/local/nagios/etc/nrpe.cfg sed -i ‘s/^command[check/#command[check/g’ /usr/local/nagios/etc/nrpe.cfg cat >> /usr/local/nagios/etc/nrpe.cfg << EOF

my custom monitor items

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10 command[check_load]=/usr/local/nagios/libexec/check_load -r -w .15,.10,.05 -c .30,.25,.20 command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p / command[check_mem]=/usr/local/nagios/libexec/check_mem.pl -w 90% -c 95% command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10% EOF /usr/local/nagios/libexec/check_nrpe -H localhost -c check_disk

** Summary: ** Check nagios logs and mail logs to troubleshoot errors.Copy the code