NAGIOS 4 Instalacion en ubuntu server 14.04

NAGIOS 4 INSTALACIONEn este tutorial vamos a hacer una instalación de nagios4 sin el famoso apt-get , aquí os dejo un link para instalarlo con apt-get nagios3, la instalación la vamos a hacer de  forma manual en este tutorial: NAGIOS 4 INSTALACION. Como ya sabéis nagios es un potente monitorizador de red que nos va a permitir saber el estado de los servidores que componen nuestra red.

Para la instalación en ubuntu server 14.04 vamos a seguir los siguientes pasos:

ÍNDICE:

Contenido

PASO1: INSTALACIÓN DE PREREQUISITOS.

Para que funcione bien nuestro nagios 4 deberemos tener instalados una serie de programas y dependencias, Damos por sentado que el servidor tiene LAMP instalado, sino deberemos instalarlo con la siguiente sentencia:

INSTALAR LAMP (Linux Apache Mysql Php)

  • INSTALAR APACHE

sudo aptget install apache2

  • INSTALAR MYSQL

sudo aptget install mysqlserver php5mysql

  • INSTALAR PHP
sudo aptget install php5 libapache2modphp5 php5mcrypt php5-gd

INSTALAR DEPENDENCIAS:

Recordar que estas dependencias van a ser útiles para instalar posteriormente NAGVIS, NDO-UTILS, NAGIOS-PLUGINS, etc.

sudo apt-get install apache2 libapache2-mod-php5 php5-gd php5 make gcc build-essential wget libgd-gd2-perl libnet-snmp-perl libssl-dev snmp daemon wget apache2-utils curl daemon apt-file libpq5 libradius1 libsensors4 libsnmp-base libtalloc2 libtdb1 libwbclient0 samba-common samba-common-bin smbclient whois mrtg libcgi-pm-perl librrds-perl vim mysql-server php5-mysql graphviz unzip

PASO2: CREACIÓN DE GRUPOS Y USUARIOS NAGIOS 4.

Es necesario crear usuario y grupos para el correcto funcionamiento de nagios 4.

sudo groupadd nagios

sudo useradd -m -g nagios nagios
Introduzca la nueva contraseña de UNIX: *** NUEVA CONTRASEÑA ***
Vuelva a escribir la nueva contraseña de UNIX: *** NUEVA CONTRASEÑA ***
sudo groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios,nagcmd www-data

PASO 3: DESCARGAR Y DESCOMPRIMIR FICHERO NAGIOS 4.

Ahora vamos a proceder a descargar el paquete de instalación y posteriormente lo descomprimiremos

cd /

mkdir descargas

cd descargas

Descargamos el paquete de instalación de Nagios4:
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz

Descomprimimos el paquete de nagios:

tar -xzf nagios*.tar.gz

cd nagios-4.1.1/

Paso 4: NAGIOS 4 INSTALACION.

Ahora una vez descomprimido procedemos configurar la instalación con la siguiente sentencia:

Y ahora empezamos con la instalación ejecutando las siguientes sentencias:

./configure –with-nagios-user=nagios –with-nagios-group=nagios –with-openssl

make all
sudo make install

/usr/bin/install -c -m 755 -d -o root -g root /etc/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/init.d/nagios

*** Init script installed ***

sudo make install-commandmode

/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw

*** External command directory configured ***

sudo make install-init

/usr/bin/install -c -m 755 -d -o root -g root /etc/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/init.d/nagios

*** Init script installed ***

sudo make install-config

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files. You’ll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

sudo make install-webconf

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
/usr/bin/install: no se puede crear el fichero regular «/etc/httpd/conf.d/nagios.conf»: No existe el archivo o el directorio
make: *** [install-webconf] Error 1

sudo mkdir /etc/httpd/

sudo mkdir /etc/httpd/conf.d/

sudo make install-webconf

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/conf-enabled/nagios.conf

sudo cp /etc/apache2/conf-enabled/nagios.conf /etc/apache2/sites-available/nagios.conf

sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

y añadimos una contraseña para nagios

sudo service apache2 reload

sudo a2enmod rewrite
sudo a2enmod cgi

