The basic installation configuration for Nagios monitoring is summarized above and now summarizes the Nagios monitoring deployment
One, Nagios server monitoring deployment
1. Nagios Server directory and related configuration file description
After Nagios installation is complete, the/usr/local/nagios/directory will generate Nagios-related directories and configuration files, with the default configuration file under the/usr/local/nagios/etc directory. The detailed description is as follows:
A) Nagios post-installation directory structure
[[email protected] ~]# ll /usr/local/nagios/ # Nagios post-installation directory structure TOTAL 32DRWXRWXR-X.  2 nagios nagios 4096 Jun 6 15:53 bin # Nagios Related Commands drwxrwxr-x. 3 nagios nagios 4096 jun 6 15:53 etc # Nagios configuration file drwxr-xr-x. 2 root root 4096 jun 6 15:52 include # Nagios Citation file drwxrwxr-x. 2 nagios nagios 4096 jun 6 15:53 libexec # nagios Plugin Directory Drwxrwxr-x. 2 nagios nagios 4096 Jun 6 15:40 sbin # nagios external Command drwxrwxr-x. 11 nagios nagios 4096 jun 6 15:52 share # Nagios Web page Display related catalogue Drwxrwxr-x. 5 nagios nagios 4096 jun 6 18:41 var # Nagios Data and log directory
All client-side local monitoring is done by executing plugins in the Libexec directory, and if the Snmp,nagios server is turned on, it can also actively crawl
b) Nagios Core configuration file description
The Nagios Master profile is nagios.cfg, default under/usr/local/nagios/etc/, and under/usr/local/nagios/etc/there is a objects Directory (similar to the extra directory in Nginx), which contains the other Nagios profiles contained in the main profile nagios.cfg: The following:
[[Email protected] ~]# tree /usr/local/nagios/etc/ # nagios Configuration file directory/usr/local/nagios/etc/|-- cgi.cfg|-- htpasswd.users # login nagios web User name password Authentication |-- nagios.cfg # #主配置文件 |-- nrpe.cfg # Client configuration file |-- objects The # Master profile contains the profile directory that defines the Nagios object | |-- commands.cfg # store Nagios own defined commands (associated with plug-in commands in Linux) | |-- contacts.cfg # for configuring alarm contact | |-- hosts.cfg # for configuring the monitored host | |-- localhost.cfg # used to define the monitoring entry for this machine | |-- printer.cfg # used to define the monitoring entry for the printer | |-- sThe ervices.cfg # is used to configure monitored services | |-- switch.cfg # to define the monitoring entry for the switch | |-- templates.cfg # template configuration file | |-- timeperiods.cfg # for configuring alarm cycle time | '-- windows.cfg # is used to define a monitoring entry for Windows '-- resource.cfg
In the master configuration nagios.cfg, you can specify that a single CFG file can be included, or include a directory, and all of the CFG files in the included directory will be nagios.cfg included:
2. Main configuration file nagios.cfg configuration process
[Email protected] ~]# cd/usr/local/nagios/etc/
[[email protected] etc]# ls
Cgi.cfg htpasswd.users nagios.cfg nrpe.cfg Objects Resource.cfg
A) Increase the configuration file for the host and service
[Email protected] etc]# vim nagios.cfg +34#20170605cfg_file=/usr/local/nagios/etc/objects/hosts.cfgcfg_file=/usr/ Local/nagios/etc/objects/services.cfgcfg_dir=/usr/local/nagios/etc/objects/services
#---Cfg_dir is a service directory added for backup, which functions: Files in the directory can be loaded by Nagios as long as they conform to *.cfg. When you use a script to deploy in bulk, you can easily randomly name the configuration file.
#cfg_file =/usr/local/nagios/etc/objects/localhost.cfg
#---Localhost.cfg is the server-side local profile, commented out, and then unified monitoring
b) Generate hosts.cfg host files based on existing data
[Email protected] etc]# cd/usr/local/nagios/etc/objects/[[email protected] objects]# head-51 localhost.cfg > hosts. Cfg[[email protected] objects]# chown nagios.nagios/usr/local/nagios/etc/objects/hosts.cfg
c) Generate Services.cfg service file
[[email protected] objects]# Touch SERVICES.CFG #---reserved [[email protected] objects]# chown Nagios.nagios services.cfg
d) Build the configuration file directory for the service, and all the *.cfg configuration files in this directory will be automatically included in the main configuration file!
[Email protected] objects]# mkdir services [[email protected] objects]# chown Nagios.nagios Services
3. Configuring Nagios service-Side monitoring items
1) hosts.cfg configuration file description
#---Hosts.cfg is used to store the configuration of the host to be monitored by nagios
#---The parameter description for the HOSTS.CFG host definition section:
Define host{#此为定义被监控主机的配置文件
Use Linux-server #引用类, define the template used by the host, predefined in templates.cfg
Host_name web01 #指定主机名, is not the actual machine hostname, its own definition, convenient later in the definition of services call
Alias Web01 #别名
Address 10.0.0.8 #指定被监控主机的地址
Check_command check-host-alive #检查主机存活命令, from Commands.cfg
Max_check_attempts 3 #故障后, maximum number of attempts detected
Normal_check_interval 2 #正常检查时间间隔, per minute
Retry_check_interval 2 #故障后, retry check interval, unit minutes
Check_period 24x7 #检查周期, see timeperiods.cfg
Notification_interval #故障后两次报警的时间间隔, per minute
Notification_period 24x7 #一天内通知的周期. For one or half days, see timeperiods.cfg
Notification_options d,u,r #主机状态通知选项, Down,unreacheable,recovery
Contact_groups Admins #报警到admins user group. Defined in Contacts.cfg
}
2) Configure HOSTS.CFG to add the client hosts and host groups you want to monitor.
Take the client web01, WEB02 host as an example:
[[email protected] ~]# cd /usr/local/nagios/etc/objects #--- Nagios.cfg contains the secondary profile directory [[Email protected] objects]# cat hosts.cfg#client_host# define a host for the local machinedefine host{ use linux-server host_name web01 alias web01 address 10.0.0.8}define host{ use linux-server host_name web02 alias web02 address 10.0.0.7}define host{ use linux-server host_name nagios01 alias nagios01 address 10.0.0.71}# Define an optional hostgroup for linux machinesdefine hostgroup{ hostgroup_name linux-servers alias Linux Servers members    WEB01,WEB02,NAGIOS01}
3) Configure the SERVICES.CFG to define the host resources to monitor
The Services.cfg file is configured as a monitoring service and is one of the Nagios core configuration files, and most of the service configurations that you want to monitor are added here (when the server is within 50 units).
Note: This file needs to be manually added
SERVICES.CFG Configuration parameters:
Define Service {
Use Generic-service
HOST_NAME WEB01
Service_description Current Load
Check_command Check_nrpe!check_load
Max_check_attempts 2
Normal_check_interval 4
Retry_check_interval 4
Check_period 24x7
Retry_interval 1
Notification_interval 1440
Notification_period 24x7
Notification_options W,c,u,r
Contact_groups Admins
Process_perf_data 1
#retain_nonstatus_information 0
}
* Configuration for monitoring client-side local resources:
[[email protected] objects]# cat services.cfg################################### Passive monitoring ################################### #磁盘分区define service { use generic-service host_name web01,web02,nagios01 service_description Disk Partition check_command check_nrpe!check_disk} #swapdefine service { use generic-service host_name &nbsP; web01,web02,nagios01 service_description swap useage check_command check_nrpe!check_swap} #内存define service { use generic-service host_name web01,web02,nagios01 service_ description mem useage check_command  CHECK_NRPE!CHECK_MEM} #以上监控项, you can write the following configuration by templates.cfg: #系统负载define service { use generic-service host_name web01,web02,nagios01 service_description Current Load check_command check_nrpe!check_load} #磁盘I/odefine service { use generic-service host_name web01,web02,nagios01 service_description Disk I/O stat check_command check_nrpe!check_iostat!5!11}############## ##### Active monitoring ################### #PING监控define service { use generic-service host_name web01,web02,nagios01 service_description ping check_command check_ping!100.2,20%!500.0,60%}
4) Debug all configurations of Hosts.cfg and Service.cfg
[Email protected] etc]#/etc/init.d/nagios checkconfig #---Check syntax running configuration check ... Ok.
Second, summary
There are a lot of problems in the Nagios monitoring deployment process, and I am also studying nagios carefully. Blog posts about Nagios and Zabbix will continue to be updated
This article from "Linuxgao" blog, declined reprint!
Nagios monitoring infrastructure installation and monitoring item deployment (bottom)