Installing Nagios 3.5 on CentOS 6.5 Minimal

Nagios
I’m in the middle of wrapping my head around a network I’ve inherited about one year ago. Honestly, I should have done this in the beginning but it’s better late than never.

Going into this network there was no monitoring in place. Nagios is a perfect tool for an environment with many services, links, servers, etc.

Here’s a little disclaimer: I’m not a Linux or Nagios guru. The following are from my own experiences and findings in my research. If you’d like to learn more about Nagios, I recommend reading Learning Nagios.

First, download CentOS Minimal and install it. I’m installing CentOS on VMware. Why CentOS Minimal? Because that’s all I need for this operating system, minimalism.

1. After you have CentOS installed, enable the eth0 interface

**Not familiar with vi? Here’s an external tutorial.**

vi /etc/sysconfig/network-scripts/ifcfg-eth0

Modify

ONBOOT=no

to

ONBOOT=yes

Add the following to the configuration file, fill the X’s to your IP configuration:

IPADDR=X.X.X.X
GATEWAY=X.X.X.X
NETMASK=X.X.X.X
NETWORK=X.X.X.X

Save the file and quit.

Now we need to restart the network service so this interface is enabled:

service network restart

2. This is about the time I connect to my virtual machine over ssh

Here are the packages we’ll have to install to complete the Nagios installation:

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

We’re installing Apache, PHP, GNU Compiler Collection, Standard C Library, graphics library, OpenSSL, file retriever, Perl, and Make.

3. Create the nagios user and set the password

/usr/sbin/useradd -m nagios
passwd nagios

The -m switch says to create the home directory if it doesn’t exist.

4. Create the nagios group, nagcmd, which will allow external commands to be submitted through the web interface. Then add the nagios user and apache user to the group

/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache

The usermod switches, -a -G, says to append the user to the nagcmd group.

5. Create a temp directory to place the nagios downloads

mkdir ~/downloads
cd ~/downloads

Download nagios:

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.0.tar.gz | wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

6. Extract the nagios tar ball

tar xzf nagios-3.5.0.tar.gz
cd nagios

7. Run the nagios script passing the nagcmd group

./configure --with-command-group=nagcmd

Take note of what gets spit out at the end. This is from my installation:

*** Configuration summary for nagios 3.5.0 03-15-2013 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
            Embedded Perl:  no
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/rc.d/init.d
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /bin/mail
                  Host OS:  linux-gnu

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/

8. Compile the nagios source code

make all

9. Install the binaries, init script, sample configs, and set permissions on external command directory

make install
make install-init
make install-config
make install-commandmode

Nagios is now installed but don’t start it yet.

10. The sample config files have been installed in the /usr/local/nagios/etc directory. Edit the /usr/local/nagios/etc/objects/contacts.cfg file and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.

vi /usr/local/nagios/etc/objects/contacts.cfg

11. Configure the web interface

make install-webconf

12. Create the nagiosadmin account for logging into the web interface

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

13. Restart Apache

service httpd restart

14. Compile and install the plugins

cd ~/downloads
tar xzf nagios-plugin (tab) #press the tab key to complete the command
cd nagios-plugins (tab)

15. Compile and install the plugins

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

16. Add nagios to the system services and have it start when system boots

chkconfig --add nagios
chkconfig nagios on

17. Verify the nagios configuration files

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

If there are no errors, start Nagios. If there are errors, you have some troubleshooting to do!

service nagios start

18. Find out if you have SELinux in Enforced mode

getenforce

If the value is on then you will need to follow step 19.

19. Most people will tell you to set the Enforce level to 0. This weakens the security of Linux. Instead, run the following commands to run the CGIs under SELinux enforcing/targeted mode

chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

20. Log into the nagios web interface

http://localhost/nagios

21. If you try to access the web interface remotely and the page doesn’t load, check to see if you have IPTABLES enabled

service iptables status

If you don’t see entries for port 80 and/or 443, then it is being denied.

Allow http and https services through IPTABLES:

vi /etc/sysconfig/iptables

Add the following entries:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

Resources

There are a couple of books if you want to get more in-depth with Nagios. I’ll admit that I am no where near being an expert on this topic. I am still learning myself.

