Linux Note Network monitoring Nagios installation and configuration

Source: Internet
Author: User
Tags install openssl disk usage

About Nagios

Nagios is an open source computer system and network monitoring tool that can effectively monitor Windows, Linux and UNIX host status, switch routers and other network settings, printers, etc. Send mail or SMS alarm when the system or service status is abnormal the first time to notify the site operators, after the status of the resumption of normal mail or SMS notification.
Nagios, formerly known as Netsaint, was developed and maintained by Ethan Galstad. Nagios is an abbreviated form: "Nagios Ain t gonna insist on sainthood" sainthood translated into saints, while "Agios" is the Greek representation of "saint". Nagios is developed for use under Linux, but it works very well under UNIX.

Main functions:

1. Network Service Monitoring (SMTP, POP3, HTTP, NNTP, ICMP, SNMP, FTP, SSH)
2. Host resource monitoring (CPU load, disk usage, system logs), and also Windows hosts (using nsclient++ plugin) can specify their own plugin to collect data over the network to monitor any situation (temperature, warning ...). ) can execute scripts remotely by configuring the Nagios remote execution plug-in
3. Remote monitoring supports SSH or SSL plus channel monitoring the simple plugin design allows users to easily develop their own inspection services, supporting many development languages (shell scripts, C + +, Perl, Ruby, Python, PHP, C # etc.) contains many graphical data plugins (Nagiosgraph, Nagiosgrapher, Pnp4nagios, etc.)
4. A parallel service check can define the hierarchy of network hosts, allowing for step-by-step inspection, starting from the parent host
Notify when a problem occurs with a service or host, via email, pager, SMS or any user-defined plugin
5. Ability to customize the event handling mechanism to reactivate a faulty service or host
? Automatic log Looping
? Supports redundant monitoring
? Includes web interface to view current network status, notifications, problem history, log files, etc.
How Nagios Works
Nagios's function is to monitor the service and host, but it does not have this function, all monitoring, detection functions are through the plug-in to complete.
Nagios periodically invokes the plugin to detect the status of the server and maintain a queue, all plug-in return status information goes into the queue, and Nagios reads the information from the first team and displays the status through the Web.
Nagios provides a number of plug-ins that enable you to monitor service status. After the installation is complete, the Nagios home directory is/libexec with all the plugins, such as Check_disk check the disk space plug-in, check_load check the CPU load, and so on. Each plugin can be run./check_xxx–h view its usage and functionality
The working schematic is as follows:

Nagios installation and Configuration I. Nagios-related Software Installation

Environment preparation
Installing the base compilation environment software
Yum install php gcc glibc glibc-common unzip GD Gd-devel–y

Solving Perl compilation Problems
echo "Export Lc_all=c" >>/etc/profile

Resolve time synchronization issues

Crontab-e
/10 */bin/sh/usr/sbin/ntpdate.sh >/dev/null 2>&1
[Email protected] nagios-plugins-2.1.2]# cat/usr/sbin/ntpdate.sh
#!/bin/bash
#date Update
Ntpdate s1a.time.edu.cn

1. Create Nagios users and related groups

[Email protected] ~]#
Useradd-m Nagios
passwd Nagios
Groupadd Nagcmd
Usermod-a-G Nagcmd Nagios
Usermod-a-G Nagcmd Apache

2. Nagios Server-side installation

Download Nagios Server Software and plugins
[Email protected] ~]#
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.1.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

3. Source code compile and install Nagios and related plugins

[Email protected] ~]#
Tar zxf nagios-4.2.1.tar.gz
CD nagios-4.2.1
./configure--with-command-group=nagcmd

There is no prompt for any errors when the following screen indicates a successful configuration

Next install prompt to compile
[Email protected] ~]#
Make all

Compiling the installation and initializing the configuration file
[Email protected] ~]#

Make install
Make Install-init
Make Install-config
Make install-webconf
Make Install-commandmode

Install and compile the Nagios plugin
[Email protected] ~]#
TAR-ZXVF nagios-plugins-2.1.2.tar.gz
CD nagios-plugins-2.1.2
./configure--with-nagios-user=nagios--with-nagios-group=nagios
Make
Make install

4. Configure Mail Contact information

