In this tutorial we will learn about how to install nagios 4.0.2 in Linux using tarball.Nagios is one of the famous and very robust Monitoring Server.The installation has been done in minimal installed CentOS 6.4.Recently Nagios team has released its much awaited 4.x version.The installation steps is applicable to other Nagios version also.

Details of Server:

Operating System : CentOS 6.4
Arch : x86_64
Nagios Version: 4.0.2
My Server IP address: 192.168.1.6

IPtables is stopped /etc/init.d/iptables stop
SELINUX is disabled

Follow the given below steps to install Nagios 4.x

Login to your Server by using root user

Step 1 : Install wget package for downloading the Nagios package through command line.

yum install wget

Step 2: Download Nagios package. You will get the Nagios package in tar format.

wget http://nchc.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.2/nagios-4.0.2.tar.gz

Step 3: Install the dependencies and apache server (httpd)

yum install   httpd php  gd gd-devel gcc glibc glibc-common openssl perl perl-devel make

Step 4: Now create the user and group for Nagios installation

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios

Step 5: Now extract the downloaded file. Here I downloaded the file called nagios-4.0.2.tar.gz (see in Step 2)


tar -xvzf nagios-4.0.2.tar.gz

Step 6: After extracting the downloaded nagios package.It will extract out the Nagios directory. Here we downloaded the package nagios-4.0.2.tar.gz, after extraction I got directory called nagios-4.0.2 .

Now change to extracted out Nagios directory . On using ls -la command you will see many files inside nagios-4.0.2 directory,these all files and directory will be used in installation. So we are going to compile the Nagios package.

cd nagios-4.0.2

./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

After running all above commands if you find no error now move to next step.

Now copy the eventhandlers directory into /usr/local/nagios/libexec/ as well as change ownership and group of this copied directory

cp -rvf contrib/eventhandlers/ /usr/local/nagios/libexec/

chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

Step 7: Now we will check nagios.cfg file configuration. Use the given below command for it. It should not show any error otherwise nagios service can not be started. You can use this command whenever you do any configuration change in nagios.cfg file.

Syntax: /usr/local/nagios/bin/nagios -v


/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Step 8: Now we set the htpasswd apache authentication for user nagiosadmin. This same username and password will be used when you will try to open nagios dashboard.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Step 9: Start the apache and nagios service

/etc/init.d/nagios start
/etc/init.d/httpd start

to bydefault service run in runlevel 3,4,5 use below given command

chkconfig nagios on
chkconfig httpd on

Step 10: Change the permission of file /usr/local/nagios/var/rw/nagios.cmd .(reference from this troubleshooting post)

chmod 666 /usr/local/nagios/var/rw/nagios.cmd

Install Nagios plugin from source

Now in this section we will install nagios plugin.Later you can also add some more nagios as per your requirement. I downloaded the plugin from this link

Follow the given below steps for nagios plugin installation

cd ~

wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz

tar -xvzf nagios-plugins-1.5.tar.gz

cd nagios-plugins-1.5

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make

make install 

Step 11: Now time to go to Nagios dashboard. Open the web browser in address link type your server ip address appending /nagios.
Now give username nagiosadmin password which you have set in Step 9

My Nagios server ip address is 192.168.1.6 hence replace the ip address with your server ip

http://192.168.1.6/nagios

After login you will get your Nagios dashboard (See the screenshot)

nagios

Read Some More Articles

10 Comments

    1. Thankyou Micheal,

      Glad to know , the post helped you.
      I would also like to thank to you for mentioning Nagios Version. This information will help other reader

      With Regards
      Sharad

  1. Hi Sharad, Nice tutorial. With Respect to Step 10, there is something i need to share. With Nagios 4.0.4, in order to sort out the rw permission issue i sorted it out by issuing “sudo chown -R nagios:apache /usr/local/nagios/var/rw/”. Because “chmod 666 /usr/local/nagios/var/rw/nagios.cmd” is not sorting the issue.

  2. Hi! Sharad,

    I could not open the nagios dashboard while trying to open http://localhost/nagios , it is asking for username and password.

    By entering username: nagiosadmin and password (according to the your step:8), again showing authentication required (username and passwd). I could not login.

    Can you please guide?

  3. Nagios is running fine for the nagios server machine, but is not reflecting info of other servers which it needs to monitor. I’m not getting any errors. My SELinux and iptable have been disabled. Please help.

    1. Hello Gourab,

      For monitoring remote machine ,you have to install nrpe client in remote machine. I have written a documentation .I hope it will help you , How to install and configure NRPE in CentOS .
      Because we have installed Nagios from tarball, use the Nagios base directory /usr/local/nagios instead of /etc/nagios/ (/etc/nagios/ path I have given in this previous tutorial)

      For Debian/Ubuntu machine, use this tutorial , https://sharadchhetri.com/2013/06/11/how-to-install-and-configure-nagios-nrpe-client-in-ubuntu-with-apt-get-command/

  4. Hi Sharad
    I think something is missing as I get this error in Apache error_log :
    Directory index forbidden by Options directive: /usr/local/nagios/share/
    After looking in Google, I find that php was missing : yum install httpd mod_php, service nagios/httpd restart and everything work’s fine.
    Could you clarify this ?
    Thanx.
    Bob

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.