viernes, 5 de diciembre de 2014

Expiró licencia de VMware 5.5 free

mv /etc/vmware/license.cfg /etc/vmware/license.cfg.05-12-2014
cp /etc/vmware/.#license.cfg /etc/vmware/license.cfg
/etc/init.d/vpxa restart

restart el VMware server

miércoles, 26 de noviembre de 2014

Balanceo de Carga y Alta Disponibilidad en un Webserver con Apache y Perl (versión 2)



En este enlace http://redes-seguridad.blogspot.com.ar/2014/07/balanceo-de-carga-y-alta-disponibilidad.html les mostré como hacer el balanceo aleatorio entre 2 webservers, detectaba si uno de ambos estaba caído enviaba las peticiones web's al otro:

Pero quedaba pendiente verificar el "CPU load" antes de hacer la redirección y basarse en la carga en vez de redireccionar aleatoria-mente. Con esta última versión del script cubrimos ese tema:


Escenario:

Tenemos 2 servidores web, cada uno escuchando en el mismo puerto la misma aplicación.

El script irá distribuyendo al webServer que tenga menor "Carga de CPU", en caso que alguno tenga el puerto bajo, es decir que la aplicación esté baja reenviará las peticiones al webserver que esté arriba.

Es decir, pueden ocurrir las diferentes situaciones:

1) Ambos servidores UP y con la aplicación ok, testea al de menor uso de CPU y redirige la petición a este.
2) Servidor1 caído ó la aplicación DOWN => redirecciona al Servidor2.
3) Servidor2 caído ó la aplicación DOWN => redirecciona al Servidor1.
4) Ambos Servidores caidos, en mi caso no hago nada, pero puedo mostrar algún mensaje que deseen.



Script:


#!/usr/bin/perl

##Descomentar la siguiente linea si desea ver lo que hace en vez de ejecutar la redirección:
#print "content-type: text/html \n\n";

##Escanea al WebServer1 el puerto 80 y verifica si está abierto, guarda en la variable $VAL1 si el comando fue correcto ó no:
$result1 = `nmap -sT -P0 WebServer1-p 80|grep open`;
$VAL1=$?;

##Escanea al WebServer2 el puerto 80 y verifica, idem al anterior, pero guarda el valor en $VAL2:
$result2 = `nmap -sT -P0 WebServer2 -p 80|grep open`;
$VAL2=$?;

##Concatena los valores de $VAL1 y $VAL2 en $VAL:
$VAL=$VAL1.$VAL2;

##Descomento las siguientes líneas si deseo ver los valores que obtienen las variables, recuerde que también debe descomentar la línea del conten-type que aparece al inicio del script:
#print "VAL1: ", $VAL1, "";
#print "VAL2: ", $VAL2, "";
#print "VAL:   ", $VAL,   "";

##Para pruebas hardcodeadas modificar y descomentar las siguientes variables:
## El valor 00     => ambos servidores escuchan, ver por CPU cual es el de menor uso
## El valor 0256   => redirige a WebServer01 (WebServer01 caido)
## El valor 2560   => redirige a WebServer02 (JDE05 caido)
## El valor 256256 => ambos webservers caido
#$VAL="00";
use Switch;
switch ($VAL)
{
 case "00"
 {
  ##Tener en cuenta que con el usuario de root no funciona, por eso utilicé el de apache, recuerde generar las keys ssh para el usuario www-data:
  my $CPU_SERVER1 = `ssh www-data'\@'ServerNagios /ruta/al/script/de/nagios/libexec/check_nt -H WebServer1 -v CPULOAD -l 5,80,90 | cut -d' ' -f3 | cut -d'%' -f1`;

  my $CPU_SERVER2 = `ssh www-data'\@'ServerNagios /ruta/al/script/de/nagios/libexec/check_nt -H WebServer2 -v CPULOAD -l 5,80,90 | cut -d' ' -f3 | cut -d'%' -f1`;

  ##Descomentar si desea ver valores, recuerde descomentar la content-type al inicio del script
  #print "SERVER1: ", $CPU_SERVER1, " ";
  #print "SERVER2: ", $CPU_SERVER2, " ";

  ##Evalua quien tene menor uso de CPU: 
  if ( $CPU_SERVER1 > $CPU_SERVER2)
  {
   ##Tener en cuenta que esto redirecciona, si descomenta el content-type lo mostrará por pantalla   
   print "Location: http://WebServer2:80/aplicacion\n\n";
  }
  else
  {
   ##Tener en cuenta que esto redirecciona, si descomenta el content-type lo mostrará por pantalla   
   print "Location: http://WebServer1:80/aplicacion\n\n";
  }
 }
 case "0256"    { print "Location: http://WebServer1:80/aplicacion\n\n"; }
 case "2560"    { print "Location: http://WebServer2:80/aplicacion\n\n"; }
 case "256256"  { print "Ningun webserver (WebServer1 y WebServer2) escucha en el puerto 80" }
 else           { print "Valor no contemplado en el Perl de Load Balance" }
}

