Nagios monitoring server of three swordsmen

Blog directory

1, Nagios

1. Nagios introduction

2. Main functions of Nagios

3. The role of Nagios

4. Nagios common monitoring status

5. The principle of Nagios

2, Install LAMP environment

3, Install Nagios

1. Install Nagios components

2. Configure Apache to support Nagios

3. Configure SendMail messages

4, Nagios monitoring Linux client

1. Install dependencies

2. Install Nagios plugins plug-in

3. Installing the NRPE plug-in

1, Nagios

1. Nagios introduction

Nagios is an open-source free network monitoring tool, which can effectively monitor the host status of Windows, Linux and Unix, switch router and other network devices, printers, etc. When the system or service status is abnormal, send an email or SMS alarm to inform the website operation and maintenance personnel at the first time, and send a normal email or SMS notification after the status recovers.

2. Main functions of Nagios

Network service monitoring (SMTP, POP3, HTTP, NNTP, ICMP, SNMP, FTP, SSH);

Host resource monitoring (CPU load, disk usage, system logs), including Windows host (using NSClient++ plugin);

You can specify your own Plugin to collect data through the network to monitor any situation (temperature, warning...) ;

The Nagios remote execution plug-in can be configured to execute scripts remotely;

Remote monitoring supports SSH or SSL plus channel mode for monitoring;

The simple plugin design allows users to easily develop the inspection services they need, and supports many development languages (shell scripts, C + +, Perl, ruby, Python, PHP, C ා);

Including many graphical data Plugins (Nagiosgraph, Nagiosgrapher, PNP4Nagios, etc.);

Parallel service check is available;

It can define the level of network host and allow level by level checking, that is, starting from the parent host and checking down;

When there is a problem with the service or the host, the notification can be sent by email, pager, sms or any user-defined plugin >
To give notice;

Can customize the event handling mechanism to reactivate the service or host in question;

Automatic log cycle;

Support redundant monitoring;

Including Web interface to view current network status, notifications, problem history, log files, etc.

3. The role of Nagios

Monitor computer hardware; monitor network; support email or SMS to send alarm.

4. Nagios common monitoring status

OK status: the display color of normal operation status is green, and the monitoring level is 0;

WARNING: WARNING status, monitoring status color is yellow, monitoring level is 1;

CRITICL: in case of failure or serious problem, the monitoring status color is red, and the monitoring level is 2;

UNKNOWN: UNKNOWN error, dark yellow monitoring status color, monitoring level 3;

5. Principles of Nagios

1) Nagiosz dependent components

LAMP environment;
nrpe component remote management use;

2) Nagios principle

Nagios performs check_nrpe plug-in informs or detects the service or process of the computer;
Save the collected process status to the message queue;
Display to users through Nagios graphical management interface;

2, Install LAMP environment

For software packages and images used in this environment, please visit: https://pan.baidu.com/s/1Q0WoV7bBUYUB8F_JMtDaOw
Extraction code: b0ah

[root@centos01 ~]# Yum - y install httpd PHP MariaDB MariaDB server PHP MySQL OpenSSL devel <! -- install LAMP dependency program -- >
[root@centos01 ~]# vim /var/www/html/ index.php    <! -- create PHP test page -- >
<?php
phpinfo();
?>
[root@centos01 ~]# Systemctl start httpd <! -- start Apache -- >
[root@centos01 ~]# Systemctl enable httpd <! -- start up automatically -- >
[root@centos01 ~]# Systemctl start MariaDB <! -- start MariaDB -- >
[root@centos01 ~]# Systemctl enable MariaDB <! -- start up automatically -- >
[root@centos01 ~]# Useradd - M - S / SBIN / nologin Nagios <! -- create management Nagios user -- >
<!--(switch Linux CD)-->
[root@centos01 ~]# tar zxvf /mnt/nagios-4.0.1. tar.gz  -C / usr / SRC / <! -- decompress Nagios package -- >
[root@centos01 ~]# CD / usr / SRC / nagios-4.0.1 / <! -- enter Nagios directory -- >
[root@centos01 nagios-4.0.1]# . / configure -- prefix = / usr / local / Nagios -- with Nagios user = Nagios -- with Nagios group = Nagios <! - configure Nagios --- >
[root@centos01 nagios-4.0.1]# make all && make install && make install-init   
           <!--Build install Nagios-->
[root@centos01 nagios-4.0.1]# make install-commandmode && make install-config  
             <!--Build install Nagios-->
