Setup A Nagios Server On CentOS 6.2 | Linux Hangout

by Andrew on January 12, 2012 · 15 comments

in Hangouts

Post image for Setup A Nagios Server On CentOS 6.2 | Linux Hangout

Today we did a Linux hangout on Google+. During the hangout we discussed how to setup a Nagios core server on CentOS 6.2. Mike Weber shared his Nagios installation script and explained how it can install Nagios quite easily in about 3 minutes. This script is located down below the video on this page.

Special thanks to +Rich Gillin for hanging out live.

See upcoming Linux hangouts and a list of topics.

#!/bin/bash

# This script comes with no warranty ...use at own risk

# Copyright (C) 2010 Mike Weber

#

# This program is free software; you can redistribute it and/or modify

# it under the terms of the GNU General Public License as published by

# the Free Software Foundation; version 2 of the License.

#

# This program is distributed in the hope that it will be useful,

# but WITHOUT ANY WARRANTY; without even the implied warranty of

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

# GNU General Public License for more details.

#

# You should have received a copy of the GNU General Public License

# along with this program or from the site that you downloaded it

# from; if not, write to the Free Software Foundation, Inc., 59 Temple

# Place, Suite 330, Boston, MA 02111-1307 USA

#####################################################################

# The purpose of the script is to install Nagios and plugins using source.

# DESIGNED AND TESTED ON CENTOS 5.5

# Created September 21, 2010

# Modified November 26, 2010

# Modified March 14,2011

# Modified July 24, 2011 update to make compatible with CentOS 6

# Updated for Nagios 3.3.1 July 26 ,2011

# Tested on CentOS 6.2 Jan. 12, 2012

#####################################################################

 

# Script Must Run as root

if [[ $EUID -ne 0 ]]; then

echo "This script must be run as root" 1>&2

exit 1

fi

cd /usr/local/src

yum install -y wget

wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.3.1/nagios-3.3.1.tar.gz

wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz

yum install -y httpd php gcc glibc glibc-common gd gd-devel make mysql mysql-devel net-snmp

useradd nagios

groupadd nagcmd

usermod -a -G nagcmd nagios

tar zxvf nagios-3.3.1.tar.gz

tar zxvf nagios-plugins-1.4.15.tar.gz

cd nagios

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

make all

make install; make install-init; make install-config; make install-commandmode; make install-webconf

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

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

cd ..

cd nagios-plugins-1.4.15

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

make

make install

chkconfig --add nagios

chkconfig --level 3 nagios on

chkconfig --level 3 httpd on

exit 0

 

{ 15 comments }

Richard February 4, 2012 at 12:20 pm

Thanks a lot for the instructions and the script,
The install went perfectly, after install I did a set of password to get in the system
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

I can login to nagios but if I click on hosts I get:
Internal Server Error
The server encountered an internal error or misconfiguration …….

In the Var log I get:
Feb 4 20:12:36 richard nagios: SERVICE ALERT: localhost;HTTP;WARNING;SOFT;1;HTTP WARNING: HTTP/1.1 403 Forbidden – 5237 bytes in 0.009 second response time

So i’m getting close I think,

In the presentation you mention NagiosVI if i’m right, is that recommended for a dummy user :)

Thanks
Richard

Mike February 4, 2012 at 1:04 pm

The issue with theHTTP/1.1 403 Forbidden is because you do not have a index.html file in /var/www/html. Just do:

touch /var/www/html/index.html

That will stop that error.

Richard February 5, 2012 at 2:20 am

Thanks That solved it,
Unfortunatly I still get the following

[root@localhost bin]# ./nagios -v /usr/local/nagios/etc/cgi.cfg
Nagios Core 3.3.1
…….
Reading configuration data…
Error in configuration file ‘/usr/local/nagios/etc/cgi.cfg’ – Line 15 (UNKNOWN VARIABLE)
Error processing main config file!

Line 15 is main_config_file=/usr/local/nagios/etc/nagios.cfg

When I check this file no errors found :S

thanks Richard
r.tilman@ymail.com

Mike February 5, 2012 at 9:03 am

Here is the problem, I think.

