Nagios – New installation on Debian 9

If you have to install a really great network those such as Nagios those will be steps needed:

1.Installing Apache2 + PHP (Skip if you already have one):

apt-get install apache2 libapache2-mod-php7.0 php7.0
# enable cgi
a2enmod rewrite headers cgi
systemctl restart apache2

# setup correct timezone in php
mcedit /etc/php/7.0/apache2/php.ini
# set date.timezone according to http://php.net/manual/en/timezones.php
systemctl restart apache2

# info.php
echo '<?php phpinfo(); ?>' >/var/www/html/info.php

# open browser apache_server_ip/info.php and check 'default timezone'

2.Installing Nagios core:

# pre-request to build nagios from source:
apt-get install autoconf gcc libc6 make apache2-utils libgd-dev

# get source from https://www.nagios.org/downloads/nagios-core/
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.4.tar.gz
tar xzf nagios-4.3.4.tar.gz
cd nagios-4.3.4/
./configure --with-httpd-conf=/etc/apache2/sites-enabled

# Output should look like this:
*** Configuration summary for nagios 4.3.4 2017-08-24 ***:

 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:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/init.d
  Apache conf.d directory:  /etc/apache2/sites-enabled
             Mail program:  /usr/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.

##################

# next we need to 'make' it ;-)
make all

# Output should look like this:
Enjoy.

# and we will in few minutes
# lets us create user for nagios
useradd nagios
# we will add him to apache group
usermod -a -G nagios www-data

# last but not least:
make install

# Output should look like this:

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/spool/checkresults
chmod g+s /usr/local/nagios/var/spool/checkresults

*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

  make install-init
     - This installs the init script in /etc/init.d

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs sample config files in /usr/local/nagios/etc


##############

# let's add init script
make install-init
# and enable init script
systemctl enable nagios.service

# install and configure permissions for external command file:
make install-commandmode

# and add sample configuration so nagios will start:
make install-config

# add nagios-site apache configuration file:
make install-webconf

# we need to create nagiosadmin account for http
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

# finally we can restart apache and start nagios:
systemctl restart apache2
systemctl start nagios

# open browser and type: nagios_ip_address/nagios/

3.Installing Nagios Plugins (needed !)

# pre-require
apt-get install libmcrypt-dev make libssl-dev bc gawk dc build-essential snmp libnet-snmp-perl gettext libldap2-dev smbclient fping default-libmysqlclient-dev

# get latest source file! from https://github.com/nagios-plugins/nagios-plugins/releases
wget https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gz
tar zxvf release-2.2.1.tar.gz
cd nagios-plugins-release-2.2.1/
./tools/setup
./configure
make
make install

# now we should have all commands in /usr/local/nagios/libexec/
ls /usr/local/nagios/libexec/

# restart nagios so he can load those:
systemctl restart nagios.service

4.Enable SSL for Nagios (and not only)

# enable module
a2enmod ssl
systemctl restart apache2

# edit apache to redirect traffic to ssl
mcedit /etc/apache2/sites-enabled/000-default.conf
# add this to VirtualHost:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{HTTP_HOST}/$1

# after modification file should look like this:
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        RewriteEngine on
        RewriteCond %{HTTPS} off
        RewriteRule ^(.*) https://%{HTTP_HOST}/$1

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

# enable ssl apache config file without it you will get SSL_ERROR_RX_RECORD_TOO_LONG error
a2ensite default-ssl.conf

# let us restart apache
systemctl restart apache2.service

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*