Nagios: Building Enterprise-Grade Monitoring Infrastructures for Systems and Networks (2nd Edition) by David Josephsen

Nagios: System and Network Monitoring by Wolfgang Barth

Related Posts

About Rowell Dionicio

I am Rowell Dionicio, an IT Manager with a coffee addiction, an advocate of WordPress, with a passion about networking as a Cisco Champion, physical server assassin with virtualization, and a padawan of security. Follow me on Twitter & LinkedIn.

Comments

  1. Deepak S says:

    HI Rowell;

    I had installed nagios in my local system with the above steps. But while I am trying to execute “htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin” in my webserver it is showing an error “-bash: htpasswd: command not found”. can you please help me out in this request

  2. Hey Rowell

    You’ve forgot:
    # chkconfig httpd on

    in my case, the Nagios service cant access the nagios.cmd in /nagios/var/rw
    -> # chcon -R -t httpd_sys_script_rw_t /usr/local/nagios/var/rw

    Greetings from germany!

    Lukas

  3. Hi Rowell,

    I have followed all above steps. Everthing was going to good. but when i am browsing below link, it’s showing 403 Forbidden error.
    http://localhost/nagios

    Please suggest me.

    Manoj Gupta

  4. Satish Aiwale says:

    great !!!

  5. Satish Aiwale says:

    Hi,

    I need help,

    Did you know, how to configure MRGT with Nagios.

    Thanks,
    Satish

  6. after i followed the above steps. i am able to see only http page only instead of nagios.
    is there any changes needed on nagios.conf file(i means to say ip address entry OR host entry)etc.
    kindly suggest.

    Prash pUNE

  7. Yuvaraj N says:

    All i can say is “It is 100 % perfect.!”. Thanks dude

  8. Awesome guide, worked first time without issue. Hats off to you sir :-)

  9. Rowell,

    Great post it helped a lot. The only thing I did different was I saved the iptables at the end so when rebooting I didn’t have to add them again. Other than that worked great.

    Thanks

  10. selvakumar says:

    Thanks :)

    Please share NCONF, Nagios graph .. etc addional tool configuration page if u have

  11. Am installed nagios with the latest version, but getting the error ie “(No output on stdout) stderr: execvp(/usr/local/nagios/libexec/check_load, …) failed. errno is 2: No such file or directory” Can you help me for solving the same..???

  12. Srinivasan says:

    I got this output after make install “make[1]: Leaving directory `/opt/nagios’” can you give any suggestion to solve this

  13. Very very Nice job!!

  14. this a great tut… thanks, it help me

  15. Very good Awesome guide, worked first time without any problem. Hats off to you buddy,…..very, very good job….Just got one question since I am new to nagios….can you tell me how I can go by configuring stuffs like service,contact.cfg,centreon etc or basically how I can get nagios to start monitoring and sending alerts…..
    Thanks once again you really made my job easier

  16. whoa. this is great! shishishi. thanks!

  17. Hi, I was able to install nagios without any error. Problem is when I go to map, “The requested URL /nagios/cgi-bin/statusmap.cgi was not found on this server.”
    Please, I need assistance. Thank you!

  18. Hi, Sometimes happening “(No output on stdout) stderr: ” and sometimes it will be automatically cleared. What is that probelm?
    How to fix it permanently. Please help me.

    • Looks like there’s a syntax error. When do you receive that error?

      • Thank you for reply.
        Previously it (Nagios version 3.2.3) was worked fine. Then I un-installed Nagios version 3.2.3 and installed latest version 4.0.1. Sometimes showing currently. I couldn’t find when it is occurring.
        Please help me.

  19. skvenkates says:

    Thank you for reply.
    Previously it (Nagios version 3.2.3) was worked fine. Then I un-installed Nagios version 3.2.3 and installed latest version 4.0.1. Sometimes showing currently. I couldn’t find when it is occurring.
    Please help me.

  20. i m getting following error:-
    (No output on stdout) stderr: execvp(/usr/local/nagios/libexec/check_ping, …) failed. errno is 2: No such file or directory

  21. Make sure you turn off SElinux if running centos. This will cause the errno is 2: No such file or directory.

  22. What a great tutorial!! Everything just works fine without facing any issues! Thanks man!!

Leave a Reply