Configuration files under directory/usr/local/nagios/etc, with these basic configuration information you can start Nagios directly, and now the only thing you need to change is contact information that you can edit/usr/local/nagios/etc/objects/ CONTACTS.CFG, replace the contact email address with your own.

If the system needs to install Sedmail to send mail
[Email protected] ~]#
Yum Install SendMail SENDMAIL-CF

5. Create a password for the login Web interface for Nagios

[Email protected] ~]#
Htpasswd-c/usr/local/nagios/etc/htpasswd.users Admin

6. Compiling and installing the Nagios plugin

[Email protected] ~]#

Tar zxf nagios-plugins-2.1.2.tar.gz
CD nagios-plugins-2.1.2
./configure--with-nagios-user=nagios--with-nagios-group=nagios
Make
Make install

7. Set up the Nagios service to boot and start Ngios

Set power-on self-boot
[[email protected] nagios]# Systemctl enable Nagios
[Email protected]]# chkconfig--list |grep Nagios
Nagios 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Start the Nagios service

[[Email protected]]# systemctl start Nagios

Check whether the start is successful
[[Email protected]ver nagios]# systemctl start Nagios
[Email protected] nagios]# Ps-ef |grep Nagios
Nagios 24997 1 0 17:46? 00:00:02/usr/local/nagios/bin/nagios-d/usr/local/nagios/etc/nagios.cfg
Nagios 25003 24997 0 17:46? 00:00:01/usr/local/nagios/bin/nagios-d/usr/local/nagios/etc/nagios.cfg
Nagios 25036 24997 0 17:46? 00:00:00 [Nagios] <defunct>
Nagios 25037 24997 0 17:46? 00:00:00 [Nagios] <defunct>
Nagios 25038 24997 0 17:46? 00:00:00 [Nagios] <defunct>
Nagios 25039 24997 0 17:46? 00:00:00 [Nagios] <defunct>
Nagios 25094 24997 0 17:54? 00:00:00/usr/local/nagios/bin/nagios--WORKER/USR/LOCAL/NAGIOS/VAR/RW/NAGIOS.QH
Nagios 25095 24997 0 17:54? 00:00:00/usr/local/nagios/bin/nagios--WORKER/USR/LOCAL/NAGIOS/VAR/RW/NAGIOS.QH
Nagios 25096 24997 0 17:54? 00:00:00/usr/local/nagios/bin/nagios--WORKER/USR/LOCAL/NAGIOS/VAR/RW/NAGIOS.QH
Nagios 25097 24997 0 17:54? 00:00:00/usr/local/nagios/bin/nagios--WORKER/USR/LOCAL/NAGIOS/VAR/RW/NAGIOS.QH
Root 25521 25118 0 19:21 pts/0 00:00:00 grep--color=auto Nagios

A description of the Nagios process has started successfully

Check that the Nagios master configuration file syntax is correct br/>[[email protected]]#
< p="">

We only need to focus on the following two parameters, total Errors is 0 to explain the syntax is correct.
Total warnings:0
Total errors:0

Next in the browser input http:/server IP address/nagios login nagios, user name and password for the fifth step with HTPASSWD set, the following screen shows that you have successfully installed

Two Verify the monitoring capabilities of the Nagios server, such as monitoring server disk load on monitored servers.

The topology is as follows

Environment preparation

1. Download and install Nrpe

[email protected]]#
wget https://jaist.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
./configure
Make all
Make Install-plugin
Make Install-daemon

I encountered the following error while installing Nrpe

Install the Openssl-devel library to resolve
[email protected] nrpe-2.15]# yum Install Openssl-devel

So far, the lab environment on the Nagios-server server is ready.

2. Install the Nigios-plugins plug-in and Nrpe in the nagios-client in the same way, detailed installation steps refer to above. 3. Server-client-side configuration

1) Add the IP address that can monitor the nagios-server end of the current client as follows
allow_hosts=192.168.10.136
Use VI to edit Nrpe configuration file/usr/local/nagios/etc/nrpe.cfg Modify about 79 lines
I'm using the SED command to modify it.
[email protected] ~]# sed-i ' s/allowed_hosts=127.0.0.1/allowed_hosts=192.168.10.136/g '/usr/local/nagios/ Etc/nrpe.cfg
Check whether the modification was successful

2) Add plugin to monitor at end of/usr/local/nagios/etc/nrpe.cfg file