Ahora si tenemos problemas cuando reiniciamos el servidor de apache y nos sale este mensaje:
AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message
debemos editar el fichero httpd.conf con el siguiente comando:
nano /etc/apache2/apache2.conf
y agregar la siguiente línea:

ServerName localhost

Guardamos el fichero y volvemos a resetear el servicio

sudo a2enmod cgi

PASO 5: NAGIOS PLUGINS INSTALACION.

Al igual que el anterior lo primero que tenemos que hacer es descargarnos el fichero:

cd /

cd descargas

wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
tar -xzf nagios-plugins*.tar.gz
cd nagios-plugin-2.1.2/

ahora procedemos a la instalación de nagios pugins:

sudo ./configure –with-nagios-user=nagios –with-nagios-group=nagios

./configure –with-nagios-user=nagios –with-nagios-group=nagios –with-openssl
make
make install

Ahora para asegurarnos que NAGIOS4 se va a lanzar en el inicio corremos esta sentencia:

sudo update-rc.d nagios defaults

Si tuvieramos algún problema con los plugins otra manera de instalarlo es esta:

sudo apt-get install nagios-plugins

cp /usr/lib/nagios/plugins/check_* /usr/local/nagios/libexec

PASO 6: INSTALAR NDOUTILS

Antes de empezar necesitamos crear la base de datos ndo dentro de nuestro mysql

sudo mysqladmin -u root -p create ndo

a continuación le damos unos permisos:

mysql> GRANT ALL ON ndo.* TO «ndouser»@»localhost» IDENTIFIED BY «ndopassword»;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit

volvemos al directorio tmp

cd/

cd tmp

sudo wget http://downloads.sourceforge.net/project/nagios/ndoutils-2.x/ndoutils-2.0.0/ndoutils-2.0.0.tar.gz

sudo tar -xzf ndoutils-2.0.0.tar.gz

cd ndoutils-2.0.0/

sudo ./configure –disable-pgsql –with-mysql-lib=/usr/lib/mysql –with-ndo2db-user=nagios –with-ndo2db-group=nagios

sudo make

ahora ejecutamos las siguientes sentencias:

sudo cp src/ndomod-4x.o /usr/local/nagios/bin/ndomod.o

sudo cp src/ndo2db-4x /usr/local/nagios/bin/ndo2db

sudo cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg

sudo cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg

CONFIGURAR NDOUTILS

Editamos el fichero nagios.cfg

nano /usr/local/nagios/etc/nagios.cfg

Agregamos las siguientes líneas:

event_broker_options=-1
broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg

nano /usr/local/nagios/etc/ndomod.cfg

y verificar/cambiar los siguientes parametros:

instance_name=Central
output_type=unixsocket
output=/usr/local/nagios/var/ndo.sock
tcp_port=5668
output_buffer_items=5000
buffer_file=/usr/local/nagios/var/ndomod.tmp

Seguimos editando otro fichero:

sudo nano /usr/local/nagios/etc/ndo2db.cfg

verificamos/cambiamos si vemos algún parámetro diferente:

ndo2db_user=nagios
ndo2db_group=nagios
socket_type=unix
socket_name=/usr/local/nagios/var/ndo.sock
tcp_port=5668
db_servertype=mysql
db_host=localhost
db_name=ndo
db_port=3306
db_prefix=nagios_
db_user=ndouser
db_pass=ndopassword

ahora cambiamos unos permisos:

sudo chmod 774 /usr/local/nagios/bin/ndo*

