1.Nagios Introduction
Nagios is a powerful network monitoring tool, it can effectively monitor the Windows, Linux, UNIX host status and router switch network settings, printer work status, and the status of abnormal services in a timely manner in the form of mail, MSN SMS, such as the first time to notify the administrator. Because it is a follow GPLV2 open-source network monitoring software, with its excellent performance low cost of use, by the vast numbers of users.
2. Installation Prerequisites
2.1 determine if the following components are available:
GCC glibc glibc-common gd gd-devel xinetd openssl-devel
Proc-devel Pcre-devel Perl Libxml2-devel
Install directly from Yum:
Yum install-y gcc glibc glibc-common gd gd-devel xinetd openssl-devel proc-devel pcre-devel perl libxml2-devel
3. Installing Nagios,nagios-plugin
Create Nagios Users
# AddUser Nagios
Installing Nagios
# tar XVF Nagios-cn-3.2.0.tar
# CD nagios-cn-3.2.0
#./configure–prefix=/usr/local/nagios
# make All
# make Install
# Make Install-init
# Make Install-commandmode
# Make Install-config
Installing Nagios-plugin
# tar XVF nagios-plugins-2.0.tar.gz
# CD nagios-plugins-2.0
#./configure–prefix=/usr/local/nagios
# Make && make install
4. Installing Apache
# tar XVF httpd-2.4.9.tar.gz
#cd httpd-2.4.9
#./configure--prefix=/usr/local/apache2
# Make && make install
If installation prompts are missing APR and Apr-util package
#tar XVF apr-1.5.0.tar.gz
#cd apr-1.5.0
#./configure–prefix=/usr/local/apr
#make && make Install
#tar XVF apr-1.5.0.tar.gz
#cd apr-1.5.0
#./configure–prefix=/usr/local/apr-util–with-apr=/usr/local/apr
#make && make Install
Install Apache after installation
#./configure--prefix=/usr/local/apache2–with-apr-util=/usr/local/apr-util
#make && make Install
5. Install PHP
#tar XVF php-5.4.10.tar.gz
#cd php-5.4.10
#./configure--prefix=/usr/local/php--with-apxs2=/usr/local/apache2/bin/apxs
#make && make Install
6. Configure Apahe
Locate the Apache configuration file/usr/local/apache2/conf/httpd.conf
Found it:
User Daemon
Group Daemon
Revision changed to
User Nagios
Group Nagios
And then find
<ifmodule dir_module>
DirectoryIndex index.html
</IfModule>
Revision changed to
<ifmodule dir_module>
DirectoryIndex index.html index.php
AddType application/x-httpd-php. php
</IfModule>
For security reasons, it is generally necessary for Nagios's web monitoring pages to be authorized for access, which requires an additional authentication configuration, i.e. the following information is added at the end of the httpd.conf file:
#setting for Nagios
Scriptalias/nagios/cgi-bin "/usr/local/nagios/sbin"
<directory "/usr/local/nagios/sbin" >
AuthType Basic
Options execcgi
AllowOverride None
Order Allow,deny
Allow from all
AuthName "Nagios Access"
authuserfile/usr/local/nagios/etc/htpasswd
Require Valid-user
</Directory>
Alias/nagios "/usr/local/nagios/share"
<directory "/usr/local/nagios/share" >
AuthType Basic
Options None
AllowOverride None
Order Allow,deny
Allow from all
AuthName "Nagios Access"
authuserfile/usr/local/nagios/etc/htpasswd
Require Valid-user
</Directory>
Create Apache directory validation files
#/usr/local/apache2/bin/htpasswd-c/USR/LOCAL/NAGIOS/ETC/HTPASSWD SSAP
7. Launch Apache and Nagios
Launch Apache
#/usr/local/apache2/bin/apachectl Start
Start Nagios
Service Nagios Start
Nagios Login
Nagios Home
8. Configure Nagios
After the Nagios installation is complete, you need to configure Nagios, which is under the/usr/local/nagios/etc directory.
File name or directory name |
Use |
Cgi.cfg |
Control the configuration file for CGI access |
Nagios.cfg |
Nagios Master configuration file |
Resource.cfg |
A variable definition file, also known as a resource file, defines variables in some files so that they can be referenced by other configuration files, such as $user1$ |
Objects |
Objects is a directory with many profile templates in this directory that define the Nagios object |
Objects/commands.cfg |
Command definition configuration file, where defined commands can be referenced by other configuration files |
Objects/contacts.cfg |
Define profiles for contacts and contact groups |
Objects/localhost.cfg |
Define a configuration file that monitors the local host |
Objects/printer.cfg |
Define a profile template for the monitoring printer, which is not enabled by default |
Objects/switch.cfg |
Define a profile template for the monitoring router, which is not enabled by default |
Objects/templates.cfg |
Defines a template configuration file for hosts and services that can be referenced in other configuration files |
Objects/timeperiods.cfg |
Define the configuration file for the Nagios monitoring time period |
Objects/windows.cfg |
Monitor a profile template for a Windows host that is not enabled by default |
Assuming that we have Nagios installed on a server with IP 192.168.195.136 and need to monitor the 192.168.195.136 server, the following modifications will be made to the configuration file:
Modify Localhost.cfg
Define Host{
Use Linux-server
HOST_NAME Nagios-server
Alias Nagios-server
Address 127.0.0.1
}
Define Hostgroup{
Hostgroup_name linux-servers
Alias Linux Servers
Members Nagios-server
}
Define Service{
Use Local-service
HOST_NAME Nagios-server
Service_description PING
Check_command check_ping!100.0,20%!500.0,60%
}
Define Service{
Use Local-service
HOST_NAME Nagios-server
Service_description Root Partition
Check_command check_local_disk!20%!10%!/
}
Define Service{
Use Local-service
HOST_NAME Nagios-server
Service_description Current Users
Check_command check_local_users!20!50
}
Define Service{
Use Local-service
HOST_NAME Nagios-server
Service_description Total Processes
Check_command check_local_procs!250!400! Rszdt
}
Define Service{
Use Local-service,srv-pnp
HOST_NAME Nagios-server
Service_description Current Load
Check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
Define Service{
Use Local-service
HOST_NAME Nagios-server
Service_description Swap Usage
Check_command check_local_swap!20!10
}
Define Service{
Use Local-service
HOST_NAME Nagios-server
Service_description SSH
Check_command Check_ssh
notifications_enabled 0
}
Define Service{
Use Local-service
HOST_NAME Nagios-server
Service_description HTTP
Check_command check_http
notifications_enabled 0
}
New Hosts.cfg
Define Host{
Use Linux-server
HOST_NAME Test-linux
Alias Test-linux
Address 192.168.195.137
}
New Service.cfg
Define Service{
Use Local-service
HOST_NAME Test-linux
Service_description check-host-alive
Check_command check-host-alive
}
Modify Nagios.cfg
Add configuration file Hosts.cfg,service.cfg
Cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
Cfg_file=/usr/local/nagios/etc/objects/service.cfg
Detection of modified configurations
/usr/local/nagios/bin/nagios–v/usr/local/nagios/etc/nagios.cfg
Restart the Nagios service after detection is correct
Service Nagios Restart
Nagios Monitoring page
Precautions:
1) If the user name set is not nagiosadmin, there will be a permissions problem, you cannot access the monitoring page, you need to modify the cgi.cfg, after nagiosadmin append the user name set.
Nagios Logon User Rights configuration
2) Nagios garbled problem
The main is that Apache does not open CGI scripts for the sake of access to the main Apache configuration file httpd.conf;
#LoadModule Cgid_module modules/mod_cgid.so;
#LoadModule Actions_module modules/mod_actions.so;
Remove the # 2 lines above and reboot Apache to be OK.
CentOS deployment Nagios+apache for server monitoring