This comprehensive Linux guide expects that you run the following commands as root user but if you decide to run the commands as a different user then ensure that the user has
sudo
access and that you precede each of the privileged commands withsudo
It is an open source software tool designed to monitor system network and infrastructure. It keeps an inventory of your entire IT infrastructure and ensures your networks, servers, applications, services, and processes are up and running. It also sends you an alert in case of failure of a critical infrastructure component.
Updating Server And Dependencies
Once logged in to your system, first type the following commands:
apt update
apt upgrade
Now you can install dependencies using following commands
apt install -y build-essential autoconf gcc libc6 make wget unzip libgd2-xpm-dev
Downloading And Installing Nagios
Use the following command to download Nagois to a directory named /opt
wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.2.tar.gz -O /opt/nagioscore.tar.gz
When the download is complete, navigate to the opt directory and extract the archive using following commands
cd /opt
sudo tar xf nagioscore.tar.gz
Once Nagios archive is extracted, navigate to the newly created directory and run the following command to check for missing libraries
cd /opt/nagioscore-nagios-4.4.2
./configure
The output would be somewaht similar to shown below:
*** Configuration summary for nagios 4.4.2 2018-08-16 ***:
General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagios
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Install ${includedir}: /usr/local/nagios/include/nagios
Lock file: /run/nagios.lock
Check result directory: /usr/local/nagios/var/spool/checkresults
Init directory: /lib/systemd/system
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
IOBroker Method: epoll
Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /usr/sbin/traceroute
Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.
After completing configuration, run the following command to build the software:
make all
Use the following commands to create Nagios user
make install-groups-users
usermod -a -G nagios www-data
Now install Nagios using following commands
make install
Now you will run the following commands to install configuration files
make install-config
You can install the services using following commands
root@codesposts:/opt/nagioscore-nagios-4.4.2# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /lib/systemd/system
/usr/bin/install -c -m 755 -o root -g root startup/default-service /lib/systemd/system/nagios.service
root@codesposts:/opt/nagioscore-nagios-4.4.2# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
Now you will configure external command file
root@codesposts:/opt/nagioscore-nagios-4.4.2# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
Install the Apache web server using the following commands
make install-webconf
To restart Apache service you will use following commands
systemctl restart apache2
a2enmod rewrite && a2enmod cg
Configuration Of Nagios Web Server Interface
To create Apache user account use the following commands
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Downloading And Installing Nagios Plugins
You should make sure that pre-requisite packages are installed.This can be done using following commands
apt install -y autoconf gcc libc6 libmcrypt-dev make libssl-dev wget bc gawk dc build-essential snmp libnet-snmp-perl gettext
Now you will create your own working directory using following command
mkdir /opt/nagios && cd /opt/nagios
wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gz
tar zxf nagios-plugins.tar.gz
cd nagios-plugins-release-2.2.1
Compiling And Installing Plugins
./tools/setup
./configure
make
make install
You can check configuration file errors using following commands
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.4.2
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
...............................................
...............................................
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
To start Nagios web panel use the following commands
systemctl start nagios
Now Open your browser and then navigate to http://your-domain-or-ip/nagios
and you will be presented with the login pop-up.
Enter the login credentials that you created earlier with the htpasswd
command, and you will be redirected to the Nagios home page