Monday, February 14, 2011

How to install nagios in RHEL 5 or FEDORA



Install Nagios on RHEL5
Dependencies
* Install Apache and PHP
* GCC
* GD development lib
Create User Account

/usr/sbin/useradd -m nagios
passwd nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache

Build and Install Nagios Core

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.0.tar.gz
tar zxf nagios-3.2.0.tar.gz
cd nagios-3.2.0
./configure --with-command-group=nagcmd

make all
make install
# Installs the init script in /etc/rc.d/init.d
make install-init
# Installs and configures permissions on the directory for holding the external command file
make install-config
# Installs sample config files in /usr/local/nagios/etc
make install-commandmode

# Set contact email
vi /usr/local/nagios/etc/objects/contacts.cfg

# Install web interface
make install-webconf
# Create web interface account
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

# Restart Apache
/usr/local/apache2/bin/apachectl stop
/usr/local/apache2/bin/apachectl start
# Or
/sbin/service httpd restart

Compile and Install Nagios Plugins

wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz
tar zxf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

AutoStart/Start/Stop Nagios
 # Auto start Nagios
/sbin/chkconfig --add nagios
/sbin/chkconfig nagios on
# Check config file
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# Start/Stop Nagios
/etc/init.d/nagios stop
/etc/init.d/nagios start

Add host/router/switches to nagios
# To add node, uncomment respective cfg_file line in
/usr/local/nagios/etc/nagios.cfg

Example: if you want to monitor a switch then uncomment following line in nagios.cfg

cfg_file=/usr/local/nagios/etc/objects/switch.cfg

# Then go to /usr/local/nagios/etc/objects/
And open switch.cfg

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

There is an example of adding node. You can use that by copy/paste.

Access Web Interface
or

References