Nagios is one of the most widely used open source Linux and Windows server monitoring tools. With it, you can monitor the execution of various applications and services remotely through a web interface. Nagios can also monitor routers and other network devices.
With Nagios, you can monitor basic server parameters such as CPU load, memory usage, etc. All this is available in a web interface that requires simple authentication to access. In this article, we will look at how the installation of Nagios Ubuntu is carried out, as well as the configuration of this program.
Installing Nagios in Ubuntu
There are several ways to install Nagios Ubuntu 16.04. You can use the PPA or install using the archive downloaded from the official website. At the moment, the latest version is 4.3. Only 4.2 is available in the PPA, so we will consider manual installation using the archive.
But before we proceed to the installation, you need to update the system and install all the necessary components to build the program:
sudo apt update
sudo apt install build-essential apache2 php7.0 openssl perl make php7.0-gd libgd2-xpm-dev libapache2-mod-php7.0 libperl-dev libssl-dev daemon wget apache2-utils unzip
Then you need to create a group and user under which Nagios will run, as well as shell commands executed in the web interface:
sudo useradd nagios
$ sudo groupadd nagcmd
Add the nagios user and the user under which Apache runs to the nagcmd group:
sudo usermod -a -G nagcmd nagios
$ sudo usermod -a -G nagcmd www-data
Next, we need to download the nagios sources. This can be done using the terminal command, but since we want to get the latest version, it’s better to go to the official website and download.
First click on “Nagios Core” , then scroll down and click “Download” :
At this stage, you can fill in your information, or skip by clicking “Skip download” :
It remains to choose the version, for example, 4.3.2. After the download is complete, go to the downloads folder and unpack the archive:
cd ~/Downloads/
$ tar -zxvf /tmp/nagios-4.3.2.tar.gz
Now we can move on to compiling nagios. To do this, you need to run the following commands:
./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/
$ make all
$ sudo make install
$ sudo make install-init
$ sudo make install-config
$ sudo make install-commandmode
$ sudo make install-webconf
Configuring Nagios in Ubuntu
All configuration files of the program will be placed by the installer in /usr/local/nagios/etc/. The default settings allow Nagios to run, but we need to make a few more changes. Open the contact.cfg file and change the email address to which notifications will be sent:
sudo vi /usr/local/nagios/etc/objects/contacts.cfg
For the web interface to work, you need to create a password for the nagiosadmin user using htpasswd, without it you simply won’t be able to enter the interface:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Finally, for correct operation, you need to make a few settings for the web server. Enable the cgi module:
sudo a2enmod cgi
Restart the web server:
sudo service apache2 restart
For more nagios features, you can install a set of plugins. To do this, first download it:
Now unpack the archive and go to the folder with it:
tar -zxvf /tmp/nagios-plugins-2.1.1.tar.gz
$ cd /tmp/nagios-plugins-2.1.1/
To compile modules run:
./configure --with-nagios-user=nagios --with-nagios-group=nagios
$ make
$ make install
The modules are installed in the Nagios folder, now check if the configuration is correct:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
To automatically start, create a Unit file for systemd:
sudo vi /etc/systemd/system/nagios.service
[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
Launching Nagios
Almost everything is ready, it remains to start the service and start using it. To start the service, type:
sudo systemctl stat nagios
To open the nagios web interface, it will be enough to type the ip address and url of nagios in the browser. If you installed all this on your local computer, then use:
Immediately after opening the page, you will need to enter the username nagiosadmin and the password that you set for it earlier. After that, you can use all the features of the program:
Findings
In this article, we looked at how to set up nagios 4, as well as fully install the latest version on the Ubuntu operating system. Despite the fact that, at first glance, everything seems complicated, the process is quite simple. Now you can monitor nagios ubuntu 16.04. I hope this information was helpful to you.