Detailed explanation of Nagios installation and configuration under CentOS6.6
1. Install the environment
# Yuminstall-y gcc glibcglibc-common gd-devel xinetd openssl-devel httpd php
2. Set selinux
1. View The SELinux status:
#/Usr/sbin/sestatus-v # If The SELinux status parameter is enabled, it is enabled.
That is, SELinuxstatus: enabled
2 disable SELinux:
Temporarily shut down (no need to restart the machine ):
Setenforce 0 # Set SELinux to permissive Mode
# Setenforce 1 Set SELinux to enforcing Mode
To modify the configuration file, restart the machine:
Modify the/etc/selinux/config file, change SELINUX = enforcing to SELINUX = disabled, and then restart.
3. Create users and user groups
[Root @ Nagios-Server/] # useradd-s/sbin/nologin nagios
[Root @ Nagios-Server/] # mkdir/usr/local/nagios
[Root @ Nagios-Server/] # chown-R nagios. nagios/usr/local/nagios
Add nagios and apache users to the nagcmd group to ensure that nagios and apache have permissions.
# Groupadd nagcmd
# Usermod-G nagcmd nagios
# Usermod-G nagcmd apache
After that, copy the downloaded nagios compressed package to the/root/Downloads directory (if the package is manually downloaded directly on the webpage, the default storage location is also in the directory ), perform the following steps for compilation and installation:
# Tar-zxvf nagios-4.0.6.tar.gz
# Cd nagios-4.0.6
Initialize and build the compiling environment
#./Configure-prefix =/usr/local/nagios-with-command-group = nagcmd
# Make all
# Make install # install a binary file
# Make install-init # Initialization Script
# Make install-config # sample configuration file
# Make install-commandmode # Set Directory Permissions
If the installation is complete, run the following command: # ls/usr/local/nagios
You can see these directories (bin etc sbin share var) in the/usr/local/nagios Directory, which indicates that nagios is successfully installed.
After the installation is complete, do not rush to start nagios, because there are still some operations to be executed.
4. Install the web configuration file of nagios
# Make install-webconf
After the installation is complete, it is installed in the conf. d directory of Apache by default.
(The Apache service is httpd. We have installed it through yum at the beginning. In this version, httpd is integrated into the system, so you can install it directly .)
5. Use apache to create basic web page authentication methods
Use Basic Authentication in apache to create an admin user for logging on to the nagios web interface.
Remember the logon password you set, and the account and password of this user will be stored in the/usr/local/nagios/etc/passwd. users file. If you want to view it, you can only see the user, but the password is encrypted by MD5 and cannot be seen. What should I do if I forget my password.
# Htpasswd-c/usr/local/nagios/etc/htpasswd. users admin
After the main program of nagios is installed, the related apache configuration file is automatically put under/etc/httpd/conf. d/. The file name is nagios. conf and the content of the file is as follows:
This means that only authenticated users can access the content in the/usr/local/nagios/share directory and/usr/local/nagios/sbin directory through http. The authenticated user, admin, can restart apache to apply the Configuration:
# Service httpd restart
# Chkconfig-level 235 httpd on
6.nagiosplug-in install nagios-plugins-2.0.3.tar.gz
As mentioned earlier, the main Nagios program is only a control center. Many Nagios plug-ins can provide functions such as service monitoring and system monitoring. The Nagios system without plug-ins is actually just an empty shell. Therefore, after installing the Nagios platform, we also need to install the plug-in.
# Cd/root/Downloads
# Tar-zxvf nagios-plugins-2.0.3.tar.gz
# Cd nagios-plugins-2.0.3
#./Configure-prefix =/usr/local/nagios-with-nagios-user = nagios-with-nagios-group = nagios
# Make
# Make install
Then add nagios to the service list so that it can be automatically started when the system starts:
# Chkconfig-add nagios
# Chkconfig nagios on
7. Check the correctness of the configuration file and enable web Access
#/Usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios. cfg
If the final result is the same as the following, you can start the nagios service.
We also recommend that you use this command to check whether the configuration is correct after a large number of configuration files are modified.
Then start the nagios service.
# Service nagios start
Then you can access the link http: // 192.168.34.131/nagios/in the browser. If you can see the page normally, it indicates that the main program and plug-in are installed and configured successfully! Click the "Hosts" link to view the monitoring details of your local machine.
If the following error message is displayed on the monitoring page, modify the configuration file of nagios to fix it.
Vi/usr/local/nagios/etc/cgi. cfg
Find use_authentication = 1 # Change 1 to 0, and then save
Then restart the service: # service nagios restart
# service httpd restart
Then try again and the access will be OK.
If the web interface cannot be opened on your local computer, you may need to disable the firewall in linux. The command is as follows:
# Service iptables status view Firewall status
# Service iptables stop disable Firewall