How to Install Nagios Server on Debian 11

This guide provides a step-wise tutorial on how to install Nagios server on Debian 11. Nagios Core is a system and network monitoring program that is open source. It monitors the hosts and services you designate, notifying you when things go wrong and when they recover.

How to Install Nagios Server on Debian 11

Nagios Core can be installed from the default Debian 11 main repositories.

Nagios Core v4.4.6 is the most recent stable release version as of this writing.

Install Nagios Server on Debian 11

To install Nagios server on Debian 11, run the command below;

sudo apt install nagios4

Accept the installation prompt by pressing y or Y and hit Enter.

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-utils bsd-mailx exim4-base exim4-config exim4-daemon-light fontconfig-config fonts-dejavu-core libapache2-mod-php libapache2-mod-php7.4 libapr1
  libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libdeflate0 libevent-2.1-7 libfontconfig1 libgd3 libgdbm-compat4 libgnutls-dane0 libidn11 libjbig0 libjpeg62-turbo
  libjs-jquery liblockfile1 liblua5.3-0 libperl5.32 libsodium23 libtiff5 libunbound8 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 mailcap mime-support
  monitoring-plugins-basic monitoring-plugins-common nagios4-cgi nagios4-common nagios4-core perl perl-modules-5.32 php-common php7.4-cli php7.4-common php7.4-json
  php7.4-opcache php7.4-readline psmisc
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser exim4-doc-html | exim4-doc-info eximon4 spf-tools-perl swaks php-pear libgd-tools dns-root-data
  icinga2 nagios-nrpe-plugin perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make libtap-harness-archive-perl
Recommended packages:
  apache2 javascript-common apache2 | httpd nagios-images monitoring-plugins
The following NEW packages will be installed:
  apache2-bin apache2-utils bsd-mailx exim4-base exim4-config exim4-daemon-light fontconfig-config fonts-dejavu-core libapache2-mod-php libapache2-mod-php7.4 libapr1
  libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libdeflate0 libevent-2.1-7 libfontconfig1 libgd3 libgdbm-compat4 libgnutls-dane0 libidn11 libjbig0 libjpeg62-turbo
  libjs-jquery liblockfile1 liblua5.3-0 libperl5.32 libsodium23 libtiff5 libunbound8 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 mailcap mime-support
  monitoring-plugins-basic monitoring-plugins-common nagios4 nagios4-cgi nagios4-common nagios4-core perl perl-modules-5.32 php-common php7.4-cli php7.4-common
  php7.4-json php7.4-opcache php7.4-readline psmisc
0 upgraded, 54 newly installed, 0 to remove and 0 not upgraded.
Need to get 23.5 MB of archives.
After this operation, 102 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Install other recommended packages;

apt install apache2 javascript-common nagios-images monitoring-plugins -y

Running Nagios Server on Debian 11

Check if nagios service is active and running.

