วันอาทิตย์ที่ 15 พฤษภาคม พ.ศ. 2554

Nginx Web Cluster (ตอนที่ 2)

ต่อจากตอนแรก ยังคงมีปัญหาค้างอยู่คือ เครื่องที่ทำหน้าที่ Load Balance นั้น มีแค่เครื่องเดียว ซึ่งเป็น Single point of failure อยู่
จำเป็นที่จะต้องทำให้ Load Balance นี้ มีตัวตายตัวแทน

วิธีแก้ปัญหา -> ใช้ Common Address Redundancy Protocol (CARP)

1. ที่เครื่อง Load Balance ทั้ง 2 เครื่อง ต้อง compile Kernel FreeBSD ใหม่

โดยเพิ่ม device carp เข้าไป

# cd /usr/src/sys/amd64/conf
# cp GENERIC GENERIC.carp

เพิ่ม device carp เข้าไป แล้วเซฟ

# config GENERIC.carp
# cd ../compile/GENERIC.carp
# make depend
# make
# make install

restart เครื่อง 1 รอบ

ทำอย่างนี้ที่ เครื่อง Loadbalance1 และ Loadbalance2

cloned_interfaces="carpXX"
ifconfig_carpXX="vhid advskew pass "

ตัวอย่างเครื่องที่ 1
/etc/rc.conf

ifconfig_bge1="inet 192.168.10.2 netmask 255.255.255.0"

cloned_interfaces="carp1"
ifconfig_carp1="vhid 10 advskew 50 pass password 192.168.10.1"

ตัวอย่างเครื่องที่ 2
/etc/rc.conf

ifconfig_bge1="inet 192.168.10.3 netmask 255.255.255.0"

cloned_interfaces="carp1"
ifconfig_carp1="vhid 10 advskew 80 pass password 192.168.10.1"


ขั้นตอนสุดท้าย แก้ไขไฟล์ /etc/sysctl.conf โดยเพิ่มบรรทัดต่อไปนี้เข้าไป

net.inet.carp.preempt=1


Restart แล้ว ทดลอง ดู ifconfig ที่เครื่องแรกดู จะเป็น interface carp up และมี IP เป็น 192.168.10.1


อ้างอิง

cloned_interfaces="carpXX"

Add an ifconfig variable for each CARP interface that was created.

ifconfig_carpXX="vhid advskew pass "

The is an identifier that groups the CARP interface with it's counterpart interface on the other hosts. The common IP address is shared with all interfaces that have the same . The may be anything but must match on all the hosts.
The should be different on each host. The value on the master host should be less than the backup hosts.
is a string used to validate the CARP exchanges between the hosts. This can be any string you want but must be the same on all hosts that share a common .
The is the virtual IP address that the CARP interface will have. This IP address must be in the network block assigned to one of the physical interfaces. CARP uses this IP address to figure out what physical interface to assign the CARP interface too.

ไม่มีความคิดเห็น:

แสดงความคิดเห็น