nagios Red hat linux Shell scripting

How to Install Nagios 4.3.4 on RHEL / CentOS

Nagios is an awesome Open Source monitoring tool, its provides you more comprehensive monitoring environment to always keep an eye on your all machines / networks whether you are in a your data center or just your small labs.

CentOS6-Nagios6

With Nagios, you can monitor your remote hosts and their services remotely on a single window. It shows warnings and indicates if something goes wrong in your servers which eventually helps us to detect some problems before they occur. It helps us to reduce downtime and business losses.

Download Nagios:
nagios-4.2.4.tar.gz
nagios-plugins-2.2.1.tar.gz
nrpe-2.13.tar.gz

## Create nagios user, add nagios and web server users to the nagios group
adduser nagios
mkdir /usr/local/nagios
chown nagios.nagios /usr/local/nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd daemon
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd [APACHE USER]
/usr/sbin/usermod -G nagcmd nagios
./configure --prefix=/usr/local/nagios --with-cgiurl=/nagios/cgi-bin --with-htmurl=/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf

Include Ngios config file to apache

ll /etc/httpd/conf.d/
mv /etc/httpd/conf.d/nagios.conf /usr/local/apache2/conf/extra/
vim /usr/local/apache2/conf/httpd.conf

go to the bottom of the page and insert as below

# Nagios Configuration
Include c/etc/httpd/conf.d/nagios.conf

Create password for “nagiosadmin” user

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

Restart apache and start nagios

service httpd restart
service nagios restart

Install Nagios Plugins

tar xzf nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1
./configure
make
make install
chown -R nagios.nagios /usr/local/nagios/libexec

Set auto start to nagios and apache services

chkconfig --list | grep httpd
chkconfig --level 345 httpd on
chkconfig --list | grep nagios
chkconfig --add nagios
chkconfig --list | grep nagios

usermod -a -G nagios apache – [mks_highlight color=”#81d742″]permanent fix for Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update![/mks_highlight]

Installing Plugins and NRPE on Remote Linux Host

adduser nagios
tar -xzf nagios-plugins-1.4.6.tar.gz
cd nagios-plugins-1.4.6
./configure
make
make install
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec

Installing NRPE without xinetd on Nagios Host and Remote Host

./configure --enable-ssl
make all
make install-plugin
make install-daemon
make install-daemon-config
install init-script /etc/init.d/nrpe

Configure NRPE

#vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,,

#/etc/init.d/nrpe start

#vim /etc/services
nrpe            5666/tcp                        # NRPE

#chkconfig --list | grep nrpe
#chkconfig --add nrpe
#chkconfig --list | grep nrpe

===check nrpe===	
#/usr/local/nagios/libexec/check_nrpe -H localhost
#/usr/local/nagios/libexec/check_nrpe -H 

===Allow NRPE from IPtables====
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT

===Add check_nrpe command to commands.cfg====
vi /usr/local/nagios/etc/commands.cfg
define command{
		command_name check_nrpe
		command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
		}

Veryfing nagios config

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

Enable external cgi commnds

#vim /usr/local/nagios/etc/cgi.cfg
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
#vim /usr/local/nagios/etc/nagios.cfg
check_external_commands=1

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *