How-to – Install Nagios system to Debian Wheezy


How-to install  the last Nagios version

Nagios is an open source monitoring tool for the network devices.

Nagios Core Installation

  • Install the required packages:
# apt-get install -y apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev libssl-dev
  • Add and create nagios users and groups:
# groupadd -g 9000 nagios
# groupadd -g 9001 nagcmd
# useradd -u 9000 -g nagios -G nagcmd -d /usr/local/nagios -c 'Nagios Admin' nagios
# adduser www-data nagcmd
  • Download the latest version of Nagios Core and unzip it (at the moment is the 3.5.1 version):
# wget 
# tar xzf nagios-3.5.1.tar.gz
  • Change directory to the newly unzipped Nagios directory and run these commands:
# ./configure –-prefix=/usr/local/nagios -–with-nagios-user=nagios –-with-nagios-group=nagios –-with-command-user=nagios –-with-command-group=nagcmd --with-cgiurl=/nagios/cgi-bin --with-htmurl=/nagios/

# make all
# make install
# make install-init
# make install-config
# make install-commandmode
# make install-webconf
  • Next, create a user for web console access:
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# chown nagios:nagcmd /usr/local/nagios/etc/htpasswd.users
  • Make Nagios start on boot:
# chmod +x /etc/init.d/nagios
# update-rc.d nagios defaults

Nagios Plugin Installation

  • Download and unzip the latest Nagios plugin version:
# wget
# tar xzf nagios-plugins-1.4.16.tar.gz

Configure and install:

# ./configure --with-nagios-user=nagios --with-nagios-group=nagios  --with-openssl=/usr/bin/openssl --enable-perl-modules --enable-libtap
# make
# make install

Nagios NRPE Plugin

  • Install the Nagios NRPE plugin from the Debian repo’s:
# apt-get install -y nagios-nrpe-plugin
  • The installation will prompt you for a password for ‘nagiosadmin’

Install Packages for Email Notifications

# apt-get install -y postfix

Editing Nagios Email Notifications

I edited my ‘/usr/local/nagios/etc/objects/commands.cfg’  file so that Nagios will send email alerts. I had to change two lines in that file from ‘/bin/mail’ to ‘/usr/bin/mail’. I also added the ‘-r [email protected]’ so I could change from what email address these alerts come from.
edit the ‘/usr/local/nagios/etc/objects/commands.cfg’ file by changing the ‘command_line’ sections in the ‘notify-host-by-email’ and ‘notify-service-by-email’ by makeing sure it is using::

# /usr/bin/mail -r [email protected]

Here is an example of what your code should look like there:

/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -r [email protected] -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $ $SERVICESTATE$ **" $CONTACTEMAIL$ [email protected]

Configure Nagios Web Console to use SSL

The configure script has already generate the conf file fopr Apache – /etc/apache2/conf.d/nagios.conf
  • Restart apache:
# service apache2 restart

Browse the url http://SERVER-IP/nagios and enter the login and password previously created.