| Subcribe via RSS

Nagios3 on CentOS: Quick Install Script

January 3rd, 2009 Posted in Random Tech

As part my job, I find myself doing Nagios installs on a somewhat regular basis. The following is a quick guide on installing Nagios 3 on CentOS, distilled from the official Nagios docs. It is meant to be copied and run as a shell script (you should only have to update the passwords):

#!/bin/sh

# Any Failing Command Will Cause The Script To Stop
set -e

# Treat Unset Variables As Errors
set -u

echo "***** Starting Nagios Quick-Install: " `date`
echo "***** Installing pre-requisites"
yum -y install httpd
yum -y install gcc
yum -y install glibc glibc-common
yum -y install gd gd-devel

echo "***** Setting up the environment"
useradd -m nagios
echo "INSERT_PASSWORD_HERE" |passwd --stdin nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

echo "***** Getting the Nagios Source and Plug-Ins"
cd /usr/local/src
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.0.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz
tar xzf nagios-3.2.0.tar.gz
tar xzf nagios-plugins-1.4.14.tar.gz

echo "***** Installing Nagios"
cd /usr/local/src/nagios-3.2.0
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

echo "***** Setting up htpasswd auth"
htpasswd -nb nagiosadmin INSERT_PASSWORD_HERE > /usr/local/nagios/etc/htpasswd.users
service httpd restart

echo "***** Setting up Nagios Plug-Ins"
cd /usr/local/src/nagios-plugins-1.4.14
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

echo "***** Fixing SELinux"
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

echo "***** Starting Nagios"
chkconfig --add nagios
chkconfig nagios on
service nagios start

echo "***** Done: " `date`

Hope you find this useful!

* EDIT: 2009-09-07 – Updated link to get Nagios 3.2.0
* EDIT: 2009-10-14 – Updated link to get Nagios Plugins 1.4.14

Share and Enjoy:
  • Digg
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • Technorati
Tags:

10 Responses to “Nagios3 on CentOS: Quick Install Script”

  1. Veit Says:

    This is great! Thanks a lot. And yes: I know, I should have updated the passwords at first… ;-)


  2. Morgan Says:

    I have run the script, but my website has an all text version of the pages. The sorting has text to click on instead of up and down arrows. Is this a result of the CentOS package the is installed or am I just missing some Perl module? Additional information: Acroread cannot run due to missing library.

    Thanks


  3. IP_Slinger Says:

    Great Timesaving Script… Thanks!
    I did have to execute the following to move beyond the dreaded http whoops error by manually starting the daemon. the restarted the service

    /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
    [root@xxxxxx]# service nagios restart


  4. The IT Guru Says:

    Very nice script! I’ve not tried, but the comments are promising! Will leave some feedback soon.


  5. Aman Says:

    nice script … can u please send me how to install NRE plugins and how to configure servers with nagios..

    Thanks in advance .,,


  6. Luke Sheldrick Says:

    Nicely done, however looks like nagios-plugins is 404′ing…


  7. Colin jack Says:

    Nice script once updated – certainly makes life easier.
    Needs matching plugins versions though :)

    wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz
    tar xzf nagios-plugins-1.4.13.tar.gz

    Thanks for making this available.


  8. rlowe Says:

    @Colin -> Fixed. thanks

    – Ryan Lowe


  9. Linu Says:

    Nice script
    Can anyone share the script on installation of NSCA pluging on nagios and how it can monitor Solaris servers


  10. dav Says:

    Thankyou for publishing this!!!

    You are a legend. I have been looking for something like this for ages. Why more people do not do this is beyond me.

    I just installed this for CentOS 5.5 (after updating the script to get the latest Nagios versions) and it all went very smoothly.

    Two things though..
    1) There is a typo,
    echo “***** Setting up Nagios Plug-Ins”
    cd /usr/local/src/nagios-plugins-1.4.13
    needs to be…
    echo “***** Setting up Nagios Plug-Ins”
    cd /usr/local/src/nagios-plugins-1.4.14

    and 2) I also had to do the following commands to get it to work after installing…
    /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
    [root@xxxxxx]# service nagios restart

    Thanks a million for posting this. It’s been stickied!


Leave a Reply