Wednesday, March 12, 2014

The Great Nagios Adventure

Do you know the answer to the following questions for the Servers you support? Is my server up or down? Is the hard drive space filling up? What is the CPU load? Is the website actually displaying? Well if you don't know the answer to these questions you should. How do you do it you ask? The answer is Nagios.. Nagios is an open source web app running on linux that can monitor multiple servers in your network. I have been using Nagios for several years, but recently had to actually install and configure it for the first time. The installation is very easy, but depending on your environment, the set up and configuration can be tricky.


You can get the Nagios files here. If you are a DIY guy like me then you want to download the Nagios Core version. This the free Open source version.. There are other paid support versions as well. 

So .. this is how it goes.. step by step. 

1.Get the Prerequisites. You need the following packages already installed.
a.       Apache
b.      PHP
c.       GCC Compiler
d.      GD Development Libraries
Yum can be used to install each one as seen below.
yum install httpd php
yum install gcc glibc glibc-common
yum install gd gd-devel

2.      Account Setup
a.       First make sure you are using root permissions.
                                                              i.      Su –
b.      Create the Nagios Account and give it a password.
                                                              i.      /usr/sbin/useradd -m nagios
                                                            ii.      passwd nagios

c.       Create a new nagios nagcmd group for allowing external commands used via the web ui. Add the nagios user and the apache user to this group.

/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache

3.      Get the Nagios Core Install and Plugins
a.       Create and navigate to a download directory
                                                              i.      mkdir ~/downloads
b.      Navigate to /downloads
                                                              i.      cd /downloads
4.      Get the files downloaded into the directory

5.      Install Nagios
a.       First uncompressed the downloaded files
                        i.   tar xzf nagios-4.0.4.tar.gz
                      ii.   tar xzf nagios-plugins-2.0.tar.gz

b.      Navigate to the Nagios core file folder
                        i.   cd /nagios-4.0.4
c.       Run the Nagios Configure Script including the New Group Name
                                                              i.      ./configure --with-command-group=nagcmd
d.      Compile Nagios Core
                                                              i.      make all
e.       Install it all
                                                              i.      make install
                                                            ii.      make install-init
                                                          iii.      make install –config
                                                          iv.      make install –commandmode


Don't start Nagios yet - there's still more that needs to be done... 



6) Customize Configuration 



Sample configuration
files have now been installed in the /usr/local/nagios/etc
directory. These sample files should work fine for getting started with Nagios.
You'll need to make just one change before you proceed... 



Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with
your favorite editor and change the email address associated with the nagiosadmin
contact definition to the address you'd like to use for receiving alerts. 



 
vi /usr/local/nagios/etc/objects/contacts.cfg
 
7) Configure the Web Interface Install the Nagios web config file in the Apache conf.d directory.
 
make install-webconf
 
Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account - you'll need it later.
 
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
 
Restart Apache to make the new settings take effect.
 
service httpd restart
 
Note: Consider implementing the ehanced CGI security measures described here to ensure that your web authentication credentials are not compromised. 8) Compile and Install the Nagios Plugins Extract the Nagios plugins source code tarball.
 
cd ~/downloads
 
tar xzf nagios-plugins-1.4.11.tar.gz
 
cd nagios-plugins-1.4.11
 
Compile and install the plugins.
 
./configure --with-nagios-user=nagios --with-nagios-group=nagios
 
make
 
make install
 
9) Start Nagios Add Nagios to the list of system services and have it automatically start when the system boots.
 
chkconfig --add nagios
 
chkconfig nagios on
 
Verify the sample Nagios configuration files.
 
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
 
If there are no errors, start Nagios.
 
service nagios start
 
10) Modify SELinux Settings Fedora ships with SELinux (Security Enhanced Linux) installed and in Enforcing mode by default. This can result in "Internal Server Error" messages when you attempt to access the Nagios CGIs. See if SELinux is in Enforcing mode.
 
getenforce
 
Put SELinux into Permissive mode.
 
setenforce 0
 
To make this change permanent, you'll have to modify the settings in /etc/selinux/config and reboot. Instead of disabling SELinux or setting it to permissive mode, you can use the following command to run the CGIs under SELinux enforcing/targeted mode:
 
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
 
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
 
For information on running the Nagios CGIs under Enforcing mode with a targeted policy, visit the Nagios Support Portal or Nagios Community Wiki. 11) Login to the Web Interface You should now be able to access the Nagios web interface at the URL below. You'll be prompted for the username (nagiosadmin) and password you specified earlier.
 
http://localhost/nagios/
 
Click on the "Service Detail" navbar link to see details of what's being monitored on your local machine. It will take a few minutes for Nagios to check all the services associated with your machine, as the checks are spread out over time. 12) Other Modifications Make sure your machine's firewall rules are configured to allow access to the web server if you want to access the Nagios interface remotely. Configuring email notifications is out of the scope of this documentation. While Nagios is currently configured to send you email notifications, your system may not yet have a mail program properly installed or configured. Refer to your system documentation, search the web, or look to the Nagios Support Portal or Nagios Community Wiki for specific instructions on configuring your system to send email messages to external addresses. More information on notifications can be found here.  You're Done Congratulations! You sucessfully installed Nagios. Your journey into monitoring is just beginning.

No comments:

Post a Comment