miércoles, 18 de agosto de 2010

gentoo - genkernel modules

Cada vez que compile un nuevo núcleo o recompile el actual, necesitará reinstalar los módulos del núcleo de nVidia. Una forma fácil de seguir la pista de los módulos instalados por los ebuilds (como nvidia-drivers es instalar sys-kernel/module-rebuild. Una vez lo haya instalado, simplemente ejecute module-rebuild populate para llenar su base de datos con una lista de paquetes que deben reconstruirse. Una vez haya terminado de compilar o recompilar un núcleo, simplemente ejecute module-rebuild rebuild para reconstruir los controladores para su nuevo núcleo. 

martes, 17 de agosto de 2010

Openbox & sesiones ssh - ssh-agent ssh-add -

El problema que tenia es que cuando arrancaba el agente de ssh (eval `ssh-agent`) y ssh-add en un terminal, las variables de entorno que hacen referencia a la ubicación de los archivos y pid no eran visibles para otras sesiones de terminal y por lo tanto me pedia de nuevo hacer ssh-add en cada consola.

SSH_AUTH_SOCK=/tmp/ssh-xBlFuc3166/agent.3166; export SSH_AUTH_SOCK;
SSH_AGENT_PID=3167; export SSH_AGENT_PID;

La solución que me ha funcionado en openbox es añadir en el fichero .xinitrc eval `ssh-agent -s` para que qeuede así:

eval `ssh-agent -s`
exec ck-launch-session dbus-launch openbox-session

jueves, 5 de agosto de 2010

Wrapper sobre ncsvc cliente vpn juniper

Nueva forma de conectarme sin usar el cliente de juniper network connect. Un sencillo wrapper que ahorra usar java. Solo es necesario el binario de ncsvc y ejecutar el script como root.


#!/bin/bash
# Wrapper sobre ncsvc.
set +o posix

ok() { echo -ne "\e[32m#\n#\t$1\n#\e[m\n"; }
nk() { echo -ne "\e[31m#\n#\t$1\n#\e[m\n"; exit 1; }

USER="usuario"
HOST="hostvpn.dominio.com"
REALM="sistemas"
[ $HOST ] && [ $REALM ] || nk "Falta especificar HOST y/o REALM en el script."

PATH=$PATH:$(dirname $0)
ok "Verificando binarios wvdial pppd y grep:"
which ncsvc pgrep openssl kill || nk "Faltan binarios!"
[ $(uname -m) = "x86_64" ] && ok ": Se necesita comp. 32 bits. Arch: pacman -S lib32-glibc lib32-gcc-libs lib32-zlib"

pgrep ncsvc > /dev/null && {
ok "Procesos ncscv corriendo, los mato..."
ncsvc -K || for i in `pgrep ncsvc`; do kill -9 $i; done
ok "OK!"
} || {
[ $USER ] || { ok "Usuario: "; read -r USER; }
[ $USER ] || nk "El usuario no puede ser nulo!"
ok "Conectando..."
ncsvc -u $USER -h $HOST -r $REALM -f <(openssl x509 -in <(openssl s_client -connect secure.dominio.com:443 /dev/null | sed -n '1h;1!H;${;g;s/.*\(-----BE.*TE-----\).*/\1/p;}') -outform der)    reset } 
Gracias Oscar por esta solucion :)

miércoles, 4 de agosto de 2010

Powermt Management

Un pequeño script para escanear las HBAs y descubir los targets que hay asignados

lun_scan.sh



#!/bin/sh
#
#/*******************************************************************
# * This file is part of the Emulex Linux Device Driver for *
# * Fibre Channel Host Bus Adapters. *
# * Copyright (C) 2003-2005 Emulex. All rights reserved. *
# * EMULEX and SLI are trademarks of Emulex. *
# * www.emulex.com *
# * *
# * This program is free software; you can redistribute it and/or *
# * modify it under the terms of version 2 of the GNU General *
# * Public License as published by the Free Software Foundation. *
# * This program is distributed in the hope that it will be useful. *
# * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
# * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
# * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
# * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
# * TO BE LEGALLY INVALID. See the GNU General Public License for *
# * more details, a copy of which can be found in the file COPYING *
# * included with this package. *
# *******************************************************************/
#
# scripts/lun_scan Rev : 1.2
# This script is provided by Emulex to use with its 7.x and 8.x linux device
# drivers for Light Pulse Fibre Channel adapters.
#
# This script performs a scan on either specific lpfc HBAs or on all
# lpfc HBAs. When scanning an HBA, all discovered targets, and all
# luns will be probed.
#
#
# USAGE: The script is invoked with at least 1 argument. The arguments
# specify either the SCSI Host numbers corresponding to the specific
# lpfc HBA that are to be scanned, or the keyword "all" which indicates
# that all lpfc HBAs are to be scanned.
#

VERSION="1.2"
OS_REV=`uname -r | cut -c1-3`

usage()
{
echo ""
echo "Usage: lun_scan [ <#> [<#>] | all ]"
echo " where "
echo " <#> : is a scsi host number of a specific lpfc HBA that is to"
echo " be scanned. More than 1 host number can be specified. "
echo " all : indicates that all lpfc HBAs are to be scanned."
echo ""
echo " Example:"
echo " lun_scan all : Scans all lpfc HBAs"
echo " lun_scan 2 : Scans the lpfc HBA with scsi host number 2"
echo " lun_scan 2 4 : Scans the lpfc HBAs with scsi host number 2 and 4"
echo ""
echo " Warning: Scanning an adapter while performing a tape backup should"
echo " be avoided."
echo ""
}

abort_exit() {
echo ""
echo "Error: Cannot find an lpfc HBA instance with scsi host number : $host"
echo "... Aborting lun_scan."
echo ""
exit 2
}