Circular section is the default monitoring plug-in, if you need to monitor other content, you can add and install the relevant plug-in, this experiment is monitoring the disk load Check_load, is included in the default monitoring content

4) Start Nrpe

[email protected] ~]#/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-d

Set power-on self-boot
echo "/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg–d" >>/etc/rc.local

Check if the service started successfully

[email protected] ~]# netstat-lnt |grep 5666
TCP 0 0 0.0.0.0:5666 0.0.0.0: LISTEN
TCP6 0 0::: 5666::
: LISTEN

[[email protected] ~]# lsof-i: 5666
COMMAND PID USER FD TYPE DEVICE size/off NODE NAME
Nrpe 46042 Nagios 4u IPv4 55448 0t0 TCP : 5666 (LISTEN)
Nrpe 46042 nagios 5u IPv6 55449 0t0 TCP
: 5666 (LISTEN)

Nrpe ports and processes are present stating that Nrpe started successfully.

Hint: Restart Nrpe can use Killall to kill Nrpe process and then start

4. Nagios-server-side configuration.

1) Create Host.cfg host file to add monitored host
Here we use lohosthost.cfg as a template to take the first 51 rows as a template for host.cfg
[email protected] ~]#
Head-51/usr/local/nagios/etc/objects/localhost.cfg >/usr/local/nagios/etc/objects/hosts.cfg

Use VI edit hosts.cfg to change to the following content

Authorized
[email protected] ~]# chwon-r nagios.nagios/usr/local/nagios/etc/objects/hosts.cfg

2) Create a SERVICES.CFG monitoring service file to add services to monitor
[email protected] ~]#
Touch/usr/local/nagios/etc/objects/services.cfg
Chwon-r nagios.nagios/usr/local/nagios/etc/objects/hosts.cfg

Edit the/usr/local/nagios/etc/objects/services.cfg file to enter the following:

[email protected] objects]# vi/usr/local/nagios/etc/objects/services.cfg
Define Service {
Use Generic-service; monitoring parameters using the Templates.cfg template
HOST_NAME nagios-client; host name of the server being monitored
Service_description Check Load
Check_command check_nrpe!check_load; service commands to monitor
}

Note: The default is to use the templates.cfg template to monitor the parameters, if not required, you can define their own

3) Add CHECK_NRP plugin configuration in commands.cfg
Edit/usr/local/nagios/etc/objects/commands.cfg Add the following at the end of the file

Define Command{
Command_name Check_nrpe
Command_line $USER 1$check_nrpe-h $HOSTADDRESS $-C $ARG 1$

}

4) Check the Nagios master configuration file and restart

[email protected] ~]#/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg

Total warnings:0
Total errors:0

Restart

[email protected] ~]#/etc/init.d/nagios Reload
Reloading Nagios configuration (via Systemctl): [OK]

5) The client tests whether there are monitoring hosts and services
Open Browser appears the following screen does not successfully monitor the host and related services

Fine read the original is the permission out of the question, we previously configured the login admin does not have sufficient permissions to access the CGI

Workaround:
Replace all cgi.cfg nagiosadmin with admin (login name we set previously)

[email protected] ~]# sed-i ' s/nagiosadmin/admin/g '/usr/local/nagios/etc/cgi.cfg

Check syntax and restart Nagios
[email protected] ~]#/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg

Total warnings:0
Total errors:0

Restart

[email protected] ~]#/etc/init.d/nagios Reload
Reloading Nagios configuration (via Systemctl): [OK]

Open browser Access
Can see information about the host being monitored

However, the following exception occurred while viewing the monitored services

4. Troubleshooting

1). View Nagios's error log

[email protected] ~]# Tail-100/usr/local/nagios/var/nagios.log
[1523721600] LOG rotation:daily
[1523721600] LOG version:2.0
[1523721600] current HOST state:nagios-client; up; hard;1; PING Ok-packet loss = 0, RTA = 1.16 ms
[1523721600] current SERVICE state:nagios-client;check load; CRITICAL; hard;3; (Return code of 255 is out of bounds)
[1523721614] Warning:return Code of 255 for check the service ' Check load ' on host ' nagios-client ' is out of bounds.
[1523721945] caught SIGHUP, restarting ...
The log probably says no. Check_load cannot return results, see if it is a permission issue