This is incorrect:
nagios -v /usr/local/nagios/etc/cgi.cfg

You should process the nagios.cfg file instead.
nagios -v /usr/local/nagios/etc/nagios.cfg

The error is telling you that you are processing the wrong file.

John Milwak March 21, 2012 at 11:31 am

After doing this, where is the nagios www located ?

I have nothing related to nagios on my /var/www or /var/www/html.

Where should I point my browser to ?

Thanks.

Mike March 21, 2012 at 2:31 pm

Point your browser to http://ip_address/nagios

John Milwak March 22, 2012 at 4:34 am

Not Found

The requested URL /nagios was not found on this server.

How does httpd know where to find the nagios files ? It’s not done on the script.

Mike March 22, 2012 at 7:30 am

Yes, the script sets it all up. Make sure you have the web server running and Nagios with:

service httpd start
service nagios start

The web server knows about the files based on the information in /etc/httpd/conf.d/nagios.conf and the configuration that is set up with Nagios.

If you get the same error, check to see if you have nagios installed in /usr/local/nagios/etc.

What distro are you using? This script will only work with CentOS.

James March 22, 2012 at 11:02 pm

Thanks a lot for this – installation completed without any issues and no errors show up on verification.
CentOS release 6.2 (Final)

The homepage link works fine but when I click on any of the other items on the menu I get an error as:
Internal Server Error

Example of a framed link that shows this error is
http://localhost/nagios/cgi-bin/tac.cgi
I am guessing this is becuase the cgi-bin folder doesnt exist.
Do I need to make any vhost changes?

Thanks

James March 22, 2012 at 11:21 pm

Ok I realised that this file /etc/httpd/conf.d/nagios.conf ensures the vhost settings are correct, so I can only presume there is some permission issue?

James March 26, 2012 at 4:55 am

I have worked out that the issue is suexec won’t execute any cgi outside of predefined docroot of “/var/www/html” ( my docroot is set as under /home ). So that means I will have to install nagios into “/var/www/html” or recompile suexec. A temporary work around is copy the cgi files to “/var/www/html/nagios-cgi” and changed the scriptalias which works.

Brad March 27, 2012 at 6:42 pm

I’ve been working on a new server that will run Cacti, Nagios and IPPLAN.
I have Cacti installed and working.
I just installed your script but the Nagios is not accessable.
I started the network service and its running:
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

However I can not access the site. There is no var/www/html/nagios folder.

Running it on CentOS6.2
Linux localhost.localdomain 2.6.32-220.7.1.el6.i686 #1 SMP Tue Mar 6 21:21:22 GMT 2012 i686 i686 i386 GNU/Linux

Cacti-0.8.7i

Any help would be great

Brad March 27, 2012 at 6:50 pm

also…this was in var/log/messages:

Mar 27 21:27:05 localhost nagios: Nagios 3.3.1 starting… (PID=28600)
Mar 27 21:27:05 localhost nagios: Local time is Tue Mar 27 21:27:05 EDT 2012
Mar 27 21:27:05 localhost nagios: LOG VERSION: 2.0
Mar 27 21:27:05 localhost nagios: Finished daemonizing… (New PID=28601)
Mar 27 21:30:55 localhost nagios: SERVICE ALERT: localhost;SSH;CRITICAL;SOFT;1;Connection refused
Mar 27 21:31:55 localhost nagios: SERVICE ALERT: localhost;SSH;CRITICAL;SOFT;2;Connection refused
Mar 27 21:32:55 localhost nagios: SERVICE ALERT: localhost;SSH;CRITICAL;SOFT;3;Connection refused
Mar 27 21:33:55 localhost nagios: SERVICE ALERT: localhost;SSH;CRITICAL;HARD;4;Connection refused

Brad March 27, 2012 at 7:21 pm

I copied the files from /usr/local/nagios/share to /var/www/html/nagios

I get the MAIN Nagios screen but non of the CGI links are working.

Really lost

Brad March 28, 2012 at 6:18 am

Forget about it. I rebooted and it’s all working now. DUH!

Nice script guys…keep up the good work.

Previous post:

Next post: