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
Tags: Nagios
January 15th, 2009 at 4:27 am
This is great! Thanks a lot. And yes: I know, I should have updated the passwords at first…
April 13th, 2009 at 8:25 am
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
June 17th, 2009 at 8:52 pm
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
August 13th, 2009 at 4:33 am
Very nice script! I’ve not tried, but the comments are promising! Will leave some feedback soon.
September 10th, 2009 at 1:35 am
nice script … can u please send me how to install NRE plugins and how to configure servers with nagios..
Thanks in advance .,,
September 24th, 2009 at 6:15 pm
Nicely done, however looks like nagios-plugins is 404′ing…
January 31st, 2010 at 12:37 pm
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.
February 5th, 2010 at 5:42 pm
@Colin -> Fixed. thanks
– Ryan Lowe
March 5th, 2010 at 9:33 am
Nice script
Can anyone share the script on installation of NSCA pluging on nagios and how it can monitor Solaris servers
June 14th, 2010 at 12:03 am
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!