Let us discuss the overview, installation and configuration of Nagios, a powerful open source monitoring solution for host and services.
I. Overview of nagios
II. 8 steps for installing nagios on Linux:
- Download the nagios and plugins
- Take care of the prerequisites
- Create user and group for nagios
- Install nagios
- Configure the web interface
- Compile and install nagios plugins
- Start Nagios
- Login to web interface
III. Configuration files overview
I. Overview of Nagios
.
Nagios is a host and service monitor tool. Following are some of the features of nagios.
- Monitor equipments such as servers, switches, routers, firewalls, power supply etc.
- Monitor services such as disk space, cpu usage, memory usage, temperature of the equipment, HTTP, Mail, SSH etc.
- Nagios can monitor pretty much anything. for e.g. host, services, databases, applications etc.
- Nagios has an extensible plugin interface for monitoring user defined services. There are lot of plugins available for Nagios. Visit NagiosPlugins and NagiosExchange for review the available user developed plugins.
- It can send out various notifications ( email, pager etc.) when the problem occurs and get resolved.
- Web interface to view current status, notifications, problem history, log files etc.
Following is a partial screenshot of the nagios web dashboard:
II. 8 steps for installing nagios on Linux:
1. Download the nagios and plugins
Download following files from Nagios.org and move to /home/downloads
- nagios-3.0.1.tar.gz
- nagios-plugins-1.4.11.tar.gz
2. Take care of the prerequisites
- Make sure apache is working on the server by verifying from browser: http://localhost
- Verify whether gcc is installed
[root@localhost]#rpm -qa | grep gcc gcc-3.4.6-8 compat-gcc-32-3.2.3-47.3 libgcc-3.4.6-8 compat-libgcc-296-2.96-132.7.2 compat-gcc-32-c++-3.2.3-47.3 gcc-c++-3.4.6-8
- Verify whether GD is installed
[root@localhost]# rpm -qa gd gd-2.0.28-5.4E
3. Create user and group for nagios
[root@localhost]# useradd nagios [root@localhost]# passwd nagios [root@localhost]# groupadd nagcmd [root@localhost]# usermod -G nagcmd nagios [root@localhost]# usermod -G nagcmd apache
4. Install nagios
[root@localhost]# tar xvf nagios-3.0.1.tar.gz [root@localhost]# cd nagios-3.0.1 [root@localhost]# ./configure --with-command-group=nagcmd [root@localhost]# make all [root@localhost]# make install [root@localhost]# make install-config [root@localhost]# make install-commandmode
Following are some additional parameters that you can pass to ./configure to customize your installation. I used only --with-command-group as shown above.
--prefix /opt/nagios Where to put the Nagios files --with-cgiurl /nagios/cgi-bin Web server url where the cgi's will be available --with-htmurl /nagios Web server url where nagios will be available --with-nagios-user nagios user account under which Nagios will run --with-nagios-group nagios group account under which Nagios will run --with-command-group nagcmd group account which will allow the apache user to submit commands to Nagios
At the end of the configure output, it will display a summary as shown below:
*** Configuration summary for nagios 3.0.1 05-28-2008 ***: General Options: ------------------------- Nagios executable: nagios Nagios user/group: nagios,nagios Command user/group: nagios,nagcmd Embedded Perl: no Event Broker: yes Install ${prefix}: /usr/local/nagios Lock file: ${prefix}/var/nagios.lock Check result directory: ${prefix}/var/spool/checkresults Init directory: /etc/rc.d/init.d Apache conf.d directory: /etc/httpd/conf.d Mail program: /bin/mail Host OS: linux-gnu Web Interface Options: ------------------------ HTML URL: http://localhost/nagios/ CGI URL: http://localhost/nagios/cgi-bin/ Traceroute (used by WAP): /bin/traceroute
5. Configure the web interface.
[root@localhost]# make install-webconf [root@localhost# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin
6. Compile and install nagios plugins
[root@localhost]# tar xvf nagios-plugins-1.4.11.tar.gz [root@localhost]# cd nagios-plugins-1.4.11 [root@localhost]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios [root@localhost]# make [root@localhost]# make install
Note: On Red Hat, the ./configure command mentioned above did not work and was hanging at the when it was displaying the message: checking for redhat spopen problem… Add –enable-redhat-pthread-workaround to the ./configure command as a work-around for the above problem as shown below.
[root@localhost]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
7. Start Nagios
- Add the nagios to the startup routine:
[root@localhost]# chkconfig --add nagios [root@localhost]# chkconfig nagios on
- Verify to make sure there are no errors in the nagios configuration file:
[root@localhost]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check
- Start the nagios
[root@localhost]# service nagios start Starting nagios: done.
8. Login to web interface
Nagios Web URL: http://localhost/nagios/
Use the userid, password that was created from step#5 above.
III. Configuration files overview
.
The first configuration to modify is to change the default value of email address in /usr/local/nagios/etc/objects/contacts.cfg file to your email address.
Following are the three major configuration files located under /usr/local/nagios/etc
- nagios.cfg – This is the primary Nagios configuration file where lot of global parameters that controls the nagios can be defined.
- cgi.cfg – This files has configuration information for nagios web interface.
- resource.cfg – If you have to pass some sensitive information (username, password etc.) to a plugin to monitor a specific service, you can define them here. This file is readable only by nagios user and group.
Following are the other configuration files under /usr/local/nagios/etc/objects directory:
- contacts.cfg: All the contacts who needs to be notified should be defined here. You can specify name, email address, what type of notifications they need to receive and what is the time period this particular contact should be receiving notifications etc.
- commands.cfg – All the commands to check services are defined here. You can use $HOSTNAME$ and $HOSTADDRESS$ macro on the command execution that will substitute the corresponding hostname or host ip-address automatically.
- timeperiods.cfg – Define the timeperiods. for e.g. if you want a service to be monitored only during the business hours, define a time period called businesshours and specify the hours that you would like to monitor.
- templates.cfg – Multiple host or service definition that has similar characteristics can use a template, where all the common characteristics can be defined. Use template is a time saver.
- localhost.cfg – Defines the monitoring for the local host. This is a sample configuration file that comes with nagios installation that you can use as a baseline to define other hosts that you would like to monitor.
- printer.cfg – Sample config file for printer
- switch.cfg – Sample config file for switch
- windows.cfg – Sample config file for a windows machine
I will discuss about the steps to configure a remote Linux Host and Windows Host for monitoring through nagios in upcoming posts.
Best Nagios Book
Nagios Core 3 eBook – I’ve been using Nagios for several years, and I can sleep peacefully at night knowing that Nagios is monitoring all my systems and will warn me about any potential issue, before it becomes critical. I strongly recommend that you read Nagios Core 3 ebook to gain detailed understanding on Nagios. Since Nagios is free software, spending few dollars on the book can be the best investment you can make.
Awesome Nagios Articles
Following are few awesome Nagios articles that you might find helpful.
Comments on this entry are closed.
I cant find any documentation about how to add further hosts. i have nagios running, monitoring the local host and another pc, using the localhost.cfg and windows.cfg file. How to add more hosts? I tried to create another file and declared it in the nagios.cfg file but doesnt work. any ideas?
I think you missed a command. Step 4 should also include “make install-init” otherwise step 7 will fail. Otherwise perfect post, thank you! Saved me a bit of hair pulling. 🙂
There are also very useful quick start guides for Fedora, openSUSE and Ubuntu in the Nagios documentation 🙂
Hi, I had configured the windows.cfg file for one server. How do I configure for multiple servers?
Thank u so much for nice article.It is very understandable.
i configured nagios . when i was starting the NAGIOS service it is showing the error like unrecgnised service can u help me what is the service for nagios
waiting for reply
What does chkconfig –list | grep nagios show? If it shows nothing you need to go through the install guide again and check all the steps.
Thanks I have successfully configured nagios by reading the above. but before trying this i installed through rpm which failed.
I configured Nagios no errors and warnings.But when i tried to start the Nagios service its saying “unrecognized service Nagios” .Please help me out in this issue..
“make install-init” chould be added to step 4 in RHEL.Otherwise its not working step 7 fails.I dont know about the other distros.
Thanks for the wonderful post.
For installation on Ubuntu server see: https://help.ubuntu.com/9.10/serverguide/C/nagios.html
Thanks I have successfully configured nagios but i got some error
(( (13)Permission denied: exec of ‘/usr/local/nagios/sbin/statusmap.cgi’ failed, referer: http://10.35.29.100/nagios/side.php
[Fri Mar 05 15:46:44 2010] [error] [client 10.35.45.116] Premature end of script headers: statusmap.cgi, referer: http://10.35.29.100/nagios/side.php))
I got a solution for this error here is the udpate. pelase run this command.
#chcon -R system_u:object_r:httpd_sys_script_exec_t /usr/local/nagios/sbin
it will solve the problem.
Once again thanks.
Hi i got 403 forbidden error for nagios like::::
You don’t have permission to access /nagios/ on this server.
Apache/2.2.3 (Red Hat) Server at localhost Port 80
can any one help me please?
Thanks for the great post!!!
Just would like to add you will need to restart httpd before you start nagios
Dear Sir
I am daily visitor of your your great site and also i am getting your daily newsletters on my mail.i am a big fan of yours.
Please sir include some other post in nagios like monitoring MySql
for
•connection-time
•keycache-hitrate
•qcache-hitrate
•tablecache-hitrate
•threadcache-hitrate
•tmp-disk-tables
your configuration steps for all topics are very clear.
I hape you will consider my request.
Thanks
Hi,
I am getting the below error. Anyone help me to sort it out.
*************************************************************************************
Forbidden
You don’t have permission to access /nagios/cgi-bin/ on this server.
Apache/2.2.3 (Oracle) Server at 10.12.68.57 Port 80
*************************************************************************************
Appreciate your response asap.
Thanks in advance…,
Hi, it’s not working.
i did as per your instruction, but still http://localhost/nagios/ not opening in ocal syste.
please help on this.
Please note that php is also the prerequisite for nagios to work.
Verify you have PHP installed and enabled. Verify index.php is listed
as a DirectoryIndex within httpd.conf or conf.d/php.conf (depending on
your OS/distribution)
Its great, i dont have words for you, you explain every step v.well.
Dear Sir
Could you help me out with steps of notification of email and sms and for plotting graps
How do i setup Nagios to monitor websites on the Internet and alert if they are not reachable, Please assist with the steps to setup this as i have tried them but not successfully with it.
sir,
Thank you very much,
the installation steps are very clear,
i did as u wrote,
service nagios start also working
but in the browser
http://localhost/nagios/
showing
The requested URL /nagios was not found on this server.
Apache/2.2.3 (Red Hat) Server at localhost Port 80
,
please help me,
thanks in advance,
Hi,
I am getting the error “500 Internal Server Error” after login.
Can you please help me out.
Thanks in Advance.
Hi,
How to add multiple hosts in the nagios server.
Hi
Can you help me out, how to install nagios on windows.where can i get this software.
Hello I`d like to know if nagios has some type of documentation, guide or installation manual in spanish?
Sir,
thank u very mach,
Can you provide me the installation step in RHEL5.5
YOU can provide me the step-by-step installation guide of nagios
To establish the Nagios Service
first we have to use this command make install-init before chkconfig –add nagios
Thanks it works 🙂
Ramesh,
I tried to install nagios in centos 5.6 but i get access denied message when i enter :
http://localhost/nagios/
so what i did was i installed php :
then entered the following command as root user:
yum install php
/usr/sbin/setenforce 0
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
/sbin/service httpd restart
/sbin/service nagios restart
SUccessful !!!
THANKS
then the problem was solved
If you guys are using centos 5.6
then follow the steps below:
su root:
yum install httpd php
yum install gcc-3.4.6-8 compat-gcc* libgcc* compat-libgcc* compat-gcc-32* gcc-c++* glibc* glibc-common*
yum install gd gd-devel
/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
Download nagios and nagios-plugins as follows:
wget http://nchc.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.3.1/nagios-3.3.1.tar.gz
wget http://space.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz
eg: if you are downloading as a user called, ishara: then enter the command:
cd /home/ishara/Downloads
Extract and Install nagios as follows:
tar xvf nagios-3.3.1.tar.gz
cd nagios*
./configure –with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
Now provide a password for the username called nagiosadmin: run the following command:
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
/sbin/service httpd restart
Now let’s install the nagios-plugins as follows: Enter
tar xvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins*
./configure –with-nagios-user=nagios –with-nagios-group=nagios
make
make install
Add nagios service to the startup as follows: Enter:
chkconfig —add nagios
chkconfig nagios on
To disable SELinux to permissive mode: Enter:
/usr/sbin/setenforce 0
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
All work done in the terminal now in and now in firefox or any web-browser, type
http://localhost/nagios/
Enter username : nagiosadmin and the relevant password you entered above:
DONE!!! ENJOY NAGIOS
ISHARA FERNANDO ( FROM: SRI LANKA )
<<<<>>>>
Its nice tutorial and understandable i succeded in installation and configuration.
Thanks
content is really good & usefull , request you to review and improve documentation regarding of Nagios ….
if you want to add one more windows then add another host entry and services. in /usr/local/nagios/etc/objects/windows.cfg
for new system
if you wan to add more linux machines then add host entries and services in
/usr/local/nagios/etc/objects/localhost.cfg
for new remote linux host.
Hi,
Very usefull post, nice one
Hi,
After step 5 I get this error, “No rule to make target ‘install-webconf’. Stop”.
What can be wrong?
Can any one help me please?
Thanks in advance.
Regards.
Samuel.
Hi …I get this error while compling plugin……can anyone help .me ….
./configure ……. Ok
make giving the bellow error after compiling
***********************************************************
Making all in plugins
make[2]: Entering directory `/media/ubisrvr/nagios-plugins-1.4.16/plugins’
rm -f check_ftp
ln -s check_tcp check_ftp
ln: creating symbolic link `check_ftp’ to `check_tcp’: Read-only file system
make[2]: *** [check_ftp] Error 1
make[2]: Leaving directory `/media/ubisrvr/nagios-plugins-1.4.16/plugins’
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/media/ubisrvr/nagios-plugins-1.4.16′
make: *** [all] Error 2
***********************************************************
Thanks
How to monitor apache tom cat and mysql using nagios.
it would be great it any step by step procedure is give like the above
thank you very much
have a look at this guys for adding more Object need to get monitored. and this for monitoring Public services.
This article is really very helpful…thanks…
There are some points which needs to be taken care to make it work.
1. The server must have php installed (if not, the webpage won’t display properly).
–> You can install PHP using : “yum install php -y” command in red hat linux
2. Modify, “httpd.conf” file:
–> Replace “DirectoryIndex index.html index.html.var” with “DirectoryIndex index.php index.html index.html.var” (web interface looks for index.php, not index.html)
3. Set index.php file permission to 644
–> chmod 644 /usr/local/nagios/share/index.php
4. On Redhat linux use below command for nagios configuration
–> ./configure –with-nagios-user=nagios –with-nagios-group=nagios –enable-redhat-pthread-workaround