Wednesday, April 01, 2009

Cluster com VirtualBox e Ubuntu

Primeiramente o cluster será instalado em máquinas virtuais como o VirtualBox.

Instale a distro do Ubuntu 8,04 no Virtual Box

Copie o arquivo .vdi da instalação e depois altere o uuid com o comando abaixo

VBoxManage internalcommands setvdiuuid [nome do arquivo vdi]

onde [nome do arquivo vdi] é o seu disco virtual.

Configurar Ponte no Hospedeiro
Instalar os pacotes
apt-get install bridge-utils uml-utilities

tunctl -t tap1 -u SeUuSuArIo
brctl addbr br0 #(criamos uma bridge)
ifconfig eth0 0.0.0.0 promisc
brctl addif br0 eth0
dhclient br0
OU
ifconfig br0 192.168.0.10 #para ip fixo
brctl addif br0 tap1
ifconfig tap1 up

desfazer:
sudo ifconfig tap1 down
sudo brctl delif br0 tap1
sudo ifconfig br0 down
sudo brctl delbr br0
sudo ifconfig eth0 -promisc
sudo ifconfig eth0 down
sudo ifconfig eth0 [seu ip]/24 up
sudo ifconfig tap1 down
sudo tunctl -d tap1


Apache node 1: webserver1.example.com (webserver1) - IP address: 192.168.0.101; Apache document root: /var/www
Apache node 2: webserver2.example.com (webserver2) - IP address: 192.168.0.102; Apache document root: /var/www
Load Balancer node 1: loadb1.example.com (loadb1) - IP address: 192.168.0.103
Load Balancer node 2: loadb2.example.com (loadb2) - IP address: 192.168.0.104
Virtual IP Address: 192.168.0.105 (used for incoming requests)


No loadbalancer
Entre no terminal e digite
echo ip_vs_dh >> /etc/modules
echo ip_vs_ftp >> /etc/modules
echo ip_vs >> /etc/modules
echo ip_vs_lblc >> /etc/modules
echo ip_vs_lblcr >> /etc/modules
echo ip_vs_lc >> /etc/modules
echo ip_vs_nq >> /etc/modules
echo ip_vs_rr >> /etc/modules
echo ip_vs_sed >> /etc/modules
echo ip_vs_sh >> /etc/modules
echo ip_vs_wlc >> /etc/modules
echo ip_vs_wrr >> /etc/modules

depois digite

modprobe ip_vs_dh
modprobe ip_vs_ftp
modprobe ip_vs
modprobe ip_vs_lblc
modprobe ip_vs_lblcr
modprobe ip_vs_lc
modprobe ip_vs_nq
modprobe ip_vs_rr
modprobe ip_vs_sed
modprobe ip_vs_sh
modprobe ip_vs_wlc
modprobe ip_vs_wrr


vi /etc/apt/sources.list
deb http://www.ultramonkey.org/download/3/ sarge main
deb-src http://www.ultramonkey.org/download/3 sarge main


apt-get update
apt-get install ultramonkey


vi /etc/sysctl.conf
# Enables packet forwarding
net.ipv4.ip_forward = 1

sysctl -p

4 Configure heartbeat And ldirectord
Now we have to create three configuration files for heartbeat. They must be identical on loadb1 and loadb2!
loadb1/loadb2:
vi /etc/ha.d/ha.cf
logfacility local0
bcast eth0 # Linux
mcast eth0 239.0.0.1 694 1 0
auto_failback off
node loadb1
node loadb2
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
Important: As nodenames we must use the output of
uname -n
on loadb1 and loadb2.

Para testar:
“(class D multicast address 224.0.0.0 - 239.255.255.255). For most Heartbeat uses, the first byte should be 239. “

Caso seja necessário você pode trocar o nome da máquina digitando no console
network-admin

se der problema você pode editar o arquivo /etc/hostname

Crie o arquivo

vi /etc/ha.d/haresources
loadb1 \
ldirectord::ldirectord.cf \
LVSSyncDaemonSwap::master \
IPaddr2::192.168.0.105/24/eth0/192.168.0.255


vi /etc/ha.d/authkeys
auth 3
3 md5 somerandomstring
loadb1/loadb2:
chmod 600 /etc/ha.d/authkeys
loadb1/loadb2:
vi /etc/ha.d/ldirectord.cf
checktimeout=10
checkinterval=2
autoreload=no
logfile="local0"
quiescent=yes
virtual=192.168.0.105:80
real=192.168.0.101:80 gate
real=192.168.0.102:80 gate
fallback=127.0.0.1:80 gate
service=http
request="ldirector.html"
receive="Test Page"
scheduler=rr
protocol=tcp
checktype=negotiate