viernes, 31 de octubre de 2014

Script para Restore de informix con ontape y expect en Solaris

#!/opt/csw/bin/expect -f
set timeout -1
spawn /usr/local/apps/informix/bin/ontape -r
expect "Please mount tape 1 on /ruta/de/informix/bkp.full and press Return to continue ..."
send -- "\r"
expect "Continue restore? (y/n)"
send -- "y\r"
expect "Do you want to back up the logs? (y/n)"
send -- "n\r"
expect "Restore a level 1 archive (y/n)"
send -- "n\r"
expect "Do you want to restore log tapes? (y/n)"
send -- "n\r"
expect eof

Reinstalando expect on solaris 10 -bash: /usr/local/bin/expect: Invalid argument

Al obtener el siguiente error y no poder arreglarlo:

server pkg# expect
-bash: /usr/local/bin/expect: Invalid argument


Me decidí a reistalarlo, buscamos el paquete con pkgutil:
(Si no tenemos instalado pkgutil consultar en este enlace: http://redes-seguridad.blogspot.com.ar/2012/05/instalar-paquetes-y-dependencias.html)

server pkg# /opt/csw/bin/pkgutil -a expect
=> Fetching new catalog and descriptions (http://mirror.opencsw.org/opencsw/testing/i386/5.10) if available ...
==> 3612 packages loaded from /var/opt/csw/pkgutil/catalog.mirror.opencsw.org_opencsw_testing_i386_5.10
common               package              catalog                        size
expect               CSWexpect            5.45,REV=2013.04.10        218.6 KB
pm_expect            CSWpm-expect         1.21,REV=2013.08.18         49.7 KB
pm_expect_simple     CSWpm-expect-simple  0.04,REV=2013.08.18         14.3 KB
py_pexpect           CSWpy-pexpect        2.3,REV=2013.09.10          68.0 KB


Lo instalamos:

server pkg# /opt/csw/bin/pkgutil -i CSWexpect
Solving needed dependencies ...
Solving dependency order ...
1 CURRENT packages:
        CSWcommon-1.5,REV=2010.12.11
Install 4 NEW packages:
        CSWexpect-5.45,REV=2013.04.10 (opencsw/testing)
        CSWlibtcl8-5-8.5.15,REV=2013.10.09 (opencsw/testing)
        CSWsunmath-2007.08.04 (opencsw/testing)
        CSWtcl8-tclmodules-8.5.15,REV=2013.10.09 (opencsw/testing)
Total size: 2.2 MB
4 packages to fetch. Do you want to continue? ([y],n,auto)
=> Fetching CSWsunmath-2007.08.04 (1/4) ...
=> Fetching CSWtcl8-tclmodules-8.5.15,REV=2013.10.09 (2/4) ...
...
...
Installation of was successful.


Lo ejecutamos:

server pkg# /opt/csw/bin/expect


jueves, 23 de octubre de 2014

Instalando Webmin en Debian 7



Editamos el source list para agregar un nuevo repositorio:

root@Server:~# vi /etc/apt/sources.list
deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib


Actualizamos para que tome el cambio el nuevo repositorio, pero nos indica que no está disponible la key pública:

root@Server:~# apt-get update
....
Reading package lists... Done
W: GPG error: http://webmin.mirror.somersettechsolutions.co.uk sarge Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D97A3AE911F63C51
W: GPG error: http://download.webmin.com sarge Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D97A3AE911F63C51
....


Vamos a la ruta donde queremos descargar la key:

root@Server:~# cd /root

root@Server:~# wget http://www.webmin.com/jcameron-key.asc
--2014-10-20 12:01:48--  http://www.webmin.com/jcameron-key.asc
Resolving www.webmin.com (www.webmin.com)... 216.34.181.97
Connecting to www.webmin.com (www.webmin.com)|216.34.181.97|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1320 (1.3K) [text/plain]
Saving to: `jcameron-key.asc'
100%[=======================================================================================================================================>] 1,320       --.-K/s   in 0s
2014-10-20 12:01:48 (71.9 MB/s) - `jcameron-key.asc' saved [1320/1320]


Agregamos la key:

root@Server:~# apt-key add jcameron-key.asc
OK


Esta vez si nos dejará actualizar:

root@Server:~# apt-get update
Get:1 http://ftp.ccc.uba.ar wheezy Release.gpg [1,655 B]
Get:2 http://ftp.ccc.uba.ar wheezy-updates Release.gpg [836 B]
Get:3 http://ftp.ccc.uba.ar wheezy Release [168 kB]
Get:4 http://ftp.ccc.uba.ar wheezy-updates Release [124 kB]
Get:5 http://ftp.ccc.uba.ar wheezy/main Sources [5,955 kB]
Get:6 http://download.webmin.com sarge Release.gpg [189 B]
Hit http://security.debian.org wheezy/updates Release.gpg
Get:7 http://webmin.mirror.somersettechsolutions.co.uk sarge Release.gpg [189 B]
Hit http://security.debian.org wheezy/updates Release
Hit http://webmin.mirror.somersettechsolutions.co.uk sarge Release
Hit http://download.webmin.com sarge Release
Hit http://webmin.mirror.somersettechsolutions.co.uk sarge/contrib amd64 Packages
Hit http://download.webmin.com sarge/contrib amd64 Packages
Hit http://security.debian.org wheezy/updates/main Sources
Hit http://security.debian.org wheezy/updates/main amd64 Packages
Hit http://security.debian.org wheezy/updates/main Translation-en
Ign http://webmin.mirror.somersettechsolutions.co.uk sarge/contrib Translation-en_US
Ign http://webmin.mirror.somersettechsolutions.co.uk sarge/contrib Translation-en
Ign http://download.webmin.com sarge/contrib Translation-en_US
Ign http://download.webmin.com sarge/contrib Translation-en
Get:8 http://ftp.ccc.uba.ar wheezy/main amd64 Packages [5,841 kB]
Get:9 http://ftp.ccc.uba.ar wheezy/main Translation-en [3,846 kB]
Get:10 http://ftp.ccc.uba.ar wheezy-updates/main Sources [14 B]
Get:11 http://ftp.ccc.uba.ar wheezy-updates/main amd64 Packages/DiffIndex [1,609 B]
Get:12 http://ftp.ccc.uba.ar wheezy-updates/main Translation-en/DiffIndex [1,057 B]
Fetched 15.9 MB in 25s (620 kB/s)
Reading package lists... Done
root@Server:~#


Instalamos el webmin, le damos a 'Y' para confirmar:

root@Server:~# apt-get install webmin
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libdbi-perl libodbc1
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  apt-show-versions libapt-pkg-perl libauthen-pam-perl libio-pty-perl
The following NEW packages will be installed:
  apt-show-versions libapt-pkg-perl libauthen-pam-perl libio-pty-perl webmin
0 upgraded, 5 newly installed, 0 to remove and 22 not upgraded.
Need to get 22.1 MB of archives.
After this operation, 141 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y

Get:1 http://ftp.ccc.uba.ar/pub/linux/debian/debian/ wheezy/main libauthen-pam-perl amd64 0.16-2+b2 [31.3 kB]
Get:2 http://ftp.ccc.uba.ar/pub/linux/debian/debian/ wheezy/main libio-pty-perl amd64 1:1.08-1+b2 [40.0 kB]
Get:3 http://ftp.ccc.uba.ar/pub/linux/debian/debian/ wheezy/main libapt-pkg-perl amd64 0.1.26+b1 [84.7 kB]
1% [Connecting to download.webmin.com]
Get:4 http://ftp.ccc.uba.ar/pub/linux/debian/debian/ wheezy/main apt-show-versions all 0.20 [34.9 kB]
Get:5 http://download.webmin.com/download/repository/ sarge/contrib webmin all 1.710 [21.9 MB]
Fetched 22.1 MB in 1min 16s (288 kB/s)
Selecting previously unselected package libauthen-pam-perl.
(Reading database ... 45191 files and directories currently installed.)
Unpacking libauthen-pam-perl (from .../libauthen-pam-perl_0.16-2+b2_amd64.deb) ...
Selecting previously unselected package libio-pty-perl.
Unpacking libio-pty-perl (from .../libio-pty-perl_1%3a1.08-1+b2_amd64.deb) ...
Selecting previously unselected package libapt-pkg-perl.
Unpacking libapt-pkg-perl (from .../libapt-pkg-perl_0.1.26+b1_amd64.deb) ...
Selecting previously unselected package apt-show-versions.
Unpacking apt-show-versions (from .../apt-show-versions_0.20_all.deb) ...
Selecting previously unselected package webmin.
Unpacking webmin (from .../archives/webmin_1.710_all.deb) ...
Processing triggers for man-db ...
Setting up libauthen-pam-perl (0.16-2+b2) ...
Setting up libio-pty-perl (1:1.08-1+b2) ...
Setting up libapt-pkg-perl (0.1.26+b1) ...
Setting up apt-show-versions (0.20) ...
** initializing cache. This may take a while **
Setting up webmin (1.710) ...
Webmin install complete. You can now login to https://Server:10000/
as root with your root password, or as any user who can use sudo
to run commands as root.

miércoles, 22 de octubre de 2014

Script para copiar y verificar la copia de archivos con MD5 en Solaris

#!/bin/bash

echo "Verifico el tamaño del archivo local:"
VAR1=`du -sk /ruta/al/archivo`

echo "Copiando el archivo al servidor remoto:"
scp /ruta/al/archivo server:/ruta/remota/al/archivo

echo "Verifico el tamaño del archivo remoto:"
VAR2=`ssh server du -sk /ruta/remota/al/archivo`

echo "Verifico el md5 del archivo local:"
VAR3=`digest -v -a md5 /ruta/al/archivo | cut -d "=" -f2`

echo "Verifico el md5 del archivo remoto"
VAR4=`ssh server digest -v -a md5 /ruta/al/archivo | cut -d "=" -f2`

if [ "$VAR1" = "$VAR2" ];
then
 echo "Tamanos iguales."
else
 echo "Tamano incorrecto - Copia incorrecta !!"
fi

if [ "$VAR3" = "$VAR4" ];
then
 echo "Hashes iguales."
 echo "La copia ha finalizado correctamente."
else
 echo "Tamano incorrecto - Copia incorrecta !!"
fi

martes, 21 de octubre de 2014

UX: useradd: ERROR: Inconsistent password files. See pwconv(1M).

Al querer agregar un nuevo usuario me aparecía el siguiente mensaje:

UX: useradd: ERROR: Inconsistent password files. See pwconv(1M).


Parece que alguien previamente editó el /etc/passwd y había inconsistencia el archivo passwd y el shadow.

Ejecutar el pwconf para actualizarlo:

# pwconv