This guide is for setting up the Nagios monitoring software along with NagiosQL for easy web configuration on a RHEL6 platform. I use Nagios for server monitoring because it’s free, open source, and very reliable. NagiosQL really helps take the pain out of manual Nagios configuration. As usual, this guide assumes a fresh RHEL6 installation with default package options and all updates applied from RHN. Also, make sure this server is subscribed to the RHEL Server Optional channel in RHN as we need packages installed from that channel. One more thing, turn off SELinux by editing /etc/selinux/config and setting it to disabled or permissive. Then you will need to reboot to apply the change. I really tried to get this going with SELinux, but I honestly just don’t know enough to fix the problems that NagiosQL had.
First, you will want to head over to the nagios.org and download the latest Nagios Core package and the Nagios Plugins package. And then head over to nagiosql.org and grab the latest stable package from there. You should end up with three different .tar.gz packages.
Now, we will install some pre-requisite packages from RHN and create the nagios user/group with the following commands as root:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
yum -y install httpd php gcc gd-devel postgresql-devel mysql-devel openssl-devel net-snmp perl-Net-SNMP mod_ssl mysql-server php-mysql php-pecl-ssh2
The next few commands create the nagios user and group. Run as root:
useradd -m nagios
echo MyPass | passwd --stdin nagios
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
Next, you want to change to the directory where you downloaded your nagios packages and run the following commands to unpackage, compile, and install them:
tar -xvzf nagios-3*gz && tar -xvzf nagios-plug*gz && tar -xvzf nagiosq*gz
cd nagios && ./configure --with-command-group=nagcmd --localstatedir=/var/nagios --sysconfdir=/etc/nagios && make all && make install
make install-init && make install-config && make install-commandmode && make install-webconf
cd ../nagios-plugin* && ./configure --with-nagios-user=nagios --with-nagios-group=nagios && make && make install
cd ../ && mv nagiosql /var/www/html && chcon -R -t httpd_sys_content_t /var/www/html/nagiosql/ && chown apache /var/www/html/nagiosql/config
mkdir /etc/nagiosql /etc/nagiosql/hosts /etc/nagiosql/services /etc/nagiosql/backup /etc/nagiosql/backup/hosts /etc/nagiosql/backup/services
chmod 775 /etc/nagios && chmod 664 /etc/nagios/cgi.cfg /etc/nagios/nagios.cfg && chgrp nagcmd /etc/nagios /etc/nagios/nagios.cfg /etc/nagios/cgi.cfg /etc/nagios/resource.cfg
chmod -R 6755 /etc/nagiosql && chown -R apache.nagios /etc/nagiosql && chown -R apache.apache /var/www/html/nagiosql/config
chown nagios.nagcmd /usr/local/nagios/bin/nagios && chmod 750 /usr/local/nagios/bin/nagios
chown -R nagios.nagcmd /var/nagios/rw && chgrp nagcmd /var/nagios/spool/checkresults
The next command will setup your nagiosadmin user and password, you will use this to login to the web interface, run as root:
htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
Next, we need to make a change by opening up /etc/php.ini with our favorite editor and searching for date.timezone, find the line that looks like this:
and replace it with something like this:
date.timezone = America/Chicago
Replace America/Chicago with your own timezones country/city.
Now, we will start up the apache, nagios, and mysql services, set them to startup on reboot.
chkconfig httpd on && chkconfig nagios on && chkconfig mysqld on && service httpd start && service nagios start && service mysqld start
iptables -I INPUT -p tcp --dport 80 -j ACCEPT && iptables -I INPUT -p tcp --dport 443 -j ACCEPT && service iptables save
Now, point your browser to http://yourserversip/nagiosql and click START INSTALLATION.
On the next page, you should have all green checks except for one yellow exclamation point about a config file that will be created automatically, if this is what you have, then click Next in the lower right corner.
On this page, leave the database stuff alone unless you want to change the database name, username, password, or if you set a password on the mysql root user. In the NagiosQL User Setup you will want to type in a password that you will use to login as the admin user on the NagiosQL site and then type it a second time in the next box. You also want to check Import Nagios sample config. Then click Next again.
This page should have nothing but green words indicating that things went well. If not look back and see if you missed a step. Now you will want to delete the install directory, so back at the command line, run this command as root:
rm -rf /var/www/html/nagiosql/install
Then, click Finish in the lower right corner, which will bring you to a login screen for NagiosQL, login with the username admin and the password that you specified for the admin user.
Now, we need to make some modifications to the /etc/nagios/nagios.cfg file to point the config files to the path for NagiosQL. Use the following commands for this:
cp /etc/nagios/nagios.cfg /etc/nagios/nagios.cfg.bck && sed -i 's/cfg_file/#cfg_file/g' /etc/nagios/nagios.cfg
The line above comments out current cfg_file locations, the lines below adds new ones(make sure to copy/paste whole thing at once)
cfg_file=/etc/nagiosql/serviceextinfo.cfg" >> /etc/nagios/nagios.cfg
At this point, you should be able to login to NagiosQL at http://yourserversip/nagiosql with the username admin and the password you provided earlier when setting up NagiosQL. After you successfully login, go to Tools > Nagios control. Then click all the Do It buttons from top to bottom and verify you do not get any errors. Then, you can access your Nagios web interface at http://yourserversip/nagios to see that it is working.
At this point, NagiosQL is setup to manage Nagios properly. In the next post, I will go over how to use NagiosQL to configure Nagios hosts and services.