Call Us! 1-800-383-5193
Call Us! 1-800-383-5193
Call Us! 1-800-383-5193

Need Help?

Emergency Response Time custom

Our experts have had an average response time of 11.06 minutes in March 2021 to fix urgent issues.

We will keep your servers stable, secure and fast at all times for one fixed price.

Installing and Configuring Nagios

by | Feb 20, 2006

This article attempts to provide complete and easy steps for Nagios installation on a Webserver or a Local cluster.


Hire Bobcares Linux Server Administrators
Get super reliable servers and delighted customers

See how we do it!



Getting Nagios


You need root access on the server, where you would like to install Nagios.
* Login as root.

* Create a directory for downloads.

#mkdir -p /usr/src/backs/nagios

#cd /usr/src/backs/nagios


Download source of nagios and nagios-plugins at




Implement custom monitoring by Bobcares.

Compilation and installation of Nagios


Login as root and create a user, say “nagios”


#adduser nagios
#passwd nagios
Changing password for user nagios.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
In some servers normal users may not have permission to use ‘mail’ inorder to send alerts.
usermod -G mail nagios
Make a directory for working with the source code.
cd /usr/src/works/nagios/
tar -zxvf /usr/src/backs/nagios/nagios-1.2.tar.gz
cd nagios-1.2/

The default is fine for normal operation.
for details see the file ‘INSTALL’

./configure –prefix=prefix –with-cgiurl=cgiurl
–with-htmurl=htmurl –with-nagios-user=someuser

make all
make install
make install-init # Needed to add the service ‘nagios’.
make install-commandmode
make install-config

Install the plugins
cd ../
tar -zxvf /usr/src/backs/nagios/nagios-plugins-1.3.1.tar.gz
cd nagios-plugins-1.3.1/

NOTE:- For mysql and postgresql plugins to work,
their libraries have to be installed. so to avoid
installing those we will use ‘check_tcp’
Instead later with seperate port for mysql and postgresql

