systemadmin.es > Monitorización > Instalación de Nagios 4

Instalación de Nagios 4

Vamos a ver la instalación de la última versión de nagios: Nagios 4, que modifica ligeramente la interfaz por defecto

Primero de todo deberemos añadir el usuario nagios y preparar el entorno:

useradd nagios
mkdir -p /var/lib/nagios
chown nagios. /var/lib/nagios

A continuación deberemos bajar el código fuente de nagios core y lo compilamos:

./configure --prefix=/usr/local/ \
            --exec-prefix=/usr/local/ \
            --with-nagios-user=nagios \
            --with-nagios-group=nagios \
            --with-command-user=nagios \
            --with-command-group=nagios \
            --with-httpd-conf=/etc/apache2/sites-available/ \
            --localstatedir=/var/lib/nagios \
            --datarootdir=/var/www/nagios/htdocs \
            --with-htmurl= \
            --with-cgiurl=/cgi-bin \
            --sbindir=/var/www/nagios/htdocs/cgi-bin

Al final del configure nos dará un resumen de lo que hemos configurado:

(...)
*** Configuration summary for nagios 4.0.5 04-11-2014 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagios
             Event Broker:  yes
        Install ${prefix}:  /usr/local
    Install ${includedir}:  /usr/local/include/nagios
                Lock file:  /var/lib/nagios/nagios.lock
   Check result directory:  /var/lib/nagios/spool/checkresults
           Init directory:  /etc/init.d
  Apache conf.d directory:  /etc/apache2/sites-available/
             Mail program:  /usr/bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost//
                  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.

Compilamos mediante:

make all

Primero instamos los programas, CGIs, los ficheros HTML, el script de inicio y una configuración de ejemplo que nos servirá de base:

make install
make install-init
make install-commandmode
make install-config
make install-cgis
make install-html

Añadimos la opción configtest al script de inicio de nagios para que añada más información que el checkconfig:

sed 's/*)/configtest)\n\t\tprintf "Running configuration check..."\n\t\t\$NagiosBin -v \$NagiosCfgFile\n\t\t;;\t\n\n\t*)/g' -i /etc/init.d/nagios

Por ejemplo, mediante configtest veríamos:

# /etc/init.d/nagios configtest

Nagios Core 4.0.5
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 04-11-2014
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
	Checked 8 services.
	Checked 1 hosts.
	Checked 1 host groups.
	Checked 0 service groups.
	Checked 1 contacts.
	Checked 1 contact groups.
	Checked 24 commands.
	Checked 5 time periods.
	Checked 0 host escalations.
	Checked 0 service escalations.
Checking for circular paths...
	Checked 1 hosts
	Checked 0 service dependencies
	Checked 0 host dependencies
	Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check
Object precache file created:
/var/lib/nagios/objects.precache

Mientras que con checkconfig obtendríamos:

# /etc/init.d/nagios checkconfig
Running configuration check...
 OK.

A continuación reordenamos el directorio de configuración de nagios mediante subdirectorios:

mv /usr/local/etc/objects/ /usr/local/etc/nagios
sed 's@etc/objects@etc/nagios@' -i /usr/local/etc/nagios.cfg 
mkdir -p /usr/local/etc/nagios/resource
mkdir -p /usr/local/etc/nagios/commands
mkdir -p /usr/local/etc/nagios/contacts
mkdir -p /usr/local/etc/nagios/timeperiods
mkdir -p /usr/local/etc/nagios/templates
mkdir -p /usr/local/etc/nagios/localhost
mv /usr/local/etc/resource.cfg /usr/local/etc/nagios/resource
mv /usr/local/etc/nagios/localhost.cfg /usr/local/etc/nagios/localhost
mv /usr/local/etc/nagios/commands.cfg /usr/local/etc/nagios/commands
mv /usr/local/etc/nagios/contacts.cfg /usr/local/etc/nagios/contacts
mv /usr/local/etc/nagios/timeperiods.cfg /usr/local/etc/nagios/timeperiods
mv /usr/local/etc/nagios/templates.cfg /usr/local/etc/nagios/templates
sed 's@\(.*\)/\([^\.]*\)\.cfg$@\1/\2/\2.cfg@' -i /usr/local/etc/nagios.cfg 

A continuación deberemos preparar el VirtualHost para el nagios:

cat > /etc/apache2/sites-available/nagios.conf <<"EOF"
<VirtualHost *:80>

DocumentRoot /var/www/nagios/htdocs
ServerName nagios.lolcathost.perdiguer.com

ScriptAlias /nagios/cgi-bin "/var/www/nagios/htdocs/cgi-bin"

<Directory "/var/www/nagios/htdocs/cgi-bin">
#  SSLRequireSSL
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/etc/nagios/htpasswd.users
   Require valid-user
</Directory>

<Directory "/var/www/nagios/htdocs">
#  SSLRequireSSL
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/etc/nagios/htpasswd.users
   Require valid-user
</Directory>

</VirtualHost>
EOF

Creamos el usuario nagiosadmin con la contraseña “systemadmin.es” mediante:

htpasswd -cb /usr/local/etc/nagios/htpasswd.users nagiosadmin systemadmin.es

Lo habilitamos mediante:

ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/
/etc/init.d/apache2 restart

Para poder realizar los checks deberemos instalar los diferentes checks de nagios:

cd /usr/local/src/
wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
tar xzf nagios-plugins-2.0.tar.gz 
cd nagios-plugins-2.0/
./configure --prefix=/usr/local/ --exec-prefix=/usr/local/ --with-mysql
make && make install

Además del NRPE para la ejecución de los mismos en equipos remotos:

cd /usr/local/src
wget 'http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz'
tar xzf nrpe-2.15.tar.gz 
cd nrpe-2.15/
./configure  --prefix=/usr/local --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/i386-linux-gnu
make && make install

Finalmente ya podemos arrancar nagios:

# /etc/init.d/nagios start
Starting nagios: done.

Podemos verificar su funcionamiento mediante el fichero /var/lib/nagios/nagios.log:

# tail -f /var/lib/nagios/nagios.log 
[1398426654] nerd: Channel servicechecks registered successfully
[1398426654] nerd: Channel opathchecks registered successfully
[1398426654] nerd: Fully initialized and ready to rock!
[1398426654] wproc: Successfully registered manager as @wproc with query handler
[1398426654] wproc: Registry request: name=Core Worker 1055;pid=1055
[1398426654] wproc: Registry request: name=Core Worker 1054;pid=1054
[1398426654] wproc: Registry request: name=Core Worker 1053;pid=1053
[1398426654] wproc: Registry request: name=Core Worker 1052;pid=1052
[1398426654] Successfully launched command file worker with pid 1056
[1398426658] HOST ALERT: localhost;UP;SOFT;2;PING OK - Packet loss = 0%, RTA = 0.06 ms

Para que desde la interfaz web se puedan mandar comandos a nagios deberemos añadir el grupo nagios a usuario con el que corra el servidor web (en este caso www-data):

usermod -a -G nagios www-data

A continuación accediendo con el navegador en la URL que hayamos configurado podremos ver la interfaz de nagios:

Interfaz nagios 4

Interfaz nagios 4

A partir de aquí ya sólo nos queda configurar los diferentes hosts a monitorizar

Servidor de Nagios instalado

Servidor de Nagios instalado

Deja un comentario:

XHTML - Tags permitidos:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>