Nagios configuration tips

Source: Internet
Author: User

Nagios Structure

The structure of Nagios is actually very simple. A monitoring system, a web display system, and a remote server are gone.

The monitoring system is fundamental. In debian, the package to be installed is Nagios3. After the package is installed, a monitoring process is started to check whether all services are OK. If it is not OK, the event is triggered.

During the check, Nagios calls some "plug-ins ". These plug-ins are actually registered under/etc/Nagios-plugins/config. Every plug-in configuration is name! V1! V2... Format. In the registration, we can see that command_name corresponds to a command_line. You can easily see that this converts a definition to a command line.

You can directly execute this command line to see a standard output. Nagios parses the standard output to obtain whether the value is within a valid range. In principle, you can write your own plug-ins to monitor Nagios for everything.

For information that can be obtained remotely, nothing can be done on the target device, such as ping connectivity or port connectivity. For other information, such as the remaining disk space value, which cannot be obtained remotely, you need to install nrpe and Nagios Remote Plugin Executor Server on the target device. In debian, It is the Nagios-nrpe-server package. This package is not required if local information is obtained.

Finally, cgi exposes local information to web queries, which constitutes a complete Nagios system. In debian, This Is The Nagios3-cgi package.

Configuration of Nagios page on nginx

This process is cumbersome because apache will automatically configure it, while nginx does not have a host process or cgi. Therefore, you need to run two host processes.

First, you need to install the php-fpm host process, which is the best host for nginx and php Execution. Php is used in Nagios, so you need php Execution capabilities.

Install the fcgiwrap package. This is the cgi execution host, which is exposed using the fastcgi protocol. Note. If your nginx and Nagios hosts are not virtualized on the same device, for example, shells), you only need to execute fcgiwrap on the Nagios host. Php-fpm and nginx can be executed on different devices. Only the former must have the cgi code of Nagios, and the latter must have the webpage and php code of Nagios. And these three are in the Nagios3-cgi package. Therefore, several machines need to install the Nagios3-cgi package.

Finally, configure nginx.

 
 
  1. location /Nagios3 { 
  2. index index.html index.htm index.php; 
  3. location /Nagios3/stylesheets { 
  4. root /etc; 
  5. }  

The first ing is the basic directory of Nagios. In the root directory, I actually configured the link location in Nagios3->/usr/share/Nagios3/htdocs/debian ). The second ing is the style table configuration. I use the system default.

 
 
  1. location ~ ^/Nagios3/.*.php$ { 
  2. include fastcgi_params; 
  3. fastcgi_pass unix:/var/run/php5-fpm.sock; 
  4. }  

This is the php Parsing Code of Nagios. My php-fpm runs on the same machine, so you can configure it directly.

 
 
  1. location /cgi-bin/Nagios3 { 
  2. root /usr/lib; 
  3. include fastcgi_params; 
  4. fastcgi_param REMOTE_USER $remote_user; 
  5. fastcgi_pass dev:port; 
  6. }  

Finally, the configuration exposed by cgi is used. Because my Nagios host is not on the web server, fastcgi is a remote address. Also, pay attention to REMOTE_USER. Pass this command to remotely recognize your user basic auth. Because the cgi of Nagios works through this operation, the other party will always think that you are an unauthorized user.

Simple Nagios Configuration

Nagios is not responsible for machine maintenance. His design goal is "availability ". Therefore, whether the target is reachable and whether the service is available is the focus of Nagios. As for disks and loads, It's Just monitoring by the way. So you can see that Nagios does not have a direct plug-in to monitor CPU or memory. Only the snmp plug-in can query the data.

So we are happy. To a minimum, we add all the devices and service ports to be monitored to the list. When these devices are unavailable, Nagios will send an alert email ). If we are lucky, we can monitor whether the machine has apt packages to be upgraded and whether the disk space is sufficient. As a suggestion, you only need to monitor the load and disk space utilization. The rest is generally not needed. When the memory or CPU is faulty, your query actually cannot be returned. In contrast, it is our expectation that the target port will soon lose response and an alarm will be triggered.

OK. On this basis, let's see what can be configured.

Add Server

First, you can define some machines. There is an example in localhost_Nagios2.cfg, which is roughly like this.

 
 
  1. define host{ 
  2. use generic-host ; Name of host template to use 
  3. host_name host 
  4. alias host 
  5. address IP 
  6. }  

I suggest you create a file to manage these devices. For example, my name is hosts. cfg.

Basic services

Hostgroups_Nagios2.cfg has many server groups, including an ssh group and an http group. If your device has these two most common services, you can directly add them to these two groups, and the corresponding services of the device will be monitored.

There is a debian group. This group does not provide services, but this group defines the device type as debian. You can see the logo on the web.

In services_Nagios2.cfg, you can also define other common services and add servers to hostgroups.

For a few special services, it is necessary to open them in services. Defining some services in hosts is simple and straightforward.

Server Definition

The default generic-host contains keep-alive, and the server will ping the server to confirm that the device is alive. If icmp is disabled for the sake of security and firewall, it is difficult for the target machine to trust your IP address. So it will be annoying to open the ping command. It's okay to watch a server go down every day.

You can copy the standard configuration in the generic-host_Nagios2.cfg and remove the following line. This server will not check whether it is alive.

 
 
  1. check_command check-host-alive  

Nrpe

The configuration of nrpe is cumbersome. You must first define the commands to be executed in the configuration file of the nrpe service. Then use check_nrpe to check and return the result in Nagios service.

Reference: http://www.linuxany.com/archives/2004.html

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.