Install and configure Nagios on Ubuntu 18.04 Bionic Beaver
A working install of Ubuntu 18.04 with root privileges
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of
- $ - requires given linux commands to be executed as a regular non-privileged user
What is Nagios
Nagios is one of the best enterprise grade server monitoring solutions available. Unlike cPanel, it's available across a wide range of Linux distributions, including Debian and Ubuntu.
Since Ubuntu 18.04 is an LTS release, upgrading your servers and running Nagios on them could be a great idea. Even though Nagios isn't up to date in the Ubuntu repositories, and setup isn't turn-key, it's still not too hard to get it running.
Install The Requirements
Before you can install Nagios on your Ubuntu server, you're going to need to install the build dependencies. Yes, that means that you're going to be building Nagios from source, but the process isn't too complex. Begin by installing the packages you need.
$ sudo apt install build-essential libgd-dev openssl libssl-dev unzip apache2
SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.
Create A Nagios User
It's best for security reasons to create a user and group specifically to run Nagios. Start by making both the new user and the new group.
$ sudo useradd nagios
$ sudo groupadd nagcmd
user to the
$ sudo usermod -a -G nagcmd nagios
Next, you're going to need to download and build the Nagios source. Go the the Nagios Core download page
, and download the latest stable release of Nagios 4.
Change in the directory where you downloaded Nagios. Unpack it with
$ tar xpf nagios-*.tar.gz
Now, change into the resulting directory.
$ cd nagios-4.3.4
Prepare the Nagios source. Configure it to use the user and group that you created.
$ ./configure --with-nagios-group=nagios --with-command-group=nagcmd
Nagios Compile Configuration On Ubuntu 18.04
That will only take a couple of seconds. Review the output. Make sure that nothing looks ridiculously out of place.
Build everything. Don't forget to use the
flag with the number of cores on your machine to speed up the process.
$ make -j4 all
It should be a fairly fast compile on modern hardware. When it's finished, you can install all of the Nagios components that you just compiled.
$ sudo make install
$ sudo make install-commandmode
$ sudo make install-init
$ sudo make install-config
Before you leave the folder, you need to copy the provided Apache configuration over to Apache's
$ sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
Then, add Apache's user to your
$ sudo usermod -a -G nagcmd www-data
Install The Plugins
Nagios has loads of great plugins that enhance its functionality. It's best to get those and install them now too. Download them from their download page
Change into the directory where you downloaded them, and unpack them.
$ tar xpf nagios-plugins-*.tar.gz
Change into the resulting directory.
$ cd nagios-plugins-2.2.1
Configure them like you did Nagios, but include OpenSSL support too.
$ ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --with-openssl
When the configuration finishes,
and install the plugins.
$ make -j4
$ sudo make install
Before you can start using Nagios, you're going to need to tweak the base configurations that you already installed.
Start by opening up the main configuration file. It's located at
Find the line below, and uncomment it. When you're gone, save and exit.
Now, make that directory.
$ sudo mkdir /usr/local/nagios/etc/servers
Open up the contacts configuration. You should change it to refelct your actual email address. The file is at
. Change the line below to match your email.
email nagios@localhost; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
In order for Apache to serve the Nagios interface, you need to enable a couple of Apache modules. Begin with that.
$ sudo a2enmod rewrite
$ sudo a2enmod cgi
Now, create an admin password for a Nagios admin user. After you enter the command, you'll be prompted to create you password.
$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
You already copied over the default Apache configuration for Nagios. You just need to enable it. Create the symlink between the copy in
sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/
Nagios Apache Configuration On Ubuntu 18.04
Its a good idea to restrict access to your Nagios server. It's best to only allow access from localhost and your own computer. Open you Apache Nagios configuration file, and find the line
. Make it look like the example below.
Deny from all
Allow from 127.0.0.1 172.86.186.XXX
Obviously, substitute your actual external IP for the final IP. The
part is just there to obscure the example. Change this for both
entries. Save it and exit.
Start up Apache.
$ sudo systemctl start apache2
Create the Service
Nagios doesn't automatically come with a Systemd service file. You need to make it at
. Copy the one below.
Enable and start your service.
$ sudo systemctl enable /etc/systemd/system/nagios.service
$ sudo systemctl start nagios
Nagios is now available at
. When you arrive, you'll be prompted to enter the password that you created for
. From there, you'll be able to browse the Nagios admin interface.
Your Nagios installation is now up and running. That Ubuntu server will be able to monitor itself, and you can see the data presented in real time through the web interface.