Nagios is one of the most famous and used application, to check other servers in a network.
We can define hosts, and the services we need to monitor, in a ‘.cfg’ file. Once we are done with that, we can enter the IP of the machine on which we installed nagios followed by ‘/nagios’ i.e ‘192.168.0.100/nagios‘.
After authenticating, we will see a list of all the hosts, and their status. We can know which host is up, which is down, and which host has problems in which of its services. Nagios provides a detailed view of all the host and its services, including its up-time.
The main advantage and plus point of nagios is, you can check and monitor all the computers on your network in one single windows. It gives us warnings shows alerts, and tells us which of our servers are down. It also helps us detect problems.
You can install Nagios in Cent OS in two ways.
- By downloading its repo, and using YUM.
- By downloading its packages, extracting it and configuring them.
We will install via Second method. The first one is pretty simple. Download Nagios and nrpe using YUM, Edit the hosts. cfg file and enter the host names and IP addresses of host you want to monitor.
However Downloading its packages and configuring it is a very complex and lengthy process. We will see all the steps IN DETAIL. So this will be a very long post.
If you’re configuring Nagios for the first time, it will look confusing and difficult. But once you get through the installation, you’ll find it simple and straight-forward. You’ll know what to do next.
yum install httpd php gcc glibc glibc-common gd gd-devel make -y
Install all the dependencies.useradd -m nagios
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache
passwd nagios
Add a new user as ‘nagios’ , and new group as ‘nagcmd’. Add ‘nagios’ and ‘apache’ users to group ‘nagcmd’
Set a password fornagios user.mkdir /root/nagios
cd /root/nagios
Make a new directory namednagios. We will download all the files and extract them in this directory only.wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.1.tar.gz
wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
DownloadNagios package and its plugins package.- Check the downloaded files before extracting.
tar -zxvf nagios-4.0.1.tar.gz
ExtractNagios in the current folder.cd nagios-4.0.1
Once the tar fileis extracted, a folder would be created with the name ‘nagios-4.0.1’. Enter that directory../configure --with-group=nagcmd
make all
make install
Configure the package with group ‘nagcmd’. Then use ‘make all’. Only ‘make’ command won’t work. Then enter ‘make install’.make install-init
make install-config
make install-commandmode
These commands will install init scripts for nagios ( ‘init’ ) , install the sample nagios files ( ‘config’ ) and use nagios via
command line ( ‘commandmode’ ) .vi /usr/local/nagios/etc/objects/contacts.cfg
Open the ‘contacts.cfg’ file in ‘/etc/objects‘ directory of ‘nagios‘.
Edit the Email address of admin. Put your own Email address. The alerts would be directly sent to the admin.make install-webconf
htpasswd -c -s /usr/local/nagios/etc/htpasswd.users nagiosadmin
service httpd restart
First install the web interface for Nagios. A new user nagiosadmin would be created.
Set password for nagios admin using htpasswd. ‘-c‘ switch is used to create the ‘htpasswd.users‘ file, and ‘-s‘ is used too set its place, Then restart apache.cd ..
orcd /root/nagios
tar -zxvf nagios-plugins-1.5.tar.gz
Currently you’re in /root/nagios/nagios-4.0.1.
Come one directory up, that is to /root/nagios.
Now extract ‘nagios-plugins’.cd nagios-plugins-1.5
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
Once extracted a new folder would be created. Go in that folder, and run ./configure for user and group ‘nagios’ . Next run ‘make’ and ‘make install’./usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Verify your commands by running the above command.chkconfig --add nagios
chkconfig nagios on
Add nagios to Startup usingchkconfig./etc/init.d/nagios start
StartNagios.http://10.0.2.15/nagios
Enter in your browser ‘http://[ IP ]/nagios
Enter Username asnagiosadmin, and enter the password you gave in step 11.Note : Set Selinux in Permissive mode 🙂