systemctl status nagios4
● nagios4.service - nagios4
     Loaded: loaded (/lib/systemd/system/nagios4.service; disabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-11-17 17:29:31 UTC; 12min ago
       Docs: man:nagios4
   Main PID: 11175 (nagios4)
      Tasks: 6 (limit: 2276)
     Memory: 21.6M
        CPU: 531ms
     CGroup: /system.slice/nagios4.service
             ├─11175 /usr/sbin/nagios4 /etc/nagios4/nagios.cfg
             ├─11177 /usr/sbin/nagios4 --worker /var/lib/nagios4/rw/nagios.qh
             ├─11178 /usr/sbin/nagios4 --worker /var/lib/nagios4/rw/nagios.qh
             ├─11179 /usr/sbin/nagios4 --worker /var/lib/nagios4/rw/nagios.qh
             ├─11180 /usr/sbin/nagios4 --worker /var/lib/nagios4/rw/nagios.qh
             └─11317 /usr/sbin/nagios4 /etc/nagios4/nagios.cfg

Nov 17 17:31:23 debian-2gb-hel1-1 nagios4[11175]: SERVICE ALERT: localhost;HTTP;CRITICAL;SOFT;1;connect to address 127.0.0.1 and port 80: Connection refused
Nov 17 17:32:23 debian-2gb-hel1-1 nagios4[11175]: SERVICE ALERT: localhost;HTTP;CRITICAL;SOFT;2;connect to address 127.0.0.1 and port 80: Connection refused
Nov 17 17:33:23 debian-2gb-hel1-1 nagios4[11175]: SERVICE ALERT: localhost;HTTP;CRITICAL;SOFT;3;connect to address 127.0.0.1 and port 80: Connection refused
Nov 17 17:33:53 debian-2gb-hel1-1 nagios4[11175]: SERVICE ALERT: localhost;Swap Usage;CRITICAL;SOFT;1;SWAP CRITICAL - 0% free (0 MB out of 0 MB) - Swap is either disabled,>
Nov 17 17:34:23 debian-2gb-hel1-1 nagios4[11175]: SERVICE ALERT: localhost;HTTP;CRITICAL;HARD;4;connect to address 127.0.0.1 and port 80: Connection refused
Nov 17 17:34:53 debian-2gb-hel1-1 nagios4[11175]: SERVICE ALERT: localhost;Swap Usage;CRITICAL;SOFT;2;SWAP CRITICAL - 0% free (0 MB out of 0 MB) - Swap is either disabled,>
Nov 17 17:35:53 debian-2gb-hel1-1 nagios4[11175]: SERVICE ALERT: localhost;Swap Usage;CRITICAL;SOFT;3;SWAP CRITICAL - 0% free (0 MB out of 0 MB) - Swap is either disabled,>
Nov 17 17:36:53 debian-2gb-hel1-1 nagios4[11175]: SERVICE NOTIFICATION: nagiosadmin;localhost;Swap Usage;CRITICAL;notify-service-by-email;SWAP CRITICAL - 0% free (0 MB out>
Nov 17 17:36:53 debian-2gb-hel1-1 nagios4[11175]: SERVICE ALERT: localhost;Swap Usage;CRITICAL;HARD;4;SWAP CRITICAL - 0% free (0 MB out of 0 MB) - Swap is either disabled,>

Enable Nagios service start automatically when the system boots up.

sudo systemctl enable nagios4

Configuring Nagios Server Web Access

When installed, Nagios create an Apache configuration file, /etc/apache2/conf-available/nagios4-cgi.conf.

This is how this configuration file looks like with comment lines removed;

grep -vE "^.*#|^$" /etc/apache2/conf-available/nagios4-cgi.conf
ScriptAlias /cgi-bin/nagios4 /usr/lib/cgi-bin/nagios4
ScriptAlias /nagios4/cgi-bin /usr/lib/cgi-bin/nagios4
Alias /nagios4/stylesheets /etc/nagios4/stylesheets
Alias /nagios4 /usr/share/nagios4/htdocs
<DirectoryMatch (/usr/share/nagios4/htdocs|/usr/lib/cgi-bin/nagios4|/etc/nagios4/stylesheets)>
    Options FollowSymLinks
    DirectoryIndex index.php index.html
    AllowOverride AuthConfig
    Require ip	::1/128 fc00::/7 fe80::/10 10.0.0.0/8 127.0.0.0/8 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16
    <Files "cmd.cgi">
	AuthDigestDomain "Nagios4"
	AuthDigestProvider file
	AuthUserFile	"/etc/nagios4/htdigest.users"
	AuthGroupFile	"/etc/group"
	AuthName	"Nagios4"
	AuthType	Digest
	Require all	granted
    </Files>
</DirectoryMatch>
<Directory /usr/share/nagios4/htdocs>
    Options	+ExecCGI	
</Directory>

Update the configuration file above as follows;

mv /etc/apache2/conf-available/nagios4-cgi.conf{,.old}
cat > /etc/apache2/conf-available/nagios4-cgi.conf << EOL
ScriptAlias /cgi-bin/nagios4 /usr/lib/cgi-bin/nagios4
ScriptAlias /nagios4/cgi-bin /usr/lib/cgi-bin/nagios4

Alias /nagios4/stylesheets /etc/nagios4/stylesheets

Alias /nagios4 /usr/share/nagios4/htdocs

<DirectoryMatch (/usr/share/nagios4/htdocs|/usr/lib/cgi-bin/nagios4|/etc/nagios4/stylesheets)>
    Options FollowSymLinks
    DirectoryIndex index.php index.html
    AllowOverride AuthConfig
	AuthDigestDomain "Nagios4"
	AuthDigestProvider file
	AuthUserFile	"/etc/nagios4/htdigest.users"
	AuthGroupFile	"/etc/group"
	AuthName	"Nagios4"
	AuthType	Digest
	Require	valid-user
</DirectoryMatch>

<Directory /usr/share/nagios4/htdocs>
    Options	+ExecCGI	
</Directory>
EOL

Nagios Web Authentication

By default, as seen from the configuration above, Nagios uses MD5 digest for web authentication:

<DirectoryMatch (/usr/share/nagios4/htdocs|/usr/lib/cgi-bin/nagios4|/etc/nagios4/stylesheets)>
    Options FollowSymLinks
    DirectoryIndex index.php index.html
    AllowOverride AuthConfig
	AuthDigestDomain "Nagios4"
	AuthDigestProvider file
	AuthUserFile	"/etc/nagios4/htdigest.users"
	AuthGroupFile	"/etc/group"
	AuthName	"Nagios4"
	AuthType	Digest
	Require	valid-user
</DirectoryMatch>

The default authentication passwdfile is set to /etc/nagios4/htdigest.users in the setup above.

By default, Nagios uses the user, nagiosadmin, for authentication. This user is defined in the file, /etc/nagios4/cgi.cfg.

You can instead use a different user if you want. In that case, be sure to replace all instances of the user, nagiosadmin, with the user of your choice.

The user needs to be createed for authentication. Such command can be used to create MD5 digest users.

htdigest [ -c ] passwdfile realm username

For example, you can run the command below to add the users and passwords into this file.

htdigest -c /etc/nagios4/htdigest.users "Nagios4" nagiosadmin

If you used a different user apart from nagiosadmin, be sure to create that user as well.

Enable Required Modules

Enable required MD5 Digest Authentication modules.

a2enmod auth_digest authz_groupfile

Disable some modules;

a2dismod mpm_event

Enable mpm_prefork:

a2enmod mpm_prefork

Similarly, enable Apache rewrite and CGI modules must be enabled.

a2enmod rewrite cgid

Enable PHP module;

a2enmod php7.4

Other Nagios Configuration files can be located under /etc/nagios4/ directory.

Enable Nagios Apache Configuration

Once done with the configuration file, enable the configuration file;

a2enconf nagios4-cgi

Start Apache Web server

Check Apache configuration syntax;

apachectl -t
Syntax OK

If no error is found, restart Apache.

systemctl restart apache2

Check the status;

systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-11-17 18:55:31 UTC; 16s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 14904 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 14908 (apache2)
      Tasks: 56 (limit: 2276)
     Memory: 9.5M
        CPU: 32ms
     CGroup: /system.slice/apache2.service
             ├─14908 /usr/sbin/apache2 -k start
             ├─14909 /usr/sbin/apache2 -k start
             ├─14910 /usr/sbin/apache2 -k start
             └─14911 /usr/sbin/apache2 -k start

Nov 17 18:55:31 nagios.itnixpro.com systemd[1]: Starting The Apache HTTP Server...
Nov 17 18:55:31 nagios.itnixpro.com systemd[1]: Started The Apache HTTP Server.

If your system has a firewall, make sure to enable Apache through it.

ufw allow 80/tcp

Restart Nagios Server service

To restart the Nagios Server service, execute the command;

systemctl restart nagios4

Check the status thereafter;

systemctl status nagios4
● nagios4.service - nagios4
     Loaded: loaded (/lib/systemd/system/nagios4.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-11-17 19:00:41 UTC; 17s ago
       Docs: man:nagios4
    Process: 14995 ExecStartPre=sh -c nagiospipe=$$(sed -n "s/^command_file=\(.*\)/\1/p" ${NAGIOSCFG}); [ -z "$${nagiospipe}" -o ! -e "$${nagiospipe}" ] || rm -f "$${nagio>
   Main PID: 14997 (nagios4)
      Tasks: 6 (limit: 2276)
     Memory: 2.0M
        CPU: 20ms
     CGroup: /system.slice/nagios4.service
             ├─14997 /usr/sbin/nagios4 /etc/nagios4/nagios.cfg
             ├─14998 /usr/sbin/nagios4 --worker /var/lib/nagios4/rw/nagios.qh
             ├─14999 /usr/sbin/nagios4 --worker /var/lib/nagios4/rw/nagios.qh
             ├─15000 /usr/sbin/nagios4 --worker /var/lib/nagios4/rw/nagios.qh
             ├─15001 /usr/sbin/nagios4 --worker /var/lib/nagios4/rw/nagios.qh
             └─15002 /usr/sbin/nagios4 /etc/nagios4/nagios.cfg

Nov 17 19:00:41 nagios.itnixpro.com nagios4[14997]: wproc: Registry request: name=Core Worker 15001;pid=15001
Nov 17 19:00:41 nagios.itnixpro.com nagios4[14997]: wproc: Registry request: name=Core Worker 15001;pid=15001
Nov 17 19:00:41 nagios.itnixpro.com nagios4[14997]: wproc: Registry request: name=Core Worker 15000;pid=15000
Nov 17 19:00:41 nagios.itnixpro.com nagios4[14997]: wproc: Registry request: name=Core Worker 15000;pid=15000
Nov 17 19:00:41 nagios.itnixpro.com nagios4[14997]: wproc: Registry request: name=Core Worker 14999;pid=14999
Nov 17 19:00:41 nagios.itnixpro.com nagios4[14997]: wproc: Registry request: name=Core Worker 14999;pid=14999
Nov 17 19:00:41 nagios.itnixpro.com nagios4[14997]: wproc: Registry request: name=Core Worker 14998;pid=14998
Nov 17 19:00:41 nagios.itnixpro.com nagios4[14997]: wproc: Registry request: name=Core Worker 14998;pid=14998
Nov 17 19:00:41 nagios.itnixpro.com nagios4[14997]: Successfully launched command file worker with pid 15002
Nov 17 19:00:41 nagios.itnixpro.com nagios4[14997]: Successfully launched command file worker with pid 15002

Check the logs as well;

tail -f /var/log/nagios4/nagios.log

Accessing Nagios Server Web Interface on Debian 11

Once you’ve finished configuring your Nagios server, go to your browser and type http://<server-IP>/nagios4 into the address bar.

To log in, you must use the username and password you created before.

How to Install Nagios Server on Debian 11

Default dashboard

How to Install Nagios Server on Debian 11

Current host status

How to Install Nagios Server on Debian 11

Current service status;

How to Install Nagios Server on Debian 11

And that is it on how to install Nagios server on Debian 11. You can continue to add hosts and services to monitor.

Further Reading

Nagios Core Documentation

Other Tutorials

Install Wazuh Server with ELK Stack on Debian 11

Install Monitorix on Rocky Linux 8

ELK: Send Alerts when no data is received on an index

Founder of itnixpro.com|Linux Engineer|Author at Itnixpro.com

Leave a Comment