Nagios system Monitoring
Nagios is a free, open source IT infrastructure monitoring system that is powerful, flexible, and capable of monitoring Windows, Linux, VMware and Unix host status, switches, routers and other network settings. Once the host or service status is abnormal, a message or SMS alert will be sent to the IT operator for the first time to send a normal email or text message after the recovery. Nagios is simple, maintainable, and provides an optional browser-based WEB interface that allows administrators to view the system's operational status, network status, service status, log information, and other anomalies.
A simple description of Nagios structure
Nagios is structurally divided into two parts of the core and plugin. The core of Nagios only provides very little monitoring, so to build a complete IT monitoring management system, users also need to install the appropriate plugin on the Nagios server, plug-ins can be downloaded from the Nagios official website http://www.nagios.org/, You can also write your own required plugins according to the actual requirements.
Second, Nagios can realize the functional characteristics
- Monitoring network Services (SMTP, POP3, HTTP, FTP, ping, etc.)
- Monitor local and remote host resources (CPU load, disk utilization, process, etc.)
- Allows users to write their own plugins to monitor specific services and support multiple development languages (Shell, Perl, Python, PHP, C, etc.)
- Ability to define network hierarchy
- Send alerts to Contacts when a service or host problem arises and resolves (via email, SMS, custom)
- Can support and implement redundant monitoring of the host
- Available Web interface for viewing current network status, notification and fault history, log files, etc.
Three, Nagios monitoring implementation principle
Nagios software needs to be installed on a separate server, called the Monitoring Center, the Monitoring Center server can use Linux or Unix operating system; each monitored hardware host or service runs a Nagios software daemon that communicates with the Monitoring Center server, It can also be understood as either an Agent or a plug-in. The Monitoring Center server reads the instructions in the configuration file to communicate with the remote daemon and instructs the remote daemon to perform the necessary checks. Although Nagios software must be run on a Linux or Unix operating system, the remotely monitored machine can be any host that can communicate with it, and Naigos will respond to the configuration based on the response returned by the remote host, and Nagios will be tested on a local machine, If the detected return value is incorrect, Nagios will alert you in one or more ways.
Iv. Monitoring Center Server installation Configuration
1. Central server Basic Environment
Operating system: CentOS 6.4 x86_64
IP Address: 192.168.0.8
2. Installing the Epel extension Source (Nagios)
[email protected] ~]# Yum install epel-release-y
3. Installing the Nagios series software
[email protected] ~]# Yum install httpd nagios nagios-plugins-all Nagios-plugins-nrpe
4. Set the user password to modify background
[Email protected] ~]# htpasswd-c/etc/nagios/passwd nagiosadmin
Default User name: nagiosadmin password: nagiosadmin The password can be modified by this command.
5. Configuration file Modification
[[email protected] ~]# vim/etc/nagios/nagios.cfg # configuration file basic without modification
Check the configuration file for syntax errors:
[Email protected] ~]# nagios-v/etc/nagios/nagios.cfg
6. Start Nagios related services
[[Email protected] ~]# service Nagios start[[email protected] ~]# service httpd start
7. Browser Access
Http://192.168.0.8/nagios # Note It's best to close iptables and SELinux
Access the above address through the browser, enter the background user name and password. Default: Nagiosadmin nagiosadmin
V. Monitoring Client BASIC network services
1. Description
For the client-like ping, SSH, HTTP and other basic network services, only need to perform simple network probe on the server side of the command to see if the appropriate service is working properly, so the monitoring of these services on the client does not need to install any plug-ins and services.
2. Client Environment
Operating system: CentOS 6.4 x86_64
IP Address: 192.168.0.28
3. Add basic services
To add a configuration file on the server side:
VIM/ETC/NAGIOS/CONF.D/192.168.0.28.CFG # Add the following:
Define host{# Definition Host: 192.168.0.28 use Linux-server host_name 192.168.0.2 8 alias 0.28 address 192.168.0.28}define service{# Add ping monitoring service Use Generic-service host_name 192.168.0.28 service_description check_ Ping Check_command check_ping!100.0,20%!200.0,50% max_check_attempts 5 normal_check_in Terval 1}define service{# Add SSH monitoring service use Generic-service HOST_NAME 192.168.0.28 service_description check_ssh Check_command check_ssh max_check_attempts 5 Normal_check_interval 1}define service{# Add HTTP monitoring service use Generic-service HOST_NAME 192.168.0.28 service_description check_http check_command check_h TTP Max_check_attempts 5 Normal_check_interval 1}
4. Reload the Nagios configuration file
Service Nagios Reload
Access Http://192.168.0.8/nagios through the browser via current Status-the service can see a list of the 3 services added to the host 192.168.0.28, just beginning Pending status, after a period of time the status will become OK words.
5. Configuration file Explanation
A total of three Service:ssh ping http three items were monitored in our defined profiles using local Nagios tools to connect to remote machines, and no plug-ins were installed in time to monitor them.
Max_check_attempts 5: Try to detect 5 times there is a problem before the alarm, if set to 1, once detected a problem immediately alarm
Normal_check_interval 1: The time interval for re-detection, in minutes, and 3 minutes by default.
Notification_interval 60: The failure has not been resolved after an exception, and Nagios again notifies the user of the time. Set to 0, notify only once.
Vi. monitoring client Local System services
Other services such as load, disk usage, etc. require the server to connect to the remote host via Nrpe to obtain information, so a remote host is required to install the Nrpe service and the corresponding plug-in program.
1. Monitoring the Client
IP Address: 192.168.0.28
2. Software The client needs to install
[[email protected] ~]# Yum install epel-release-y # installation Epel source [[email protected] ~]# Yum install nrpe-y # install Nrpe service Soft item [[email protected] ~]# Yum install nagios-plugins-all-y # Install all Nagios plugins
3. Configure the client Nrpe service to be monitored
[[email protected] ~]# vim/etc/nagios/nrpe.cfg # Modify the following allowed_hosts=127.0.0.1,192.168.0.8 # Add 192.168.0.8来 monitoring dont_blame_nrpe=1 # Modify 0 to 1, set to pass parameters
Command[check_hda1]=/usr/lib64/nagios/plugins/check_disk-w 20%-C 10%-p/dev/sda1
4. Client-initiated Nrpe service
[[Email protected] ~]# service Nrpe startstarting Nrpe: [OK]
5. Server-side configuration to monitor clients
[Email protected] ~]# vim/etc/nagios/objects/commands. CFG was added as follows: Define command{ command_name Check_nrpe command_line $USER 1$/check_nrpe-h $HOSTADDRESS $-C $ARG 1$}
[Email protected] ~]# vim/etc/nagios/conf.d/192.168.0.28.cfg
Add the following content:
Define service{ # Add monitoring payload use generic-service host_name 192.168.0.28 service_ Description check_load check_command check_nrpe!check_load max_check_attempts 5 Normal _check_interval 1}define service{ # Add monitoring sda1 disk use generic-service host_name 192.168.0.28 service_description check_disk_hda1 check_command check_nrpe!check_hda1 Max_check_attempts 5 Normal_check_interval 1}
6. Reload the server configuration
[[Email protected] ~]# service Nagios Reload
Http://192.168.0.8/nagios normal display via browser access.
Vii. Nagios Configuration Graphical display
Nagios monitors a transient state of service or host, and sometimes the system administrator needs to understand the performance of the host over time and the response status of the service, and form a chart, which needs to be analyzed by viewing the log data. But this approach is not only cumbersome, but also abstract. In order to see the host running state more intuitively, PNP is used to implement this function. PnP is a small open source package that is based on PHP and Perl scripting, and PNP can use the Rrdtoul tool to chart the data that Nagios collects, and then show the status of the host or service running over time. Note: The following actions are for the hub server.
1. Installing the Pnp4nagios Software
[email protected] ~]# Yum install-y pnp4nagios RRDtool
2. Modify the master configuration file
[[email protected] ~]# Vim/etc/nagios/nagios.cfg Modify the following configuration: Process_performance_data=1 host_perfdata_command= Process-host-perfdataservice_perfdata_command=process-service-perfdata Enable_environment_macros=1
3. Modify the Command.cfg configuration file
[Email protected] ~]# vim/etc/nagios/objects/commands.cfg
Comment out the original process-host-perfdata and Process-service-perfdata redefined
Define command { command_name process-service-perfdata command_line /usr/bin/perl/usr/libexec/ pnp4nagios/process_perfdata.pl } define command { command_name process-host-perfdata command _line /usr/bin/perl/usr/libexec/pnp4nagios/process_perfdata.pl-d Hostperfdata }
4. Modify the Templates.cfg configuration file
Vim/etc/nagios/objects/templates.cfgdefine Host { name hosts-pnp Register 0 action_url/ pnp4nagios/index.php/graph?host= $HOSTNAME $&srv=_host_ process_perf_data 1}define Service { name srv-pnp Register 0 action_url/pnp4nagios/index.php/graph?host= $HOSTNAME $&srv=$ servicedesc$ process_perf_data 1}
5. Modify the configuration of host and service
[Email protected] ~]# vim/etc/nagios/conf.d/192.168.0.28.cfg
Add Hosts-pnp behind the templates used by all hosts:
Define host{ use LINUX-SERVER,HOSTS-PNP
Add Srv-pnp behind the templates used by all services:
Define service{ use generic-service,srv-pnp host_name 192.168.0.48 service_description CHECK_DISK_HDA1 check_command check_nrpe!check_hda1}
6. Restart the service and visit again
[[Email protected] conf.d]# service Nagios restart[[email protected] conf.d]# service httpd restart[[email protected ] conf.d]# service NPCD start
Browser access: Http://192.168.0.8/nagios Click on the current Status service to display the "curve" icon, wait a while, click on the icon to see the data.
Eight, configure mail alarm
1. Add a Contact Group
Vim/etc/nagios/objects/contacts.cfg
Add the following content:
Define contact{ contact_name 123 use generic-contact alias aming email [email Protected] }define contact{ contact_name 456 use generic-contact alias AAA Email [Email protected] } Define contactgroup{ contactgroup_name Common alias common members 123,456 }
2. Add an alert contact to the service that needs to be alerted
Then add Contactgroup to the service that needs to be alerted , and here's an example of an HTTP service:
Define service{ use generic-service,srv-pnp host_name 192.168.0.48 service_description Check_http check_command check_http max_check_attempts 5 normal_check_interval 1 contact_groups Common # Add alert Contact}
Restart the service, OK.
Nagios system Monitoring