11 sep. 2008

Resolviendo nombres dns de manera independiente del protocolo

Este es un ejemplo del uso de la funcion getaddrinfo , la cual nos permite resolver nombres de host a ip, de forma independiente del protocolo( Ipv4 o IPv6).
No se porq no se muestra los includes.


#define
#define
#define
#define

#define MAXSOCK 20

int main(int argc, char **argv)
{
int error=0;
struct addrinfo hints, *res, *res0;

memset(&hints, 0, sizeof(hints));
hints.ai_socktype= 0;//SOCK_STREAM;

if(argc!=2)
fprintf(stderr,"modo de uso: dns_resolve fqdn\n");
else
{
error = getaddrinfo(argv[1],NULL,&hints,&res0);
if(error)//si es diferente de cero
{
fprintf(stderr,"dns_resolve %s: %s\n",argv[1],gai_strerror(error));
}
else
{
for(res=res0; res ; res=res->ai_next)
{
int error;
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
switch (res->ai_family) {
case AF_INET:
printf("Interfaz IPv4 %d\n", res->ai_family);
break;
case AF_INET6:
printf("Interfaz IPv6 %d\n", res->ai_family);
break;
default:
printf("interfaz desconocida \n");
return 1;
break;
}
error = getnameinfo(res->ai_addr, res->ai_addrlen, hbuf,
sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
if(error)//si es diferente de cero
{
fprintf(stderr,"error dns_resolve: %s\n",gai_strerror(error));
}
printf("addr: %s port: %s\n",hbuf,sbuf);
}
}
}
return 1;
}

8 sep. 2008

Configurando LVS/DR para balanceo de carga

Topologia



Instalacion de paquetes
debian-ldirector
aptitude install ldirectord-2 heartbeat
debian-rs y debian-rs2
aptitude install apache2



Configuracion de red

debian-ldirector
auto eth0
iface eth0 inet static
address 192.168.1.35
netmask 255.255.255.0
gateway 192.168.1.1

auto eth0:0
iface eth0:0 inet static
address 192.168.1.34
netmask 255.255.255.0

debian-rs
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.36
netmask 255.255.255.0
gateway 192.168.1.1

auto lo:0
iface lo:0 inet static
address 192.168.1.34
netmask 255.255.255.255


debian-rs2
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.37
netmask 255.255.255.0
gateway 192.168.1.1

auto lo:0
iface lo:0 inet static
address 192.168.1.34
netmask 255.255.255.255




Modificando parametros del kernel para evitar el problema arp
debian-ldirector
#vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
#sysctl -p
debian-rs y debian-rs2
#vi /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
#sysctl -p

Configuracion de ldirectord
vi /etc/ha.d/ldirectord.cf
checktimeout=10
checkinterval=2
autoreload=no
logfile="/var/log/ldirectorlog.log"
quiescent=yes
# Virtual Server for HTTP
virtual=192.168.1.34:80
fallback=127.0.0.1:80
real=192.168.1.36:80 gate
real=192.168.1.37:80 gate
service=http
request="test.html"
receive="funciona"
scheduler=rr
protocol=tcp
checktype=negotiate