quarta-feira, 15 de julho de 2009

Balanceamento de Rede no Debian Etch

Objectivo

A maior parte dos sistemas actuais dispõe de 2 ligações Ethernet. Estas podem ser utilizadas em separado ou em paralelo, numa técnica chamada bonding, que possibilita o balanceamento de dados (os dados são transmitidos pelas 2 interfaces) e tolerância a falhas (caso uma ligação falhe, a transmissão é assegurada pela outra).

No nosso servidor, iremos agregar as duas interfaces físicas do sistema eth0 e eth1 para criar uma nova interface de rede bond0 de alta disponibilidade.

Ethernet bonding:
Ethernet bonding, regulado pela norma IEEE 802.3ad com o título link aggregation é um termo da disciplina de redes de computadores que descreve o acoplamento de dois ou mais canais Ethernet em paralelo para produzir um único canal de maior velocidade e/ou aumentar a disponibilidade e redundância desse canal.

Instalação

server~# apt-get install ifenslave

Configuração

Para criar a interface bond0 deverá ser carregado e configurado o módulo bonding do kernel, o que é feito no ficheiro /etc/modprobe.d/arch/i386:

# [...]
alias bond0 bonding
options bonding mode=balance-rr miimon=100 downdelay=200 updelay=200
# [...]

O parâmetro **mode=balance-rr" indica que a interface irá operar em modo balance-rr, em que os dados serão transmitidos alternadamente pelas diversas interfaces físicas.

Em seguida, carregue o módulo em memória:

server:~# modprobe bonding

O passo seguinte é a parametrização da nova interface de rede e remover (ou comentar) qualquer referência às interfaces físicas por ela usadas, o que é feito no ficheiro /etc/network/interfaces:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
# allow-hotplug eth0
# iface eth0 inet dhcp

# Static IP address
# auto eth0
# iface eth0 inet static
# address 192.168.1.100
# netmask 255.255.255.0
# network 192.168.1.0
# broadcast 192.168.1.255
# gateway 192.168.1.1

auto bond0
iface bond0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
up /sbin/ifenslave bond0 eth0 eth1
down /sbin/ifenslave -d bond0 eth0 eth1

Finalmente, reiniciar os serviços de rede:

server:~# /etc/init.d/networking restart

Verificação

O comando ifconfig permite verificar o estado das interfaces de rede:

server~# ifconfig
bond0 Link encap:Ethernet HWaddr 00:30:1B:B0:C3:4A
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::230:1bff:feb0:c34a/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:138463721 errors:0 dropped:0 overruns:0 frame:0
TX packets:148628904 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1388966198 (1.2 GiB) TX bytes:2736663053 (2.5 GiB)

eth0 Link encap:Ethernet HWaddr 00:30:1B:B0:C3:4A
inet6 addr: fe80::230:1bff:feb0:c34a/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:72483854 errors:0 dropped:0 overruns:0 frame:0
TX packets:74314223 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:845394853 (806.2 MiB) TX bytes:3488708425 (3.2 GiB)

eth1 Link encap:Ethernet HWaddr 00:30:1B:B0:C3:4A
inet6 addr: fe80::230:1bff:feb0:c34a/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:65979867 errors:0 dropped:0 overruns:0 frame:0
TX packets:74314681 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:543571345 (518.3 MiB) TX bytes:3542921924 (3.2 GiB)
Interrupt:185 Base address:0xa000

# [...]

A interface bond0 tem atribuído um endereço Internet e as 3 interfaces (bond0, eth0 e eth1) têm o mesmo endereço físico ("HWaddr 00:30:1B:B0:C3:4A"), para que sejam "vistas" pelo resto da rede como sendo apenas uma.