Install and Configure Nagios on CentOS 7
Install and configure NAGIOS on CentOS 7
Let see about NAGIOS,
Nagios is an open source monitoring system,It was designed with core components to run on the Linux operating system and can monitor devices running Linux, Windows and Unix Operating systems.
Nagios runs periodic checks on critical parameters of application, network and server resources.
Nagios can monitor, for example, memory usage, disk usage, microprocessor load, the number of currently running processes and log files.
Nagios also can monitor services, such as Simple Mail Transfer Protocol (SMTP), Post Office Protocol 3 (POP3), Hypertext Transfer Protocol (HTTP) and other common network protocols.
Active checks are initiated by Nagios, while passive checks come from external applications connected to the monitoring tool.
Working structure of Nagios
Nagios is organized as a pluggable, open source tool, which makes it easy to develop new components for it and to extend its functionality. At the heart of Nagios is its server, where plug-ins and add-ons allow the user to define targets and which parameters on these targets to monitor.
Lets move to installing and configuring Nagios.
Prerequisites for installing
- Server with CentOS 7 – 64bit
- Root Privileges on the server
Before Installing Nagios, Make sure you have updated your server to latest kernals and modules.
To update your server use,
# yum -y update
After successful update reboot your server to update new kernal.
Step 1 – Disable Selinux
To disable selinux, use
# setenforce 0
You can see the result as
[root@webhostingchennai ~]# setenforce 0 setenforce: SELinux is disabled [root@webhostingchennai ~]#
then run the below commands
# sed -i 's/enforcing/disabled/' /etc/sysconfig/selinux # sed -i 's/enforcing/disabled/' /etc/selinux/config
Once it was done, you will need to install some basic prerequisite packages for Nagios.
# yum install gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget unzip nano -y
Step 2 – Installing Apache and PHP
Now, let install Apache webserver and PHP
We have already discussed this topic in previous post, Click here and refer steps 3 and 4.
Step 3 – Adding a Nagios user
Now, we have to add a Nagios user to our system, along with nagcmd, so that Nagios and Apache can be integrated together.
# useradd nagios # groupadd nagcmd # usermod -a -G nagcmd nagios # usermod -a -G nagcmd apache
Step 4 – Installing and Configuring Nagios
Now, we can proceed with the installation of Nagios.
# cd /tmp # wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.1.tar.gz # wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
Unzip the Nagios archive you downloaded and use the script inside to install the program.
# tar -zxvf nagios-4.2.1.tar.gz
Go to the nagios dir
# cd nagios-4.2.1/
Configure before make
# ./configure --with-command-group=nagcmd
Make all necessary files for Nagios
# make all # make install # make install-init # make install-config # make install-commandmode # make install-webconf
Now, open the contact file in your favorite text editor and change the enclosed email address to your own.
# nano /usr/local/nagios/etc/objects/contacts.cfg
Navigate to “nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******”
and modify nagios@localhost to your email address and save the file.
Now, set the password that you can use to access Nagios.
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
[root@webhostingchennai nagios-4.2.1]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Type your password Re-type new password: Re-type your password Adding password for user nagiosadmin [root@webhostingchennai nagios-4.2.1]#
Now, you can unzip and install the Nagios plugins from the second archive you have downloaded.
# cd /tmp # tar -zxvf nagios-plugins-2.1.2.tar.gz # cd nagios-plugins-2.1.2/ # ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl # make # make install
To be a safer side, let check our config file has no errors.
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Your output should be as follows,
[root@webhostingchennai nagios-plugins-2.1.2]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Nagios Core 4.2.1 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 09-06-2016 License: GPL Website: https://www.nagios.org Reading configuration data... Read main config file okay... Read object config files okay... Running pre-flight check on configuration data... Checking objects... Checked 8 services. Checked 1 hosts. Checked 1 host groups. Checked 0 service groups. Checked 1 contacts. Checked 1 contact groups. Checked 24 commands. Checked 5 time periods. Checked 0 host escalations. Checked 0 service escalations. Checking for circular paths... Checked 1 hosts Checked 0 service dependencies Checked 0 host dependencies Checked 5 timeperiods Checking global event handlers... Checking obsessive compulsive processor commands... Checking misc settings... Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check [root@webhostingchennai nagios-plugins-2.1.2]#
As a final step, we need to start up Nagios and Apache daemons.
# systemctl start httpd.service # service nagios start
Now access, http://your_server_ip/nagios and enter the username and password you have configured at Step 4
Now, you can configure your monitoring system as you need.
Hope, this post helps your need. Please share your valuable comments to improve us.
For installing cacti : Click Here