sudo chown nagios:nagios /usr/local/nagios/bin/*

sudo chown nagios:nagios /usr/local/nagios/etc/ndo*

ahora creamos la base de datos:

cd db/

sudo ./installdb -u ndouser -p ndopassword -h localhost -d ndo

DBD::mysql::db do failed: Table ‘ndo.nagios_dbversion’ doesn’t exist at ./installdb line 51.
** Creating tables for version 2.0.1
Using mysql.sql for installation…
** Updating table nagios_dbversion
Done!

Ahora creamos un fichero nuevo:

sudo nano /etc/init.d/ndo2db

y agregamos las siguientes líneas:

#!/bin/sh
#
#
# chkconfig: 345 99 01
# description: Nagios to mysql
#
# Author : Gaëtan Lucas
# Realase : 07/02/08
# Version : 0.1 b
# File : ndo2db
# Description: Starts and stops the Ndo2db daemon
#              used to provide network services status in a database.
#

status_ndo ()
{
if ps -p $NdoPID > /dev/null 2>&1; then
return 0
else
return 1
fi

return 1
}

printstatus_ndo()
{
if status_ndo $1 $2; then
echo «ndo (pid $NdoPID) is running…»
else
echo «ndo is not running»
fi
}

killproc_ndo ()
{
echo «kill $2 $NdoPID»
kill $2 $NdoPID
}

pid_ndo ()
{
if test ! -f $NdoRunFile; then
echo «No lock file found in $NdoRunFile»
echo -n »         checking runing process…»
NdoPID=`ps h -C ndo2db -o pid`
if [ -z «$NdoPID» ]; then
echo »     No ndo2db process found»
exit 1
else
echo »     found process pid: $NdoPID»
echo -n »         reinit $NdoRunFile …»
touch $NdoRunFile
chown $NdoUser:$NdoGroup $NdoRunFile
echo «$NdoPID» > $NdoRunFile
echo »     done»
fi
fi

NdoPID=`head $NdoRunFile`
}

# Source function library
# Solaris doesn’t have an rc.d directory, so do a test first
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi

prefix=/usr/local/nagios
exec_prefix=${prefix}
NdoBin=${exec_prefix}/bin/ndo2db
NdoCfgFile=${prefix}/etc/ndo2db.cfg
NdoRunFile=${prefix}/var/ndo2db.run
NdoLockDir=/var/lock/subsys
NdoLockFile=ndo2db.lock
NdoUser=nagios
NdoGroup=nagiosgrp

# Check that ndo exists.
if [ ! -f $NdoBin ]; then
echo «Executable file $NdoBin not found.  Exiting.»
exit 1
fi

# Check that ndo.cfg exists.
if [ ! -f $NdoCfgFile ]; then
echo «Configuration file $NdoCfgFile not found.  Exiting.»
exit 1
fi

# See how we were called.
case «$1» in

start)
echo -n «Starting ndo:»
touch $NdoRunFile
chown $NdoUser:$NdoGroup $NdoRunFile
$NdoBin -c $NdoCfgFile
if [ -d $NdoLockDir ]; then
touch $NdoLockDir/$NdoLockFile;
fi
ps h -C ndo2db -o pid > $NdoRunFile
if [ $? -eq 0 ]; then
echo » done.»
exit 0
else
echo » failed.»
$0 stop
exit 1
fi
;;

stop)
echo -n «Stopping ndo: »

pid_ndo
killproc_ndo

# now we have to wait for ndo to exit and remove its
# own NdoRunFile, otherwise a following «start» could
# happen, and then the exiting ndo will remove the
# new NdoRunFile, allowing multiple ndo daemons
# to (sooner or later) run
#echo -n ‘Waiting for ndo to exit .’
for i in 1 2 3 4 5 6 7 8 9 10 ; do
if status_ndo > /dev/null; then
echo -n ‘.’
sleep 1
else
break
fi
done
if status_ndo > /dev/null; then
echo
echo ‘Warning – ndo did not exit in a timely manner’
else
echo ‘done.’
fi

rm -f $NdoRunFile $NdoLockDir/$NdoLockFile
;;

status)
pid_ndo
printstatus_ndo ndo
;;

restart)
$0 stop
$0 start
;;

*)
echo «Usage: ndo {start|stop|restart|status}»
exit 1
;;

esac

# End of this script

Ahora cambiamos una serie de parámetros:

sudo chown root:root /etc/init.d/ndo2db

sudo chmod 755 /etc/init.d/ndo2db

sudo update-rc.d ndo2db defaults

Ahora ya solo queda reiniciar los servicios:

sudo /etc/init.d/ndo2db

sudo service ndo2db start

sudo service nagios restart
Running configuration check…done.
Stopping nagios: done.
Starting nagios: done.

PASO 7: INSTALAR NAGVIS:

cd /

cd tmp

wget http://www.nagvis.org/share/nagvis-1.8.5.tar.gz

tar -xzf nagvis-1.8.5.tar.gz

cd nagvis-1.8.5/

sudo ./install.sh

+——————————————————————————+
| Welcome to NagVis Installer 1.8.5 |
+——————————————————————————+
| This script is built to facilitate the NagVis installation and update |
| procedure for you. The installer has been tested on the following systems: |
| – Debian, since Etch (4.0) |
| – Ubuntu, since Hardy (8.04) |
| – SuSE Linux Enterprise Server 10 and 11 |
| |
| Similar distributions to the ones mentioned above should work as well. |
| That (hopefully) includes RedHat, Fedora, CentOS, OpenSuSE |
| |
| If you experience any problems using these or other distributions, please |
| report that to the NagVis team. |
+——————————————————————————+
| Do you want to proceed? [y]: y
+——————————————————————————+
| Starting installation of NagVis 1.8.5 |
+——————————————————————————+
| OS : Ubuntu 14.04.5 LTS |
| |
+— Checking for tools ——————————————————-+
| Using packet manager /usr/bin/dpkg found |
| |
+— Checking paths ———————————————————–+
| Please enter the path to the nagios base directory [/usr/local/nagios]: <— ENTER
| nagios path /usr/local/nagios found |
| Please enter the path to NagVis base [/usr/local/nagvis]: <— ENTER
| |
+— Checking prerequisites —————————————————+
| PHP 5.5 found |
| PHP Module: gd 5.5 found |
| PHP Module: mbstring compiled_in found |
| PHP Module: gettext compiled_in found |
| PHP Module: session compiled_in found |
| PHP Module: xml compiled_in found |
| PHP Module: pdo compiled_in found |
| Apache mod_php MISSING |
| Checking Backends. (Available: mklivestatus,ndo2db,ido2db) |
| Do you want to use backend mklivestatus? [y]: n
| Do you want to use backend ndo2db? [n]: y
| Do you want to use backend ido2db? [n]: n
| /usr/local/nagios/bin/ndo2db (ndo2db) found |
| PHP Module: mysql 5.5 found |
| Graphviz 2.36 found |
| Graphviz Module dot 2.36.0 found |
| Graphviz Module neato 2.36.0 found |
| Graphviz Module twopi 2.36.0 found |
| Graphviz Module circo 2.36.0 found |
| Graphviz Module fdp 2.36.0 found |
dpkg-query: no packages found matching sqlite3
| WARNING: The SQLite package was not found. |
| This may not be a problem if you installed it from source |
| |
+— Trying to detect Apache settings —————————————–+
| Please enter the web path to NagVis [/nagvis]: <— ENTER
| Please enter the name of the web-server user [www-data]:  <— ENTER
| Please enter the name of the web-server group [www-data]:  <— ENTER
| create Apache config file [y]: y
| |
+— Checking for existing NagVis ———————————————+
| |
+——————————————————————————+
| Summary |
+——————————————————————————+
| NagVis home will be: /usr/local/nagvis |
| Owner of NagVis files will be: www-data |
| Group of NagVis files will be: www-data |
| Path to Apache config dir is: /etc/httpd/conf.d |
| Apache config will be created: yes |
| |
| Installation mode: install |
| |
| Do you really want to continue? [y]: y
+——————————————————————————+
| Starting installation |
+——————————————————————————+
| Creating directory /usr/local/nagvis… done |
| Creating directory /usr/local/nagvis/var… done |
| Creating directory /usr/local/nagvis/var/tmpl/cache… done |
| Creating directory /usr/local/nagvis/var/tmpl/compile… done |
| Creating directory /usr/local/nagvis/share/var… done |
| Copying files to /usr/local/nagvis… done |
| Creating directory /usr/local/nagvis/etc/profiles… done |
| Creating main configuration file… done |
| setting backend to ndomy_1 done |
| Adding webserver group to file_group… done |
| Creating web configuration file… done |
| Setting permissions for web configuration file… done |
| |
| |
| |
+— Setting permissions… —————————————————+
| /usr/local/nagvis/etc/nagvis.ini.php-sample done |
| /usr/local/nagvis/etc done |
| /usr/local/nagvis/etc/maps done |
| /usr/local/nagvis/etc/maps/* done |
| /usr/local/nagvis/etc/geomap done |
| /usr/local/nagvis/etc/geomap/* done |
| /usr/local/nagvis/etc/profiles done |
| /usr/local/nagvis/share/userfiles/images/maps done |
| /usr/local/nagvis/share/userfiles/images/maps/* done |
| /usr/local/nagvis/share/userfiles/images/shapes done |
| /usr/local/nagvis/share/userfiles/images/shapes/* done |
| /usr/local/nagvis/var done |
| /usr/local/nagvis/var/* done |
| /usr/local/nagvis/var/tmpl done |
| /usr/local/nagvis/var/tmpl/cache done |
| /usr/local/nagvis/var/tmpl/compile done |
| /usr/local/nagvis/share/var done |
| |
+——————————————————————————+
| Installation complete |
| |
| You can safely remove this source directory. |
| |
| For later update/upgrade you may use this command to have a faster update: |
| ./install.sh -n /usr/local/nagios -p /usr/local/nagvis -b ndo2db -u www-data -g www-data -w /etc/httpd/conf.d -a y
| |
| What to do next? |
| – Read the documentation |
| – Maybe you want to edit the main configuration file? |
| Its location is: /usr/local/nagvis/etc/nagvis.ini.php |
| – Configure NagVis via browser |
| <http://localhost/nagvis/config.php> |
| – Initial admin credentials: |
| Username: admin |
| Password: admin |
+——————————————————————————+

sudo ln -s /etc/apache2/sites-available/nagvis.conf /etc/apache2/sites-enabled/

sudo cp /tmp/nagvis-1.8.5/etc/apache2-nagvis.conf-sample /etc/httpd/conf.d/nagvis.conf

sudo nano /etc/apache2/httpd/nagvis.conf

Descomentar las siguientes líneas quitando en la cabecera #:

AuthName «NagVis Access»
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

cp /etc/apache2/httpd/nagvis.conf /etc/apache2/sites-available/nagvis.conf

sudo ln -s /etc/apache2/sites-available/nagvis.conf /etc/apache2/sites-enabled/

sudo nano/usr/local/nagvis/etc/nagvis.ini.php

PASO 6: CONFIGURAR NAGIOS 4.

Tenemos que editar el siguiente fichero para descomentar una línea, exactamente la línea 51:

nano /usr/local/nagios/etc/nagios.cfg

y quitamos la # en la línea que dice:

cfg_dir=/usr/local/nagios/etc/servers

guardamos el fichero y salimos.

agregamos ese directorio:

sudo mkdir /usr/local/nagios/etc/servers

Configuramos ahora el email en el archivo contacts.cfg, accedemos a él con «nano» para editarlo:

nano /usr/local/nagios/etc/objects/contacts.cfg

y donde pone:

email           nagios@localhost

lo sustituimos por una dirección email que se va a encargar de enviarnos incidencias, alertas, etc.

PASO 7: CONFIGURAR APACHE PARA NAGIOS 4.

  • Activamos los modulos de Apache:

sudo a2enmod rewrite
sudo a2enmod cgi

Ahora si tenemos problemas cuando reiniciamos el servidor de apache y nos sale este mensaje:
AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message
debemos editar el fichero httpd.conf con el siguiente comando:
nano /etc/apache2/apache2.conf
y agregar la siguiente línea:

ServerName localhost

Guardamos el fichero y volvemos a resetear el servicio

  • Cambiar la contraseña del usuario nagiosadmin:

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

e introducimos la contraseña del usuario nagiosadmin que nos va a valer para acceder a la web.

  • Activar el virtual host de nagios 4

sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/

  • Reseteamos los servicios de apache e iniciamos el servicio de nagios

service apache2 restart
service nagios start

Una vez iniciado el servicio de nagios abriremos un navegador para introducir la siguiente dirección:

http:///nagios

nagios 4 instalación

Pues ya tenemos terminado nuestro tutorial de nagios 4 instalacion.

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *