Difficulty Level : 4 out of 5
Ever heard of Nagios, Zabbix, Cacti or even Icinga? If I name it, you probably heard it. These are the famous monitoring tools for IT Infrastructure today and, majority of them are built for one intention, to monitor your infrastructure be it Servers, Network Switches and Routers or even printers. They are really famous out there because they are actually free or licensed under GPL/GNU GPL which means you can actually study, share or even improve it should you have the capability to do so.The topic I cover today would be Nagios Core IV, do not get confused with another product Nagios XI, in fact both of them are by the same developer and one is intended for enterprise that pays and it is not cheap though. It is ever important skill for an IT professionals to learn about the implementation of these tool into their existing system, remember that the monitoring can always be automated in any day now but the implementation will be not at any time now.
Have a look at the link below should you want to know more about what Nagios XI offers. https://www.nagios.org/downloads/nagios-core/
I would say Nagios Core itself is suffice for majority of the system administrator out there and Nagios XI would be the icing on top of the cake as it provides better interfaces and report functionality and of course the support.
I have made this guide into 7 steps, the topic will covers the installation of Nagios CORE, Nagios Plugin (the library of feature for the CORE) and NRPE plugins (the plugin used for monitoring).
Step 1 :
Prepare your server you want Nagios CORE to be
installed with. Make sure the server come ready with LAMP (Linux, Apache,
MySQL, PHP). You can install of of them by using yum install for Red-Hat/Centos or
apt-get for Debian/Ubuntu.
i. Create a user 'nagios'
- sudo useradd nagios
ii. Create a group 'nagcmd'
- sudo groupadd nagcmd
iii. Make the user part of the group created
- sudo usermod -a -G nagcmd nagios
* For learners, I suggest you to build the LAMP stack on your own local machine. Should you need any guidance in it please write in to me and I will try to help you out. You may run it in virtual machine as well with VMWare Workstation Player.
Step 2 :
Before we go for Nagios installation, make sure
we have all the dependencies needed for NagiosCore (NC). The usual requirement
for NC is as follow :
build-essential
libgd2-xpm-dev openssl libssl-dev xinetd apache2-utils unzip
- You can use yum or apt-get to install them
* Some people may experience problem running yum or apt-get. Do not worry, it is likely that your network is blocked with a firewall or even your school or company is blocking them. Try to use proxy instead and do Google it out.
Step 3 :
Installing NagiosCORE. Start by downloading
NagiosCORE from the link below :
Just get any latest version you can find and of course like all Linux admin does, choose the [Stable] one.
Extract the NagiosCore in a directory (temporary
for installation use)
- tar xvf nagios-*.tar.gz
Change to the directory
- cd nagios-*
Set up Email server before using Nagios
You can use PostFix / EXIM or SMTP servers. I recommend you use PostFix (/usr/bin/mail) for the ease of mind. Same
thing you can install it by using yum install mailutils or apt-get install
mailutils.
Lets build the configuration file by running the
command below, you can see I added a parameter '--with-mail=/usr/sbin/sendmail'
because i wanted to use PostFix, remove it or change it if you wanna use the other one.
- ./configure --with-nagios-group=nagios
--with-command-group=nagcmd --with-mail=/usr/sbin/sendmail
After configuration is done the script actually
generates some file inside this directory with all the configuration specified.
You can run this next to compile them.
- make all
This will compile the NagiosCore. Next we need to
initiate all the Nagios script by running the command below :
sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
sudo /usr/bin/install -c -m 644
sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
Depending on your apache group and user. You will
next need to set the apache user to the group of nagios by running the
following :
- sudo usermod -G nagcmd
www-datawww-data is for my vanilla Apache2 ... It might be different in your environment and do check them out.
Step 4 :
Installing Nagios Plugin
Just like step 3, we download the Nagios Plugin
this time round. You can use curl -L -O or wget. Its up to you.
Link : http://nagios-plugins.org/download/nagios-plugins-xxxxx.tar.gz
<-- get latest version
Extract it
- tar xvf nagios-plugins-*.tar.gz
Change to the directory
- cd nagios-plugins-*
Configure the plugin
- ./configure --with-nagios-user=nagios
--with-nagios-group=nagios --with-openssl
(This will configure the nagios plugin with the
nagios user and their group)
Compile it
- make
Install It
- sudo make install
Its done for plugin, PLUGIN is not for monitoring
yet. Plugin is just the library for the NagiosCORE. Next we talk about
NRPE or the monitoring part..
Step 5
Installing NRPE
NRPE is the part used by NagiosCore for
monitoring the server. In this scenario, we will setup the NC to monitor
ourself (localhost). Just like Step 3 and Step 4, download the NRPE from the
link in a temporary directory u want.
Same thing, lets get the latest and stable
Extract it
- tar xvf nrpe-*.tar.gz
Change to Directory
- cd nrpe-*
Configure it
- ./configure --enable-command-args
--with-nagios-user=nagios --with-nagios-group=nagios
--with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu
Build and Compile
make all
sudo make install
sudo make install-xinetd
sudo make install-daemon-config
Let's modify the xinetd file after that, you
might need to install xinetd yourself in case you dont see one. Can be done
with yum or apt-get. Xinetd should be at the following path :
sudo nano /etc/xinetd.d/nrpe
Look for the portion "only_from = [IP
Address]
modify it by adding your own IP address into this
section wiith (comma ,) if you want more IP.
Remember to Save and Exit it.
Restart xinetd service now with sudo service
xinetd restart (systemctl might be needed if your on RHEL 7.x)
Now Nagios 4 Core , Plugin, NRPE is installed !
Step 6
Configuring Nagios now with our server
environment.
Open your Nagios Configuration file for editing.
- sudo nano /usr/local/nagios/etc/nagios.cfg
Locate this section
#cfg_dir=/usr/local/nagios/etc/servers
* This is actually the
path to your configuration file for Nagios to know where can I read the server
configuration. Uncomment it so that nagios will be ready to use this config file. Remember to Save and Exit.
Now create a directory based on the config file
path you set above. In this case :
- sudo mkdir /usr/local/nagios/etc/servers
* Remember how Exabytes set each server a config
file, its for this purpose.
Next, you will configure the Contact Email for
your NC
- sudo nano
/usr/local/nagios/etc/objects/contacts.cfg
* Look for the section email and change it to
your Email Address (default is nagios@localhost)
Next, configure the check_nrpe.
This is useful in order to check your NRPE
version (the monitoring plugin). One of the service we want to monitor. You can
of course ignore it if you want to.
Edit the file : - sudo nano
/usr/local/nagios/etc/objects/commands.cfg
Add in the following at the end :
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$
-c $ARG1$
}
Save and Exit
Configure Apache
Yes, its lengthy process but Apache will need to be setup
as well since we are using the web interface to view Nagios. (eg. www.pikachuben.com/nagios).
Make sure Apache rewrite and cgi is enabled.
- sudo a2enmod rewrite
- sudo a2enmod cgi
Create a user you want to use for nagios
monitoring, in my case nagiosadmin
- sudo htpasswd -c
/usr/local/nagios/etc/htpasswd.users nagiosadmin
(Put a password you can remember when it prompts
you and please remember it)
Take note
if you want to use other user, you will need to modify every section in the
file /usr/local/nagios/etc/cgi.cfg)
Create a symbolic link for nagios.conf to the
site-enabled directory. ( This is for debian/ubuntu since the Apache works a bit
different) Skip this part if your on Redhat/Centos
- sudo ln -s
/etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/
Lets start nagios and restart apache to take
effect !
- sudo service nagios start
- sudo service apache2 restart
To setup NAgios to start when boot
_ sudo ln -s /etc/init.d/nagios
/etc/rcS.d/S99nagios
Basically your Nagios is ready to kick now, you
can access to pikachuben.com/nagios and try to login now !
For Redhat / Centos
- You do not need to make site-available symbolic
link actually since Apache works differently in Centos/Redhat. Just run the
following :
- sudo systemctl daemon-reload
- sudo systemctl start nagios.service
- sudo systemctl restart httpd.service
To make nagios start during boot
- sudo chkconfig nagios on
Done for RedHat !
Step 7
Monitoring a remote Host
Go to the server
you want to monitor. Install both the following with yum or apt-get
- nagios-plugins
- nagios-nrpe-server
Modify the following file after the installation
above.
sudo nano /etc/nagios/nrpe.cfg
Find this section "allowed_host"
Add in the IP address of your remote server like
this allowed_hosts=127.0.0.1,[Your_NAGIOSCORE_IP_ADDRESS]
Save and Exit
Now lets try to monitor the disk !
type this
- df -h /
You will see your disk name most likely /dev/vda
or /dev/sda or others.
Open up this file /etc/nagios/nrpe.cfg
Look for these section : server_address /
allowed_hosts / command[check_hda1]
Change the /dev/hda1 to the disk name above where
u see ur actual disk name is. Do not change the front part [check_hda1].
Change the server_address to your own server IP
address (your current server IP not the nagios core server)
Change the allowed_hosts to your NAGIOS CORE
server IP address.
After
that, restart the NRPE by using
sudo service nagios-nre-server restart
You probably ask what
are you doing now. To make it simple to understand, you are actually creating a
NRPE plugin for the server right now. This command can then be called from the
main NAGIOS core server which will be explained next. Some feature do not need
these custom call at all. PING is special you don't need to set it up. Others yes like HTTPD, EXIM etc etc.
NOW you will need to go to your NAGIOS Core
server and setup the monitoring based on what you have done in the host server
(host = the server you want to monitor and the NRPE you just setup there)
- Go to the following path :
/usr/local/nagios/etc/servers/
* Remember this path we created early on for the
preparation of any future server? Now you will use it.
Create a cfg file here, use the server name which you are monitoring for
more convenient, you can use anything though. In my case, theorionsbelt.cfg
Add the following into it
define host {
use
linux-server
host_name [Your_remoteserver_name]
alias [Just a name for your remote server]
address [Remote server IP Address]
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
host_name [Your_remoteserver_name]
alias [Just a name for your remote server]
address [Remote server IP Address]
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}
This portion is needed because it will define
which is the remote host you wanna monitor. Look at the parameter. You need to
modify it based on what the remote server is.
Take note that the notification interval and period controls how frequent the notification is being sent out.
If you want to monitor Ping, you can add the
following line on the bottom of the same file
define service {
use
generic-service
host_name yourhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
host_name yourhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
This will monitor Ping
Remember the NRPE we made just now ? You can build the same thing here creating a new function based on it.
define service {
use generic-service
host_name yourhost
service_description PING
check_command check_nrpe!checkhda1
host_name yourhost
service_description PING
check_command check_nrpe!checkhda1
}
Notice the check_command section follow by
check_nrpe
Do not modify check_command.
check_nrpe is used to initiate to tell core to go
and look for the nrpe.cfg file in the remote server, then check_hda to tell the
core to look at the command for check_hda1 which I tell you not to change it
earlier on.
To take effect after the change, you just restart
it with sudo service nagios reload
Login to your web interface next and VOILA ...
Ping and DISK monitoring is there !!!!
MISSION ACCOMPLISHED !
For windows
monitoring you need NSClient++
The post have no image yet, will most likely upload them soon. I used to work with a company running on Nagios system and the reliability of this software is definitely good. Majority of my work today covers in Compute Virtualization. As a system administrator or system architect, it is always crucial for you to setup monitoring tools for your subordinates and the team.
Prepared and written by Ruben.Rubin.Ruban.Reuben.Rubun(?).


No comments:
Post a Comment