Install Nagios 4 on Ubuntu and Debian 8
Updated by Edward AngertContributed by Paulo Telles
This is a Linode Community guide. Write for us and earn $250 per published guide.
A monitoring tool is a key application in a production server. Nagios is a popular tool that provides monitoring and alerting services for your servers, applications and services. Using Nagios and a wide variety of available plugins, you can keep track of the status of your critical services like HTTP, SSH and SMTP. In this guide, you’ll learn how to install Nagios 4 on your Linode.
Before You Begin
- In order to run Nagios on your Linode, follow the configuration steps for Ubuntu or Debian 8 from our Getting Started guide.
- Install and configure a LAMP stack (Linux, Apache, MySQL and PHP stack). Follow the LAMP on Ubuntu 14.04 or LAMP on Debian 8 guide for instructions.
- Install updates:
1
sudo apt-get update && sudo apt-get upgrade
This guide is written for a non-root user. Commands that require elevated privileges are prefixed with
sudo
. If you’re not familiar with thesudo
command, you can check our Users and Groups guide.
Install Nagios
Create Users and Groups
Create a user, nagios
, and a distinct group, nagcmd
. Add nagios
and the Apache user, www-data
, to the nagcmd
group in order to run external commands on Nagios through the web interface:
1 2 3 |
sudo useradd nagios sudo groupadd nagcmd sudo usermod -a -G nagcmd nagios && sudo usermod -a -G nagcmd www-data |
Build Nagios 4 from Source Code
The latest stable version of Nagios 4 is not available in Ubuntu or Debian’s default repositories as of this writing. To install Nagios, download and install it from the source code:
- Install dependencies:
1
sudo apt-get install build-essential unzip openssl libssl-dev libgd2-xpm-dev xinetd apache2-utils
- In your web browser, go to the Nagios Core DIY download page. If you prefer not to register for updates, click Skip to download.
- Under Nagios Core, find the release that says Latest stable release under Notes, then copy the download link to your clipboard.
- Download and extract Nagios to your Linode using
wget
andtar
, pasting the link from Step 3:1 2
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz tar -xvf nagios-4.*.tar.gz
- Move to the newly created directory:
1
cd nagios-4.*
- Configure, compile and install Nagios:
1 2 3 4 5 6
./configure --with-nagios-group=nagios --with-command-group=nagcmd make all sudo make install sudo make install-init sudo make install-config sudo make install-commandmode
Prepare Apache and Configure Nagios Web Interface
- Make sure Apache has
mod_rewrite
andmod_cgi
enabled:1
sudo a2enmod rewrite && sudo a2enmod cgi
- Copy the sample virtual host configuration Nagios provides to
sites-available
:1
sudo cp sample-config/httpd.conf /etc/apache2/sites-available/nagios4.conf
- Restrict
nagios4.conf
file permissions:1
sudo chmod 644 /etc/apache2/sites-available/nagios4.conf
- Enable the new virtual host:
1
sudo a2ensite nagios4.conf
- The web interface requires login. Create a
nagiosadmin
account and record the password you assign:1
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
- Restart Apache
1
sudo service apache2 restart
Install Nagios Plugins
Nagios Plugins allow you to monitor services like DHCP, FTP, HTTP and NTP. To use Nagios Plugins, go to the Nagios Plugins downloads page and copy the download link for the current stable release (e.g., http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
):
- Download and extract Nagios Plugins to your Linode using
wget
andtar
, pasting the link you copied:1 2
wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz tar -xvf nagios-plugins-2*.tar.gz
- Change to the newly created directory, then configure, compile, and install Plugins:
1 2 3 4
cd nagios-plugins-2.* ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl make sudo make install
Access the Nagios Web Interface
- Before accessing the Nagios Web Interface, start the Nagios service:
1
sudo service nagios start
For Ubuntu versions after 14.04, see the Systemd section below before running this step.
- The interface can be accessed in your web browser by appending
/nagios
to your domain or Public IP. When prompted at login, usenagiosadmin
as the user and use the password you assigned in the Configure Nagios Web Interface section.You will be greeted with a screen like this one:
To view monitoring status, click the Hosts link in the menu on the left. This example screenshot shows an active Nagios server called
localhost
:
Systemd
As of this guide’s publication, the Nagios build process does not create a systemd service file. In order to manage the service with systemd, create a Nagios service file for the system to load on initialization:
- /etc/systemd/system/nagios.service
-
1 2 3 4 5 6 7 8 9 10 11 12
[Unit] Description=Nagios BindTo=network.target [Install] WantedBy=multi-user.target [Service] User=nagios Group=nagios Type=simple ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg
Enable the link, start the Nagios service, and check the status:
1 2 3 |
sudo systemctl enable /etc/systemd/system/nagios.service sudo systemctl start nagios systemctl status nagios |
You can now continue at Access the Nagios Web Interface
Next Steps
Nagios contains numerous features that are beyond the scope of this document. Explore the Nagios administrative interface as well as the resources listed below to access more information regarding the setup and configuration of Nagios.
Congratulations on your new Nagios monitoring and notification system!