[root@centos01 ~]# chown -R  nagios:nagios /usr/local/nagios    <! -- set the owner of the directory -- >
[root@centos01 ~]# Chkconfig -- add Nagios <! -- add system service -- >
[root@centos01 ~]# Chkconfig -- level 35 Nagios on <! -- set power on auto start -- >

Client access to php page

3, Install Nagios

1. Install Nagios components

[root@centos01 ~]# tar zxvf /mnt/nagios-plugins-1.5.tar.gz -C /usr/src/  
          <!--decompression  nagios-plugins Component compression package-->
[root@centos01 ~]# CD / usr / SRC / Nagios plugins-1.5 / <! -- enter Nagios plugins component directory -- >
[root@centos01 nagios-plugins-1.5]# ./configure --prefix=/usr/local/nagios   
                <!--to configure nagios-plugins assembly-->
[root@centos01 nagios-plugins-1.5]# Make & & make install <! -- compile and install Nagios plugins components -- >
[root@centos01 ~]# tar zxvf /mnt/nrpe-2.15. tar.gz  -C / usr / SRC / <! -- decompress nrpe package -- >
[root@centos01 ~]# CD / usr / SRC / nrpe-2.15 / <! -- enter the nrpe directory -- >
[root@centos01 nrpe-2.15]# ./configure && make all && make install-plugin  
         <!--Configure build install nrpe assembly-->

2. Configure Apache to support Nagios

