SoFunction
Updated on 2025-04-09

Detailed explanation of Nagios remote monitoring installation and configuration pictures and texts page 2/3


Configuration
Configuration is the most complex part of nagios. It involves the configuration of multiple files. For the sake of easy description, configuration is carried out one by one here.
1. Apache configuration
We complete this configuration in two steps. The first step is to modify the apache configuration file, the file path here is /usr/local/apache/conf/ . Change the run user [1] and run group of apache into nagios, and append the following line to the end of the file:
#setting for nagios
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
//Cgi file directory
   AuthType Basic
   Options ExecCGI
   AllowOverride None
   Order allows,deny
   Allow from all
   AuthName "Nagios Access"
   AuthUserFile /usr/local/nagios/etc/htpasswd //verify file path
   Require valid-user
Alias /nagios /usr/local/nagios/share
//nagios page file directory
   AuthType Basic
   Options None
   AllowOverride None
   Order allows,deny
   Allow from all
   AuthName "nagios Access"
   AuthUserFile /usr/local/nagios/etc/htpasswd //verify file path
   Require valid-user
The function of the above text block is to verify the directory of nagios. Only legal authorized users can access the page files of nagios. The second step is to generate the user verification file: just execute the command/usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/htpasswd sery, the web legal access user serial will be generated; the commands are executed interactively, and the password needs to be entered twice, and then a line is written in the file /usr/local/nagios/etc/htpasswd - the first field is the user name just generated, and the second is the encrypted password. If more users are to be added, the option "-c" is required to execute the command htpasswd, otherwise all generated lines will be overwritten.
After the configuration is completed, execute/usr/local/apache/bin/apachctl –tCheck whether there are syntax errors in the apache configuration file, and use it after correct/usr/local/apache/bin/apachctl start &Start apache, and then enter the access address of nagios from the browser of another machine (such as:http://ip/nagios), If it is normal, the login verification window in the figure below will appear waiting for user input:

Enter the username and password created with htpasswd to test it. If there is no problem, proceed to the next configuration operation.
2. Nagios configuration
The directory of the configuration file for nagios that has just been installed is /usr/local/nagios/etc. The following figure is the file of its etc directory:

First change the name of these files, such as -sample to , and use the command cp -sample... to copy the remaining several *.cfg-samples into *.cfg files. Starting from nagios version 2.6, you can run it directly without modifying the configuration file../bin/nagios –v Verify whether the program can run normally (the minimum running configuration file of nagios 2.5 and previous versions is, but you need to modify this file many times to verify it successfully). Of course, we cannot expect this smallest configuration file to meet actual needs. Therefore, it is necessary to modify the existing configuration file, followed by adding some custom configuration files. Here, we will proceed in two steps: first modify the configuration file and then add custom files.
1. Modify the configuration file
The main configuration file of Nagios is, let's start modifying it from this file. Edit with vi, comment the line #cfg_file=/usr/local/nagios/etc/[2], and then remove the comments from the following lines:

cfg_file=/usr/local/nagios/etc/ //Contact group configuration file pathcfg_file=/usr/local/nagios/etc/    //Contact profile pathcfg_file=/usr/local/nagios/etc/   //Host group configuration file pathcfg_file=/usr/local/nagios/etc/     //Host configuration file pathcfg_file=/usr/local/nagios/etc/    //Service configuration file pathcfg_file=/usr/local/nagios/etc/  //Monitoring time period configuration file path
Change check_external_commands=0 to check_external_commands=1. This line is used to allow the execution of operations such as restarting nagios, stopping host/service checks in the web interface. Change the value of command_check_interval from the default 1 to command_check_interval=10s (set the time interval for this command to check according to your own situation, do not be too long or too short). These are basically what you need to change the main configuration file. Through the above modification, it is found that /usr/local/nagios/etc does not have any files, etc. What should I do? Create them manually later.
The second configuration file to be modified is that its function is to control the relevant CGI scripts. Make sure use_authentication=1 first. I have read a lot of articles, and they all recommend setting the value of use_authentication to "0" to cancel the verification, which is a very bad idea. Next, modify default_user_name=sery, and the subsequent modifications are listed in the following table:
authorized_for_system_information=nagiosadmin,sery 
authorized_for_configuration_information=nagiosadmin,sery
authorized_for_system_commands=sery //Separate multiple users with commasauthorized_for_all_services=nagiosadmin,sery
authorized_for_all_hosts=nagiosadmin,sery
authorized_for_all_service_commands=nagiosadmin,sery
authorized_for_all_host_commands=nagiosadmin,sery
So where did the above username be called? Execute the command /usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/htpasswd seryFor the generated, you should pay attention to this. You cannot add any verification users that do not exist. For the sake of security, do not add too many verification users.
The third configuration file modified is that the main function of this file is to send alarm text messages and alarm emails. The modifications to them are as follows:
#host-notify-by-sms //Send SMS Alarmdefine command {
    command_name   host-notify-by-sms
    command_line   /usr/local/bin/sms_send "Host $HOSTSTATE$
alert for $HOSTNAME$! on '$DATETIME$' " $CONTACTPAGER$ } #service notify by sms //Send SMS Alarmdefine command { command_name service-notify-by-sms command_line /usr/local/bin/sms_send "'$HOSTADDRESS$'
$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" $CONTACTPAGER$ }
Mail alarm notifications for hosts and services are already in the file and do not need to be changed. You can also write configuration blocks such as SMS and Email Alarm Notifications to a file, and the effect is the same.
Previous page123Next pageRead the full text