Quickly build Nagios monitoring on Ubuntu

Source: Internet
Author: User
Nagios is a common system monitoring tool that provides monitoring scripts for many basic services, such as HTTP and MYSQL, with good scalability, you can customize monitoring scripts for specific parameters and alarm methods. However, the configuration of Nagios is quite complex. This article summarizes the process of setting up Nagios on javastuserver recently, so that you can install and build a monitoring system more quickly in the future. Installing and installing Nagios is divided into two parts: nagiosserver and monitored. Nagioss

Nagios is a common system monitoring tool that provides monitoring scripts for many basic services, such as HTTP and MYSQL, with good scalability, you can customize monitoring scripts for specific parameters and alarm methods. However, the configuration of Nagios is quite complex. This article summarizes my recent process of building Nagios on Ubuntu Server, so that you can install and build a monitoring system more quickly in the future.

Installing and installing Nagios is divided into two parts: nagios server and monitored side. The nagios server provides a web interface and alarm configuration. The monitored end needs to install the nagios nrpe service to communicate with the server about local monitoring. 1) Nagios Server Installation: by default, nagios uses apache2 as its web server. Based on the fast principle, run on the server:
1 sudo apt-get apache2 nagios3 nagios-nrpe-plugin

Nagios-nrpe-plugin is used to communicate with the nrpe service on the monitored machine. During the installation process, a message is prompted to enter the password of the nagsio web administrator. The nagios web Logon account and password are nagiosadmin/ <安装时设定的密码> You can also modify/etc/nagios3/htpasswd. users to change the user and password. After the installation is complete, nagios3.conf will be created under/etc/apache/conf. d. This is the configuration of nagios web. Visit http: // nagios3 to view the home page of nagios. To view the nagios doc on the webpage, install:
1 sudo apt-get install nagios3-doc
If you want to use Nginx as the web server, Google "Nagios Nginx ".
2) on the monitored machine, run:
1 sudo apt-get install nagios-nrpe-server

Whether it is the nagios server or the monitored machine, the default monitoring script configuration will be installed in/etc/nagios-plugin/config, and the monitoring script will be under/usr/lib/nagios/plugins.
Nagios configuration 1) Nagios Server: the objects to be configured in Nagios are mainly divided into Host, Service, and Contact. The main configuration is/etc/nagios3/nagios. cfg, which generally does not need to be modified. The script configuration is/etc/nagios3/commands. cfg, which is usually used to modify notify-host-by-email and notify-service-by-email. The command for sending emails is usually modified, I used sendEmail (apt-get install sendEmail) to send an email:
1 define command{
2         command_name    notify-service-by-email
3         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$SERVICEOUTPUT$" | /usr/bin/sendEmail -f -t -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -s -xu -xp
4         }

You can also add some SMS alarm commands. For details, refer to Google "Nagios SMS alarm ". In addition, the script configuration to be viewed is located in/etc/nagios-plugin/config, such as check_nrpe.cfg:
01 # this command runs a program $ARG1$ with arguments $ARG2$
02 define command {
03         command_name    check_nrpe
04         command_line    /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$
05 }
06   
07 # this command runs a program $ARG1$ with no arguments
08 define command {
09         command_name    check_nrpe_1arg
10         command_line    /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
11 }

The nrpe command with one parameter and two parameters is configured respectively. The command name is the check_nrpe_1arg command with one parameter. The command name is the check_nrpe command with two parameters. For example, to view the load on the target machine, SET command line to check_nrpe_1arg! Check_load, which calls the check_load command on the nrpe server. To view the details of check_http/check_ping/check_mysql, see how to configure http. cfg/ping. cfg/mysql. cfg. Generally, scripts under/usr/lib/nagios/plugins are called. These scripts are executable. You can add "-- help" to view the specific usage of the script. For example:
1 /usr/lib/nagios/plugins/check_http --help

The usage of check_http can be output.
The configuration structure is in/etc/nagios3/conf. d. There is a set of configurations. The structure of this configuration is: 1) contacts_nagios2.cfg: Configure contacts, and configure alarm commands. Generally, I will modify the contact's email here; 2) generic-service_nagios2.cfg and generic-host_nagios2.cfg configuration, some configurations of generic-host/generic-service, in this way, you only need to configure the host/service with use generic-host/use generic-service to inherit the corresponding configuration. The extended configuration is placed in extinfo_nagios2.cfg. The time period configuration is in timeperiods_nagios2.cfg. I have not modified these files. 3) configure the host group in hostgroups_nagios2.cfg. In fact, it mainly serves to classify hosts. 4) The most important thing is services_nagios2.cfg. The service to be monitored is configured here, each service can specify which host is valid. For example:
1 define service {
2         hostgroup_name                  http-servers         
 
1         service_description             HTTP
2         check_command                   check_http
3         use                             generic-service
4         notification_interval           0 ; set > 0 if you want to be renotified
5 }

A reasonable configuration method is to configure the service for each type of server in service_nagios2.cfg, and then configure the corresponding server and the type of the server in hosts. cfg and hostgroup_nagios2.cfg. In this way, when the server address or service on the server changes, you only need to Modify host. cfg and hostgroup_nagios2.cfg.
The configuration file of the monitored machine is/etc/nagios/nrpe. cfg. The main configuration items are:
1 #server_address=127.0.0.1

By default, access is only available on the local machine. If you have multiple IP addresses, you do not know which IP address to use. Generally, an Intranet address is assigned;
1 allowed_hosts=127.0.0.1

Machines that are allowed to access nrpe. Multiple hosts are separated by commas (,). Do not leave a space. "127.0.0.1, 192.168.1.12" does not work. It must be "127.0.0.1, 192.168.1.12 "; custom commands in nrpe, such:
1 command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
2 command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
3 command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1

In this way, you can use/usr/lib/nagios/plugins/check_nrpe-H on the nagios server. <被监控机器> -C check_load: Call check_load on the monitored machine. For more information, see/etc/nagios-plugin/config/check_nrpe.cfg. The command line to be configured should be check_nrpe_1arg! Check_load. I wrote check_nrpe here! Check_load causes the service to be unknown.
Follow these steps to build a basic monitoring system in about 20 minutes. After completion, you can view various hosts and services on the nagios web page and view the detailed running status, including the running time of the next monitoring script. For detailed configuration, such as configuration check interval, please refer to the official documents of nagios. (Nagios homepage in http://nagios.org) if you need to expand the monitoring script, you need to write a script, the return value is 0, 1, 2 represents Normal, Warning, Critical status, respectively, then configure command in nrpe. I also encountered an Alarm Command error. After an alarm fails, the system did not trigger another alarm when it encountered a new alarm. Google: it may be a Nagios Cache problem. Just clear the cache.
1 rm /var/cache/nagios3/*

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.