Setting up Nagios monitoring on Ubuntu is a common system monitoring tool. It provides many basic service monitoring scripts, such as HTTP and MYSQL, with good scalability, you can customize monitoring scripts for specific parameters and alarm methods. But the configuration of Nagios is quite complex ,...
Setting up Nagios monitoring on Ubuntu is a common system monitoring tool. It provides many basic service monitoring scripts, 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. Run 1 www.2cto.com sudo apt-get apache2 nagios3 nagios-nrpe-pluginnagios-nrpe-plugin on the server to communicate with the nrpe service on the monitored machine; during the installation process, you will be 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. Access http:///nagios3 The home page of nagios is displayed. If you want to see nagios doc on the webpage, install: 1 sudo apt-get install nagios3-doc if you want to use Nginx as web server, please 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 is installed in/etc/nagios-plugin/config, and the monitoring scripts are all in/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 configuration of the script www.2cto.com 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-email3 command_line/usr/bin/printf "% B" "***** Nagios ***** \ n \ nNotification Type: $ icationicationtype $ \ n \ nService: $ SERVICEDESC $ \ nHost: $ HOSTALIAS $ \ nAddress: $ HOSTADDRESS $ \ nState: $ SERVICESTATE $ \ n \ nDate/Time: $ LONGDATETIME $ \ n \ nAdditional Info: \ n $ SERVICEOUTPUT $ "|/usr/bin/sendEmail-f -T -U "** $ icationicationtype $ 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_nrpe04 command_line/usr/lib/nagios/plugins/check_nrpe-H $ HOSTADDRESS $-c $ ARG1 $-a $ ARG2 $05 www.2cto.com} 06 07 # this command runs a program $ ARG1 $ with no arguments08define command {09 command_name check_nrpe_1arg10 command_line/usr/lib/nag Ios/plugins/check_nrpe-H $ HOSTADDRESS $-c $ ARG1 $11} are configured with the nrpe command with one parameter and two parameters, respectively, command name is the check_nrpe_1arg command with one parameter. 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 can be used to output instructions for check_http. The configuration structure is in/etc/nagios3/conf. d has 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 email here; www.2cto.com 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 HTTP2 check_command check_http3 use generic-service4 icationication_interval 0; set> 0 if you want to be renotified5} reasonable configuration method is, configure the service for each type of server in service_nagios2.cfg, and then in the hosts. cfg and hostgroup_nagios2.cfg. configure the corresponding server and its category. 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 www.2cto.com is/etc/nagios/nrpe. cfg. The main configuration items are as follows: 1 # server_address = 127.0.0.1 is accessible only on the local machine by default. if there are multiple IP addresses, you do not know which IP address to use. generally, an intranet address is assigned; 1allowed_hosts = 127.0.0.1 allows access to nrpe Machines. multiple hosts are separated by commas (,). do not leave spaces. "127.0.0.1, 192.168.1.12" is not working and 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 102 command [check_load] =/usr/lib/nagios/plugins/check_load-w 15, 10, 5-c 30,25, 203 command [check_hda1] =/usr/lib/nagios/plugins/check_disk-w 20%-c 10%-p/dev/hda1 so that the nagios server can pass/usr/lib/nagios /plugins/check_nrpe-H <被监控机器> -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 the preceding steps at www.2cto.com 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. 1rm/var/cache/nagios3/* by julien
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