# Validate argument list
if [ $# -eq 0 -o "$1" = "--help" -o "$1" = "-h" ] ; then
usage
exit 1
fi

# Get list of lpfc HBAs to scan
hosts=$*;

if [ ${OS_REV} = 2.4 ]; then
lowhost=0
ha=`ls /proc/scsi/lpfc/? 2> /dev/null | cut -f5 -d'/'`
hb=`ls /proc/scsi/lpfc/?? 2> /dev/null | cut -f5 -d'/'`
hc=`ls /proc/scsi/lpfc/??? 2> /dev/null | cut -f5 -d'/'`
all_hosts="$ha $hb $hc"
lowhost=`echo $all_hosts | sed "s/ .*//"`
else
all_hosts=`ls -1 -d /sys/bus/pci/drivers/lpfc/*/host* | sed -e "s/.*host//"`
fi

# If all option is used get all the lpfc host numbers.
if [ "$hosts" == "all" ] ; then
hosts="$all_hosts"
fi

if [ ${OS_REV} = 2.4 ]; then

for host in $hosts ; do
# Convert host number to lpfc instance number.
instance=`expr $host - $lowhost`

if [ ! -e /proc/scsi/lpfc/$host ] ; then
abort_exit
fi

echo Scanning lpfc$instance, scsi host number : $host;

max_lun=256

targets=`cat /proc/scsi/lpfc/$host | grep 'lpfc*t*' | cut -f2 -d't' | cut -f1 -d' '`

for target in $targets ; do
# Convert target ID to decimal from Hex format
let "dec_target = 0x$target"
echo " Scanning Target Id $dec_target..."
for ((lun=0; lun<$max_lun; lun++)) ; do echo "scsi add-single-device $host 0 $dec_target $lun" >/proc/scsi/scsi
done
done
done

else

for host in $hosts ; do
if [ ! -e /sys/bus/pci/drivers/lpfc/*/host$host ] ; then
abort_exit
fi

echo Scanning lpfc HBA instance with scsi host number : $host;
echo '- - -' > /sys/class/scsi_host/host$host/scan
done

fi

echo ""
Ejecutamos el script:
lun_scan.sh all

Hacemos que powermt vea la nueva lun

powermt check
powermt config
powermt save

Mostramos lo que ve powermt
powermt display dev=all

viernes, 9 de julio de 2010

Firewalling - Ver que firewall corta el paso con hping

Imaginamos un entorno de red complejo donde hay nose, 4 saltos entre nuestra máquina y un servidor. Dentro de estos saltos hay switchs, routers, firewalls, etc... Y queremos ver donde se esta cortando la comunicación por ejemplo el puerto 8080.

Hacemos un traceroute -In 192.168.1.4 para ver los saltos.
traceroute to 192.168.1.4 (192.168.1.4), 30 hops max, 52 byte packets
1 192.168.12.1 1.008 ms 0.540 ms 0.535 ms
2 192.168.23.33 1.670 ms 1.115 ms 1.111 ms
3 192.168.25.3 0.631 ms 1.156 ms 0.598 ms
4 192.168.1.4 1.444 ms 1.343 ms 1.281 ms

Con el comando hping podemos comprobar en que hop no pasamos

hping 192.168.1.4 -p 8080 -St 1
TTL 0 during transit from ip=192.168.12.1 name=router1
TTL 0 during transit from ip=192.168.12.1 name=router1
TTL 0 during transit from ip=192.168.12.1 name=router1

Ok por el hop 1 pasamos, probamos por el segundo
hping 192.168.1.4 -p 8080 -St 2
TTL 0 during transit from ip=192.168.23.33 name=UNKNOWN
TTL 0 during transit from ip=192.168.23.33 name=UNKNOWN

Ok por el hop 2 pasamos, probamos por el tercero
hping 192.168.1.4 -p 8080 -St 3
HPING 192.168.1.4 (eth0 192.168.1.4): S set, 40 headers + 0 data bytes
^C
No contesta. Ya sabemos que el firewall 192.168.25.3 nos corta el paso

martes, 6 de julio de 2010

Añadir nuevo disco iscsi multipath ocfs2

En cada nodo del cluster

Reescanemos en busca de la nueva lun
iscsiadm -m session --rescan

Recargamos multipath
/etc/init.d/multipathd reload

multipath -v3

Verificamos que vemos los caminos hacia la nueva LUN
multipath -ll

Creemos los enlaces uuid
(como no se como se hace automaticamente en Suse, lo hago a mano)
blkid | grep /dev/dm-

En este caso asumo que es /dev/dm-1 con el UUID 325dab18-903a-4aae-8230-a9662294846e
cd /dev/disk/by-uuid
ln -s ../../dm-1 325dab18-903a-4aae-8230-a9662294846e

verificamos que es correcto y ya lo tenemos listo para añadir como dispositivo en el recurso fs del cluster


En un nodo del cluster

Formateamos el nuevo disco

mkfs.ocfs2 -N 16 /dev/dm-2


En el CRM

Añadimos el recurso clone fs:ocf:heartbeat con sus respectivas constraints de localización, colocación y orden y listos. Nuevo pool de espacio libre.

viernes, 2 de julio de 2010

El comando seq - un buen amigo

Imaginemos que tenemos un directorio con 100 ficheros que se llaman server_log1.log, server_log2.log... hasta server_log100.log y nos interesa comprimir del 1 al 90. Con seq es así de fácil:

miramos que hace seq.
[ferran@myhost ferran]$ seq 1 90

1
2

3
..
90

Entonces si hacemos:
for i in `seq 1 90 ` ; do gzip server_log$i.log ; done

Seria como si a manita hiciéramos 90 veces...
gzip server_log1.log
gzip server_log2.log
gzip server_log3.log
..
gzip server_log90.log