Checks whether the client Nrpe configuration file allows server addresses to be accessed


There's nothing wrong with finding the address on the server side.

2). Check the results manually with the Check_load script in the service
[email protected] ~]#/usr/local/nagios/libexec/check_nrpe-h 192.168.10.135-c check_load
Connect to address 192.168.10.135 Port 5666:no route to host

Prompt for routes without hosts, view routing table
[email protected] ~]# route-n
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
0.0.0.0 192.168.10.2 0.0.0.0 UG 0 0 0 eno16777728
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eno16777728
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eno16777728

This is strange, obviously there is a default route, ping each other also pass

3). Check firewall and SELinux
[email protected] ~]# systemctl status Firewall.service
Unit Firewall.service could not being found.

[email protected] ~]# systemctl status Setenfore.service
Unit Setenfore.service could not being found.

[email protected] ~]# systemctl status iptables

    • Iptables.service-ipv4 Firewall with Iptables
      Loaded:loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset:disabled)
      Active:active (exited) since Sun 2018-04-15 01:26:52 CST; 9s ago
      process:75135 execstop=/usr/libexec/iptables/iptables.init Stop (code=exited, status=0/success)
      process:75653 execstart=/usr/libexec/iptables/iptables.init Start (code=exited, status=0/success)
      Main pid:75653 (code=exited, status=0/success)

APR 01:26:52 nagios-client systemd[1]: Starting IPV4 firewall with iptables ...
APR 01:26:52 nagios-client iptables.init[75653]: iptables:applying firewall rules: [OK]
APR 01:26:52 nagios-client systemd[1]: Started IPv4 Firewall with iptables.

Finally found that the firewall iptables is not closed, will it be a firewall problem? Turn it off first, try it.

[email protected] ~]# systemctl stop iptables
[email protected] ~]# systemctl status iptables

    • Iptables.service-ipv4 Firewall with iptables
      loaded:loaded (/usr/lib/systemd/system/iptables.service; Enabled Vendor preset:disabled)
      Active:inactive (dead) since Sun 2018-04-15 01:30:07 CST; 12s ago
      process:75764 execstop= /usr/libexec/iptables/iptables.init Stop (code=exited, status=0/success)
      process:75653 ExecStart=/usr/libexec/ Iptables/iptables.init Start (code=exited, status=0/success)
      Main pid:75653 (code=exited, status=0/success)
    • /ul>

APR 01:26:52 nagios-client systemd[1]: Starting IPV4 firewall with iptables ...
Apr 01:26:52 nagios-client iptables.init[75653]: iptables:applying firewall rules: [OK]
Apr 01:26:52 Nagio S-client systemd[1]: Started IPv4 Firewall with iptables.
APR 01:30:06 nagios-client systemd[1]: Stopping IPv4 firewall with iptables ...
Apr 01:30:06 nagios-client iptables.init[75764]: iptables:setting chains to policy accept:filter [OK]
Apr 15 01:30:06 nagios-client iptables.init[75764]: iptables:flushing firewall rules: [OK]
Apr 01:30:07 nagios-client I PTABLES.INIT[75764]: iptables:unloading modules: [OK]
Apr 01:30:07 nagios-client systemd[1]: Stopped IPv4 Firewal L with Iptables.

4. Check again with the command on the service side
[email protected] ~]#/usr/local/nagios/libexec/check_nrpe-h 192.168.10.135-c check_load
Ok-load average:0.97, 0.91, 0.88|load1=0.970;15.000;30.000;0; load5=0.910;10.000;25.000;0; load15=0.880;5.000;20.000;0;

Can see the results, sure enough is a firewall problem, configuration is easy, troubleshooting, encountered problems is good, multi-point to consult the relevant documents, multi-angle to consider the problem, will make you grow faster!

We open the browser to see again, status is OK, this congratulations you configured to complete the

In fact, a lot of other services can also be monitored in this way, I listed above is just one of the services, I do not give an example.

Learning tips: Learning needs to be summed up, otherwise time long forgotten quickly. It is important to take notes, the memory of the human brain is limited, it is impossible to remember all the knowledge, this requires us to use hard disk to help us remember the details of the specific knowledge, we just remember the outline, and later forget to turn over the notes, you will find that the previous knowledge and back to the mind.

Linux Note Network monitoring Nagios installation and configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.