In the virtual= line we put our virtual IP address (192.168.0.105 in this example), and in the real= lines we list the IP addresses of our Apache nodes (192.168.0.101 and 192.168.0.102 in this example). In the request= line we list the name of a file on webserver1 and webserver2 that ldirectord will request repeatedly to see if webserver1 and webserver2 are still alive. That file (that we are going to create later on) must contain the string listed in the receive= line.
Afterwards we create the system startup links for heartbeat and remove those of ldirectord because ldirectord will be started by the heartbeat daemon:
loadb1/loadb2:
update-rc.d heartbeat start 75 2 3 4 5 . stop 05 0 1 6 .
update-rc.d -f ldirectord remove
Finally we start heartbeat (and with it ldirectord):
loadb1/loadb2:
/etc/init.d/ldirectord stop
/etc/init.d/heartbeat start

TESTES
tcpdump -n -i eth0 port 80
colocar a outra interface manualmente
ifconfig eth0:0 192.168.0.105 netmask 255.255.255.248 broadcast 192.168.0.255
ip addr sh eth0
The active load balancer should list the virtual IP address (192.168.0.105):
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:16:3e:40:18:e5 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.103/24 brd 192.168.0.255 scope global eth0
inet 192.168.0.105/24 brd 192.168.0.255 scope global secondary eth0
The hot-standby should show this: (é o outro de backup loadb2)
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:16:3e:50:e3:3a brd ff:ff:ff:ff:ff:ff
inet 192.168.0.104/24 brd 192.168.0.255 scope global eth0


loadb1/loadb2:
ldirectord ldirectord.cf status
Obs.: ldirectord status retorna o valor abaixo
Output on the active load balancer:
ldirectord for /etc/ha.d/ldirectord.cf is running with pid: 1455
Output on the hot-standby:
ldirectord is stopped for /etc/ha.d/ldirectord.cf


ipvsadm -L -n
Output on the active load balancer:
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.0.105:80 rr
-> 192.168.0.101:80 Route 0 0 0
-> 192.168.0.102:80 Route 0 0 0
-> 127.0.0.1:80 Local 1 0 0
Output on the hot-standby:
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn

/etc/ha.d/resource.d/LVSSyncDaemonSwap master status
Output on the active load balancer:
master running
(ipvs_syncmaster pid: 1591)
Output on the hot-standby:
master stopped
If your tests went fine, you can now go on and configure the two Apache nodes.


6 Configuração dos Servidores Apache
Finally we must configure our Apache cluster nodes webserver1.example.com and webserver2.example.com to accept requests on the virtual IP address 192.168.0.105.
webserver1/webserver2:
apt-get install iproute

Add the following to /etc/sysctl.conf:
webserver1/webserver2:
vi /etc/sysctl.conf
# Enable configuration of arp_ignore option
net.ipv4.conf.all.arp_ignore = 1
# When an arp request is received on eth0, only respond if that address is
# configured on eth0. In particular, do not respond if the address is
# configured on lo
net.ipv4.conf.eth0.arp_ignore = 1
# Ditto for eth1, add for all ARPing interfaces
#net.ipv4.conf.eth1.arp_ignore = 1
# Enable configuration of arp_announce option
net.ipv4.conf.all.arp_announce = 2
# When making an ARP request sent through eth0 Always use an address that
# is configured on eth0 as the source address of the ARP request. If this
# is not set, and packets are being sent out eth0 for an address that is on
# lo, and an arp request is required, then the address on lo will be used.
# As the source IP address of arp requests is entered into the ARP cache on
# the destination, it has the effect of announcing this address. This is
# not desirable in this case as adresses on lo on the real-servers should
# be announced only by the linux-director.
net.ipv4.conf.eth0.arp_announce = 2
# Ditto for eth1, add for all ARPing interfaces
#net.ipv4.conf.eth1.arp_announce = 2

Atenção verifique se o eth0 é zero mesmo, pode ser eth1, etc.
Digitar o comando no console:
sysctl -p

Add this section for the virtual IP address to /etc/network/interfaces:
webserver1/webserver2:
vi /etc/network/interfaces
auto lo:0
iface lo:0 inet static
address 192.168.0.105
netmask 255.255.255.255
pre-up sysctl -p > /dev/null

Then run this:
webserver1/webserver2:
ifup lo:0

talvez seja necessário derrubar e reiniciar as interfaces:
ifconfig eth0 down
ifconfig eth0 up

Finally we must create the file ldirector.html. This file is requested by the two load balancer nodes repeatedly so that they can see if the two Apache nodes are still running. I assume that the document root of the main apache web site on webserver1 and webserver2 is /var/www, therefore we create the file /var/www/ldirector.html:
webserver1/webserver2:
vi /var/www/ldirector.html
Test Page




Softwares

VirtualBox 2,0,4
Ubuntu 8,04,1 LTS

2 comments:

Mamãe Oshiro said...

Hã?? Dá pra repetir????

Unknown said...

control - c control - v nervoso