[root@centos01 ~]# vim /etc/httpd/conf/ httpd.conf         <! -- edit Apache main configuration file -- >
354 ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
355 
356 <Directory "/usr/local/nagios/sbin">
357     Options ExecCGI
358     AllowOverride None
359     Order allow,deny
360     Allow from all
361     AuthName "Nagios Access"
362     AuthType Basic
363     AuthUserFile "/usr/local/nagios/etc/htpasswd.users"
364     Require valid-user
365 </Directory>
366 
367 Alias /nagios "/usr/local/nagios/share"
368 
369 <Directory "/usr/local/nagios/share">
370     Options None
371     AllowOverride None
372     Order allow,deny
373     Allow from all
374     AuthName "Nagios Access"
375     AuthType Basic
376     AuthUserFile "/usr/local/nagios/etc/htpasswd.users"
377     Require valid-user
378 </Directory>
[root@centos01 ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin  
    <!--Configure authentication with account nagiosadmin,Password is pwd@123-->
[root@centos01 ~]# Systemctl restart httpd <! -- restart Apache Service -- >

3. Configure SendMail messages

[root@centos01 ~]# tar zxvf /mnt/sendEmail-v1.55. tar.gz    <! -- unzip SendMail package -- >
[root@centos01 ~]# mv sendEmail-v1.55/sendEmail /usr/local/bin/   
      <!--shear SendMail reach/usr/local/bin/catalog-->
[root@centos01 ~]# vim /usr/local/nagios/etc/ nagios.cfg    <! -- add storage monitoring host profile -- >
  36 cfg_dir=/usr/local/nagios/etc/conf
[root@centos01 ~]# MKDIR / usr / local / Nagios / etc / conf / <! -- create storage monitoring host directory -- >
[root@centos01 ~]# vim /usr/local/nagios/etc/objects/ commands.cfg    <! -- define Nagios command -- >
239 define command{
240         command_name     notify-host-by-sendEmail
241         command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState    : $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -o fqdn=FQND     -f 2807489749@qq.com -t $CONTACTEMAIL$ -s smtp.qq.com -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -xu 8214    09986 -xp hehe
242 
243 }
244 define command{
245         command_name    notify-service-by-sendEmail
246         command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC    $\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOU    TPUT$\n" | /usr/local/bin/sendEmail -o fqdn=FQDN -f 821409986@qq.com -t $CONTACTEMAIL$ -s smtp.qq.com -u "** $NOTIFICATIONTYPE$ Se    rvice Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu 2807489749 -xp hehe
247 }
248 define command{
249         command_name     check_nrpe
250         command_line    $USER1$/check_nrpe  -H  $HOSTADDRESS$  -c  $ARG1$
251 }
[root@centos01 ~]# vim /usr/local/nagios/etc/objects/ contacts.cfg   <! -- define contact -- >
55 define contact{
 56         contact_name                            821409986
 57         alias                                   821409986
 58         service_notification_period             24x7
 59         host_notification_period                24x7
 60         service_notification_options            w,u,c,r
 61         host_notification_options               d,u,r
 62         service_notification_commands           notify-service-by-sendEmail
 63         host_notification_commands              notify-host-by-sendEmail
 64         email   821409986@qq.com
 65 }
 66 define contactgroup{
 67         contactgroup_name       821409986
 68         alias                   Nagios admin
 69         members                 821409986
 70 }
[root@centos01 ~]# vim /usr/local/nagios/etc/conf/ hostgroups.cfg    <! -- define monitoring host -- >
define hostgroup{
        hostgroup_name                  web-server
        alias                           web-server
        members                         192.168.100.20    <!--Monitored IP address-->
}

[root@centos01 ~]# VIM / usr / local / Nagios / etc / conf / 192.168.100.20. CFG <! - edit configuration file -- >
define host{
        host_name                       192.168.100.20
        alias                           web-server
        address                         192.168.100.20
        check_command                   check-host-alive
        max_check_attempts              5
        check_period                            24x7
        notification_period                     24x7
        notification_options            d,u,r
        contact_groups                  821409986
}

define service{
        host_name                       192.168.100.20
        service_description             check-host-alive
        check_command                   check-host-alive
        max_check_attempts              3
        normal_check_interval           2
        retry_check_interval            2
        check_period                            24x7
#       notification                    web-server_interval 10
        notification_period                     24x7
        notification_options            w,u,c,r
        contact_groups                  821409986
}

define service{
        host_name                       192.168.100.20
        service_description             check-procs
        check_command                   check_nrpe!check_total_procs
        max_check_attempts              3
        normal_check_interval           2
        retry_check_interval            2
        check_period                            24x7
        notification_interval           10
        notification_period                     24x7
        notification_options            w,u,c,r
        contact_groups                  821409986
}

define service{
        host_name                       192.168.100.20
        service_description             check-load
        check_command                   check_nrpe!check_load
        max_check_attempts              3
        normal_check_interval           2
        retry_check_interval            2
        check_period                            24x7
        notification_interval           10
        notification_period                     24x7
        notification_options            w,u,c,r
        contact_groups                  821409986
}
[root@centos01 ~]# Systemctl restart httpd <! -- restart Apache Service -- >
[root@centos01 ~]# Systemctl restart Nagios <! -- restart Nagios -- >

Client access to nagios WEB interface

4, Nagios monitoring Linux client

1. Install dependencies

[root@centos02 ~]# Yum - y install OpenSSL devel OpenSSL <! -- install dependencies -- >
[root@centos02 ~]# Useradd - M - S / SBIN / nologin nagios <! -- create management nagios user -- >

2. Install Nagios plugins plug-in

[root@centos02 ~]# scp root@192.168.100.10:/mnt/nagios-plugins-1.5.tar.gz /root/  
          <!--Remote replication plugins Plug in compression package-->
[root@centos02 ~]# tar zxvf nagios-plugins-1.5. tar.gz  -C / usr / SRC / <! -- extract plugins plug-in -- > 
[root@centos02 ~]# CD / usr / SRC / nagios-plugins-1.5 / <! -- enter the plugins plug-in directory -- >
[root@centos02 nagios-plugins-1.5]# . / configure -- prefix = / usr / local / Nagios -- with Nagios user = Nagios -- with Nagios group = Nagios <! -- compiling plugins plug-ins -- > 
[root@centos02 nagios-plugins-1.5]# Make & & make install <! -- compile and install Nagios plugins plug-in -- >

3. Installing the NRPE plug-in

[root@centos02 ~]# scp  root@192.168.100.10 :/mnt/nrpe-2.15. tar.gz  /Root <! -- remote replication package -- >
[root@centos02 ~]# tar zxvf nrpe-2.15. tar.gz  -C / usr / SRC / <! -- decompress nrpe package -- >
[root@centos02 ~]# CD / usr / SRC / nrpe-2.15 / <! -- enter the nrpe directory -- >
[root@centos02 nrpe-2.15]# . / configure -- prefix = / usr / local / Nagios -- with Nagios user = Nagios -- with Nagios group = Nagios <! -- configure nrpe plug-in -- >
[root@centos02 nrpe-2.15]# Make all & & make install plugin & & make install daemon & & make install daemon config <! -- compile install nrpe plugin -- >
[root@centos02 ~]# vim /usr/local/nagios/etc/ nrpe.cfg    <! -- modify nrpe configuration file -- >
81 allowed_hosts=127.0.0.1,192.168.100.10    <!--Nagios The server IP address-->

[root@centos02 ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d 

Client access to nagios WEB interface

————————Thank you for reading————————

Tags: Linux vim PHP network Apache

Posted on Wed, 03 Jun 2020 21:28:04 -0700 by hostseller