Linux LVS - Load Balancing - 4 nodes

Linux LVS - Load Balancing - 4 nodes

Như đã nói, hôm nay tiếp đến 4 nodes. Vậy có gì khác.
Ta sử dụng 2 nodes là server1 và server2, heartbeat lắng nghe, xem master còn live ko, nếu ko bật salve lên.
2 nodes trong là 2 web, chạy web. Server active lắng nghe ở ngoài sẽ route vào trong, load balancer ở bước này.

Ta có topo.
Phần cấu hình khá giống vs 2 nodes. Lưu ý các tham số trong file cấu hình heartbeat và cấu hình arptable_jf ở 2 web.
Step 1: Trên cả 4 nodes, bạn có thể setup 1 node làm ntp server, rồi trỏ cho các node khác đến, sẽ tốt hơn.

yum install -y ntp*
ntpdate time.nist.gov

Step 2: Trên server1, làm bước này để ta scp qua các nodes khác ko cần pass. Tuy nhiên bạn cũng có thể đặt pass, mình thì ko đặt để copy tiện hơn.

ssh-keygen -t rsa
cd .ssh/
cat *.pub > authorized_keys
cd ..
scp -r .ssh/ 192.168.1.20:/root
scp -r .ssh/ 192.168.1.41:/root
scp -r .ssh/ 192.168.1.42:/root

Step 3:

vim /etc/hosts
192.168.1.10 server1.hbn.local server1
192.168.1.20 server2.hbn.local server2
192.168.1.41 web1.hbn.local web1
192.168.1.42 web2.hbn.local web2
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

Scp qua các máy còn lại, đồg bộ file host

scp /etc/hosts 192.168.1.20:/etc/
scp /etc/hosts 192.168.1.41:/etc/
scp /etc/hosts 192.168.1.42:/etc/

Step 4: Trên 2 máy web
yum install -y httpd
services httpd start

Step 5: Trên server1

vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.eth0.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

Rồi copy qua

scp /etc/sysctl.conf server2:/etc/
scp /etc/sysctl.conf web1:/etc/
scp /etc/sysctl.conf web2:/etc/

Step 6: Trên 2 máy web

yum install -y arptables_jf

arptables -A IN -d 192.168.1.100 -j DROP
arptables -A OUT -d 192.168.1.100 -j mangle --mangle-ip-s 192.168.1.10
arptables -A OUT -d 192.168.1.100 -j mangle --mangle-ip-s 192.168.1.20

Tiếp:

service arptables_jf save
chkconfig arptables_jf on
/etc/init.d/arptables_jf start

Step 7: Trên server1

vim /etc/sysconfig/network-scripts/ifcfg-lo
DEVICE=lo
IPADDR=127.0.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback

DEVICE=lo:0
IPADDR=192.168.1.100
NETMASK=255.255.255.255
NETWORK=192.168.1.0
BROADCAST=192.168.1.255
ONBOOT=yes
NAME=loopback

Copy qua:

scp /etc/sysconfig/network-scripts/ifcfg-lo server2:/etc/sysconfig/network-scripts/
scp /etc/sysconfig/network-scripts/ifcfg-lo web1:/etc/sysconfig/network-scripts/
scp /etc/sysconfig/network-scripts/ifcfg-lo web2:/etc/sysconfig/network-scripts/

Apply cả 4 nodes:

service network restart

Step 8: Trên 2 nodes lắng nghe ( server1 và 2)

yum install -y heartbeat*

Config:

[/etc/ha.d/authkeys]
auth 2
2 sha1 Ultramonkey!

File này để tạo keys giữa 2 nodes

[/etc/ha.d/ha.cf]
logfacility local0
mcast eth0 225.0.0.1 694 1 0
auto_failback off
node server1.hbn.local
node server2.hbn.local
ping 192.168.1.255
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster

Cấu hình các node, lưu ý tham số node là 2 server lắng nghe ( heartbeat)

[/etc/ha.d/haresources]
server1.hbn.local \
ldirectord::ldirectord.cf \
LVSSyncDaemonSwap::master \
IPaddr2::192.168.1.100/24/eth0/192.168.1.255

Cấu hình server master + virtual IP, là IP ảo sẽ lắng nghe, ở đây master là server1, lắng nghe trên 192.168.1.100

[/etc/ha.d./ldirector.cf]
checktimeout=10
checkinterval=2
autoreload=yes
logfile="/var/log/ldirectord.log"
quiescent=no
# Virtual Service for HTTP
virtual=192.168.1.100:80
fallback=127.0.0.1:80
real=192.168.1.41:80 gate
real=192.168.1.42:80 gate
service=http
request="alive.html"
receive="I'm alive!"
scheduler=wrr
persistent=1800
protocol=tcp
checktype=negotiate
# Virtual Service for HTTPS
virtual=192.168.1.100:443
fallback=127.0.0.1:443
real=192.168.1.41:443 gate
real=192.168.1.42:443 gate
service=https
request="alive.html"
receive="I'm alive!"
scheduler=wrr
persistent=1800
protocol=tcp
checktype=negotiate

Cấu hình phân tải, load balancing về 2 real servers ( web server), ở đây là web1 và web2, do đó chú ý tham số real+virtual ( virtual là virtual IP lắng nghe như ở trên). Chú ý tham số request là file tạo ở doc root để kiểm tra, có nội dung là receive, ở đây là file alive.html vs nội dung là I'm alive!

chmod 600 /etc/ha.d/authkeys
scp -r /etc/ha.d/ server2:/etc/

Chmod + copy qua server2
Step 9: Tại 2 web, lưu ý là web1 là Web1.hbn.local, web2 là Web2.hbn.local, để test thôi.

cd /var/www/html/
vim index.htm
web1.hbn.local

Tạo file alive.html vs nội dung I'm alive!

vim alive.html
I'm alive!

Step 10:
Tại 2 nodes, star HeartBeat, xem log ở /var/log/message

/etc/init.d/heartbear start

chkconfig heartbeat on
chkconfig httpd on

Xem load balacing: ipvsadm
Xong phần 4 nodes, chuẩn bị cho 6 nodes, thêm 2 nodes đồng bộ file + sql mater-slave:
Video demo: http://www.mediafire.com/?akwjpgyfb4aa04z
Tut text: http://www.mediafire.com/?nau09qicnswk54d

------------------------------------------------------------
Thanks for reading
--------------------------------------------------------------------------
All my Lab:
Linux Lab -- window and Cisco Lab
to be continued - I will update more.

Nam Habach