make check
make install
Libraries will be installed in ‘/usr/local/nagios/libexec’ position by the default installation.
If there is no contents do the following.
mkdir /usr/local/nagios/libexec
mv /usr/lib/nagios/plugins/* /usr/local/nagios/libexec/
ln -s /lib/ /lib/

Post install Configuration of Nagios

Edit apache’s httpd.conf file. (the location of the httpd.conf file may differ)

vim /etc/httpd/conf/httpd.conf

Add the following line at the end of the file.

Include /etc/httpd/conf/nagios.conf

Create the file ‘/etc/httpd/conf/nagios.conf’.

vi /etc/httpd/conf/nagios.conf

Add the following contents to this file.
ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/
<Directory ?/usr/local/nagios/sbin/?>
AllowOverride AuthConfig
Options ExecCGI
Allow from all
Order allow,deny

Alias /nagios/ /usr/local/nagios/share/
<Directory ?/usr/local/nagios/share?>
Options None
AllowOverride AuthConfig
Order allow,deny
Allow from all

Make sure the updations done with http is fine and restart apache.

#service httpd restart

Create ‘.htaccess’ file in ‘/usr/local/nagios/share/’ and ‘/usr/local/nagios/sbin/’.

#touch /usr/local/nagios/share/.htaccess
#touch /usr/local/nagios/sbin/.htaccess

Add the following contents to both these files.

AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user

Create the username, password for logging into the Nagios interface.

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

Make it available for the user who runs httpd.

chmod o+r /usr/local/nagios/etc/htpasswd.users

Restart the httpd service.

service httpd restart

Advanced Nagios Configurations.

Rename the sample files to the real names.

cd /usr/local/nagios/etc/
for i in *sample ; do mv $i `echo "$i" |sed s/-sample//` ; done

Edit the main conf file, nagios.cfg. and change only these lines.


Make these Cgi specific changes in cgi.cfg.


Add servers that need to be monitored

Make the Host specific changes to the hosts.cfg.

 Generic host definition template
define host{
        name                            generic-host
        notifications_enabled          1
        event_handler_enabled          1
        flap_detection_enabled          1
        process_perf_data              1
        retain_status_information      1
        retain_nonstatus_information    1

        register                        0

define host{
        use                    generic-host            ; Name of host
template to use

        host_name              <FQDN of server>
        alias                  <Any alias name for the host>
        address                <IP of server>
        check_command          check-host-alive
        max_check_attempts      10
        notification_interval  120
        notification_period    24x7
        notification_options    d,u,r

Repeat for all the hosts we want to check.
Group them in hostgroups.cfg

define hostgroup{
        hostgroup_name  <Host group name>
        alias          <any alias name>
        contact_groups  <contact group name>
        members        <<host1>,<host2>,..>

Repeat for all the hosts groups.

Specify the services that need to be checked

Edit the details of all the services, we want checked by Nagios in services.cfg.

 Generic service definition template
define service{
        name                            generic-service
        active_checks_enabled          1
        passive_checks_enabled          1
        parallelize_check              1
        obsess_over_service            1
        check_freshness                0
        notifications_enabled          1
        event_handler_enabled          1
        flap_detection_enabled          1
        process_perf_data              1
        retain_status_information      1
        retain_nonstatus_information    1
        register                        0

define service{
        use                            generic-service
        host_name                      <FQDN of server to check the service>
        service_description            <Service name>
        is_volatile                    0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval          3
        retry_check_interval            1
        contact_groups                  <contact group name for alerts
to send>
        notification_interval          120
        notification_period            24x7
        notification_options            w,u,c,r
        check_command                  <check command for the service>

Repeat for each service on each host.

Specify Alert Contacts

In order to specify details of the contacts for alerts, we need to edit contacts.cfg.

 'nagios' contact definition
define contact{
        contact_name                    <contact name>
        alias                          <some nickname>
        service_notification_period    24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options      d,u,r
        service_notification_commands  notify-by-email,notify-by-epager
        email                          <email address of the contact>
        pager                          <pager or mobile no.(optional)>

Repeat for all contacts.

Group the contacts

Edit contactgroups.cfg, in order to specify groups of contacts.

define contactgroup{
        contactgroup_name      <contact group name>
        alias                  <any nickname for the group>
        members                <members (comma seperated)>

Repeat for all groups to include all contacts

Escalation with nagios

If you need to send selective alerts, for example when critical issues occur, simply configure the escalations.cfg file.

define serviceescalation{
        host_name                      <FQDN of the server>
        service_description            < name>
        first_notification              2
        last_notification              6
        contact_groups                  < groups (comma seperated)>
        notification_interval          0

Repeat for all escalations Once again, check all the files, nagios.cfg cgi.cfg hosts.cfg hostgroups.cfg, services.cfg, contacts.cfg, contactgroups.cfg, escalations.cfg and checkcommands.cfg Restart httpd and then Nagios.

service httpd restart

Add Nagios to system services.

chkconfig --add nagios
service nagios restart

Check for any errors reported, and solve them one by one if any.
Enable nagios in runlevels, so that it starts on boot.

chkconfig nagios on

Create cron.daily entry if we want to restart the service daily. Here is the script.

vi etc/cron.daily/nagios-restart.cron
/sbin/service nagios restart >/dev/null 2>&1

Make it executable

chmod +x etc/cron.daily/nagios-restart.cron

And finally, Check if nagios is working fine.!!! 😉


Articles by Shivin S HameedAbout the author:
Shivin S. Hameed has worked in as a Technical Support Engineer for the last 1.5 years.


  1. This is good information here. I work for companies who insist on using open source software when open source software is best of breed in a market like Nagios is.

    I have written documentation like this on my blog, but you are a much better writer than I am.

    • Thank you Alpha Monk! 🙂

  2. is there a way to obfuscate the configuration file?

  3. Great information!!! Thanks!!!!

  4. this is good information that help me really to configure nagious monitor tool

  5. I am the beginner for using nagios, this info is easy to understand and to follow.



  1. Cpanel Httpd.conf Template | Cloud Hosting Service - […] Installing and Configuring Nagios – … – This article attempts to provide complete and easy steps for Nagios installation…

Submit a Comment

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

Privacy Preference Center


Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]


Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid


Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie


These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.