2. Add new configuration files
First create a simple configuration file, with the following contents:
define timeperiod{ timeperiod_name 24x7 alias 24 Hours A Day, 7 Days A Week sunday 00:00-24:00 monday 00:00-24:00 tuesday 00:00-24:00 wednesday 00:00-24:00 thursday 00:00-24:00 friday 00:00-24:00 saturday 00:00-24:00 } |
The second manually created configuration file is , its format is as follows:
define contact { contact_name sa //Don't have spaces alias system administrator service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands service-notify-by-sms,service- notify-by-email //This command reads the configuration file host_notification_commands host-notify-by-email,host-noti fy-by-sms //This command reads the configuration file email sery@ pager 13333333333 //Mobile phone number, receive alarm message } //Don't write this symbol off define contact { contact_name sery alias system administrator service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands service-notify-by-sms,service- notify-by-email host_notification_commands host-notify-by-email,host-noti fy-by-sms email sery@ pager 13312345678 } |
The third manually created configuration file is a file. This file is based on the previous file. The contactgroups file is relatively simple, and its format is as follows:
define contactgroup { contactgroup_name sagroup //Don't use spaces alias system administrator group members sa,sery //This example has 2 members} |
The key role has finally appeared, and this is the configuration file. Here are the basic styles of the two hosts I defined:
#define monitor host ################################################################# # Wangjing IDC servers # ################################################################# define host { host_name nagios-server alias nagios server address ..x.49 contact_groups sagroup //Multiple contact groups are separated by commas, |
Another heavyweight configuration file is that without this file, no monitoring is useless. Here is a style file:
#service definition ############################################################## # Wangjing IDC servers service for host-live # ############################################################## define service { host_name nagios-server //source: service_description check-host-alive check_period 24x7 max_check_attempts 4 normal_check_interval 3 retry_check_interval 2 contact_groups sagroup //source: notification_interval 10 notification_period 24x7 notification_options w,u,c,r check_command check-host-alive //Check whether the host is alive } define service { host_name 74-210 service_description check_tcp 80 check_period 24x7 max_check_attempts 4 normal_check_interval 3 retry_check_interval 2 contact_groups sagroup notification_interval 10 notification_period 24x7 notification_options w,u,c,r check_command check_tcp!80 //Check whether the tcp 80 port service is normal } |
Host group configuration file, an optional project, built on top of file hosts, in the format as follows:
define hostgroup { hostgroup_name sa-servers alias sa servers members nagios-server,24-25,24-26 //Separate multiple hosts with commas } |
After a lot of hardships, I finally saved these configurations. Now I can’t wait to run the program/usr/local/nagios –v /usr/local/nagios/etc/To check the correctness of all configuration files. If you are very lucky, the run will appear at the end of the output:
Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check |
[root@netmonitor nagios]# bin/nagios -v etc/ Nagios 2.5 Copyright (c) 1999-2006 Ethan Galstad () Last Modified: 07-13-2006 License: GPL Reading configuration data... Error: Could not find any host matching 'nagios-server' Error: Could not expand member hosts specified in hostgroup |
acceptance
Use the browser to enter the IP and directory of the server where Nagios is located, such ashttp://61...X/nagios, and then enter the username and password required for verification, and then click the relevant connection on the right side of the page to view various statuses. Turn off a service that is monitored by the nagios host or unplug the network cable of a server. Wait for a few minutes, click the hyperconnection "Service Detail" to observe the status of the page to see if there is a red eye-catching alarm.
After a while, you will receive an alarm message and an alarm email. Then, after turning on all the test services or check the unplugged network cable, the red alarm form on the web page will disappear, and the mobile phone message or email notification will be notified to recover. If your situation is the same, then it's really done.
Nagios is very powerful. In my project, it simplifies nagios as much as possible because of my different needs without using proxy, more plug-ins, etc. It works very well in a network scale of no more than 1,000 servers. If there are more servers, it is recommended to use mysql data to manage monitoring objects. During the deployment of nagios, I made many choices. For more details, please refer to the official documentation.