With more than one NAT environment in the recent project, it is not very convenient to notify contact management if it is not ideal to deploy a complete set of Nagios (Nagios-core+apache+php+pnp4nagios) in each NAT, Then we'll start deploying Nagios distributed monitoring together.
Main Nagios Center Service deployment
I. Installation of Nagios
This step is skipped, specifically unclear can refer to a key script: http://www.sijitao.net/scripts
Second, install NSCA
Here I still use the very old version 2.7.2, the function is sufficient, stable on the line.
1, first run the following command:
# wget http://download.chekiang.info/nagios/nsca-2.7.2.tar.gz
# tar ZXVF nsca-2.9.1.tar.gz
# CD nsca-2.7.2
#./configure
# make All
After the run is completed, several files are generated in SRC, with executable programs NSCA, Send_nsca, and some configuration files, scripts.
# CP src/nsca/usr/local/nagios/bin/
# CP Sample-config/nsca.cfg/usr/local/nagios/etc
# chown Nagios.nagios/usr/local/nagios/bin/nsca
# chown Nagios.nagios/usr/local/nagios/etc/nsca.cfg
# CP Init-script/etc/init.d/nsca
# chmod A+x/etc/init.d/nsca
# UPDATE-RC.D NSCA Defaults
Because I am the Ubuntu system, NSCA Service script I remove the previous lines of check statements, or it will be an error.
2, modify the NSCA configuration file
# vi/usr/local/nagios/etc/nsca.cfg
password=123456
3, modify the Nagios configuration file
# vi/usr/local/nagios/etc/nagios.cfg
Check_external_commands=1 # Configure Nagios Check Extension command
Accept_passive_service_checks=1 # Configuration accepts the results of passive service detection
Accept_passive_host_checks=1 #配置接受被动主机检测的结果
4, check the problem after restart Nagios and start Nsca.
The program that NSCA receive data here is ready to be deployed.
Distributed Server Deployment
I. Installation of Nagios
You only need to install Nagios-core, and you do not need to install additional components.
Second, install Nsca-send
1, as with the Lord, run the following command first:
# wget http://download.chekiang.info/nagios/nsca-2.7.2.tar.gz
# tar ZXVF nsca-2.9.1.tar.gz
# CD nsca-2.7.2
#./configure
# make All
The above steps to check the correct execution will be in the SRC directory to generate two programs Nsca Send_nsca (main program), Sample-config will have nsca.cfg and send_nsca.cfg (configuration file).
2, modify the configuration file
# CP src/send_nsca/usr/local/nagios/bin/
# CP sample-config/send_nsca.cfg/usr/local/nagios/etc/
# chown Nagios.nagios/usr/local/nagios/bin/send_nsca
# chown Nagios.nagios/usr/local/nagios/etc/send_nsca.cfg
Modify the Send_nsca.cfg configuration and change the password.
# vi/usr/local/nagios/etc/send_nsca.cfg
password=123456
The password here needs to be the same as the Lord's.
3, modify the Nagios configuration file
Enable_notifications=0//prevent it from sending out any notification information directly
Obsess_over_services=1//configured as forced service (obsess over services) type
Ocsp_command=submit_service_check_result//Definition of a forced service processing (OCSP) command
Obsess_over_hosts=1//configured as forced service (obsess over host) type
Ochp_command=submit_host_check_result//define an forced host processing (OCHP) command
4. Add OCSP command
When adding the Submit_service_check_result command, you need to add the PerfData data so that the Nagios will be able to generate a picture after receiving the data Pnp4nagios.
# VI command.cfg
define command{
command_name submit_service_check_result
command_line $USER 1$/eventhandlers/submit_service_check_result $HOSTNAME $ ' $SERVICEDESC $ ' $ servicestate$ ' $SERVICEOUTPUT $ | $SERVICEPERFDATA $ [$SERVICECHECKCOMMAND $] '
}
define command{
command_name submit_host_ Check_result
command_line $USER 1$/eventhandlers/submit_host_check_result $HOSTNAME $ $ hoststate$ ' $HOSTOUTPUT $ '
}
5, add command script
# mkdir/usr/local/nagios/libexec/eventhandlers
# cd/usr/local/nagios/libexec/eventhandlers
# wget Https://raw.githubusercontent.com/zhangnq/nagios/master/setup/submit_host_check_result
# wget Https://raw.githubusercontent.com/zhangnq/nagios/master/setup/submit_service_check_result
# chmod +x/usr/local/nagios/libexec/eventhandlers/submit_host_check_result
# chmod +x/usr/local/nagios/libexec/eventhandlers/submit_service_check_result
Modify Submit_host_check_result and Submit_service_check_result two scripts in the Center Nagios monitor host IP or domain name, that is, modify www.chekiang.info for your own address.
6, check that there is no problem after the start Nagios.
Adding monitoring hosts and services
When you add monitoring, you need to be aware of:
1, the central server and the distribution server need to add monitored host and service.
2. The HOST_NAME value defined by the hub server host needs to be consistent with the HOST_NAME value defined by the distribution server host.
3. The service_description value defined by the Hub Server service needs to be consistent with the Service_description value defined by the distribution Server service.
A, distributed server
The distribution server's configuration increases and the active monitoring is same, first adds the host, then adds the server to be able.
Second, the central server
Based on the considerations mentioned above, the principle is that the hub server needs to be the same as the host_name and service_description of the distributed server. This allows the data to be displayed in the main nagios.
1, increase the passive mode of the host and service templates
Modify the Templates.cfg file to add something similar to the following:
# vi/usr/local/nagios/etc/objects/templates.cfg
Define Host{
Name Passive-host
Use Generic-host
Check_period 24x7
Check_interval 5
Retry_interval 1
Max_check_attempts 10
Check_command check-host-alive
Notification_period 24x7
Notification_interval 60
Notification_options D,u,r
Contact_groups Sysmaint
Register 0
Check_freshness 1; Define Force refresh Detection
Freshness_threshold 600; Specify when the service detection results should be refreshed, in S
Passive_checks_enabled 1; Turn on passive detection
active_checks_enabled 0; Close active monitoring
}
Define Service{
Name Passive-service
Use Generic-service
active_checks_enabled 0; Close active monitoring
Passive_checks_enabled 1; Turn on passive detection
flap_detection_enabled 0; off state jitter detection
Check_freshness 1; Define Force refresh Detection
Freshness_threshold 600; Specify when the service detection results should be refreshed, in S
Max_check_attempts 4
Normal_check_interval 5
Retry_check_interval 1
Register 0
Check_command Service-is-stale; Define execution commands for Force detection
}
2, increase the Force Detection command
Add script
# vi/usr/local/nagios/libexec/staleservice.sh
#!/bin/bash
/bin/echo "Critical:service results are stale!"
Exit 2
# chmod +x/usr/local/nagios/libexec/staleservice.sh
Add command
# vi/usr/local/nagios/etc/objects/commands.cfg
Define Command{
Command_name Service-is-stale
Command_line $USER 1$/staleservice.sh
}
3. Add host and Service
Copy hosts and servers from the distribution server to the Nagios hub server, modify the passive-host that defines the use template in the host as defined, before the default is generally linux-server, Modify the definition of the Passive-service that defines the use template in the server to define the Check_command value. Similar to the following:
Define Host{
Use Passive-host
HOST_NAME 10.22.127.100
Alias 10.22.127.100
Address 10.22.127.100
}
Define Service{
Use Passive-service,srv-pnp
HOST_NAME 10.22.127.100
Service_description Check SSH Login
}
4. Check reboot
Check that the Nagios configuration is correct after the addition is complete, and then reboot.
5, log
The log is generally in/usr/local/nagios/var/nagios.log, the normal words appear as follows, if there is a problem with the configuration can also find the reason through the log.
Summarize
The
Nagios distributed monitoring Service can add hosts from different network environments to a master monitoring platform. With the active monitoring mode, with the increase of the monitoring host, the server's performance requirements will be more and more high, distributed can effectively reduce the server pressure. However, Nagios+nsca distributed mode maintenance is troublesome and needs to maintain multiple Nagios configuration files.