Author : Erika Date : Agustus, 25 2011 Location : Indonesia, Jakarta Selatan OS : FreeBSD 8.2 Title : High Availa...
Date : Agustus, 25 2011
Location : Indonesia, Jakarta Selatan
OS : FreeBSD 8.2
Title : High Availability Load Balancer Webserver dengan FreeBSD + CARP + Haproxy
Sambil nunggu buka puasa dan nunggu thr cair, saya punya utang artikel sama mas ogeb
kita langsung saja teman2.
kita langsung saja teman2.
Disini saya menggunakan:
## 2 Server yang berfungsi sebagai Load Balancer
masing-masing server menggunakan 2 Interface yaitu ethernet1 ( em0: WAN ) dan ethernet2 ( em1: LAN )
Saya kasih nama LB1 dan LB2
## 2 Server yang berfungsi sebagai Load Balancer
masing-masing server menggunakan 2 Interface yaitu ethernet1 ( em0: WAN ) dan ethernet2 ( em1: LAN )
Saya kasih nama LB1 dan LB2
Nama : LB1
IP WAN ( em0 ): 175.103.XX.Y4
IP LAN ( em1 ): 192.168.0.9
Nama : LB2
IP WAN ( em0 ): 175.103.XX.Y5
IP LAN ( em1 ): 192.168.0.10
IP WAN ( em0 ): 175.103.XX.Y4
IP LAN ( em1 ): 192.168.0.9
Nama : LB2
IP WAN ( em0 ): 175.103.XX.Y5
IP LAN ( em1 ): 192.168.0.10
## 4 Server yang berfungsi sebagai webserver ( 2 aktif dan 2 backup )
masing-masing server menggunakan 1 Interface ethernet ( LAN )
masing-masing server menggunakan 1 Interface ethernet ( LAN )
Nama : krn1
IP LAN : 192.168.0.1 status Haproxy: aktif
Nama : krn2
IP LAN : 192.168.0.2 status Haproxy: aktif
Nama : krn3
IP LAN : 192.168.0.3 status Haproxy: backup
Nama : krn4
IP LAN : 192.168.0.4 status Haproxy: backup
IP LAN : 192.168.0.1 status Haproxy: aktif
Nama : krn2
IP LAN : 192.168.0.2 status Haproxy: aktif
Nama : krn3
IP LAN : 192.168.0.3 status Haproxy: backup
Nama : krn4
IP LAN : 192.168.0.4 status Haproxy: backup
## IP Virtual ( CARP )
3 IP Virtual masing2 ( 175.103.XX.Y1 , 175.103.XX.Y2 , 175.103.XX.Y3 )
####################server LB1 dan LB2 ###########################
##Installasi haproxy
$cd /usr/ports/net/haproxy
$sudo make install
$cd /usr/local/etc
$sudo pico haproxy.conf <--- config lihat di bawah artikel ini
$sudo make install
$cd /usr/local/etc
$sudo pico haproxy.conf <--- config lihat di bawah artikel ini
##Compile kernel
##disini saya menggunakan FreeBSD 8.2 64bit
##disini saya menggunakan FreeBSD 8.2 64bit
cd /usr/src/sys/amd64/conf
echo "device carp" >> GENERIC
config GENERIC
cd ../compile/GENERIC
make depend
make
make install
make clean
sudo pico /etc/rc.conf <----- config bisa di lihat di bawah
echo "device carp" >> GENERIC
config GENERIC
cd ../compile/GENERIC
make depend
make
make install
make clean
sudo pico /etc/rc.conf <----- config bisa di lihat di bawah
sudo pico /etc/sysctl.conf <--- config bisa di lihat di bawah
sudo shutdown -r now
sudo shutdown -r now
#################### start config CARF pada LB1 /etc/rc.conf#########
defaultrouter="175.103.XX.1"
hostname="LB1.devbsd.org"
cloned_interfaces="carp0"
ifconfig_em0="inet 175.103.XX.Y4 netmask 255.255.255.0"
ifconfig_carp0="inet 175.103.XX.Y1 vhid 1 pass m4ling advskew 0"
ifconfig_carp0_alias0="175.103.XX.Y2 vhid 1 pass m4ling advskew 0"
ifconfig_carp0_alias1="175.103.XX.Y3 vhid 1 pass m4ling advskew 0"
ifconfig_em1="inet 192.168.0.9 netmask 255.255.255.0"
haproxy_enable="YES"
haproxy_config="/usr/local/etc/haproxy.conf"
hostname="LB1.devbsd.org"
cloned_interfaces="carp0"
ifconfig_em0="inet 175.103.XX.Y4 netmask 255.255.255.0"
ifconfig_carp0="inet 175.103.XX.Y1 vhid 1 pass m4ling advskew 0"
ifconfig_carp0_alias0="175.103.XX.Y2 vhid 1 pass m4ling advskew 0"
ifconfig_carp0_alias1="175.103.XX.Y3 vhid 1 pass m4ling advskew 0"
ifconfig_em1="inet 192.168.0.9 netmask 255.255.255.0"
haproxy_enable="YES"
haproxy_config="/usr/local/etc/haproxy.conf"
############################ end config CARP pada LB1#############
################## start config CARF pada LB2 /etc/rc.conf ##############
defaultrouter="175.103.XX.1"
hostname="LB2.devbsd.org"
cloned_interfaces="carp0"
ifconfig_em0="inet 175.103.XX.Y5 netmask 255.255.255.0"
ifconfig_carp0="inet 175.103.XX.Y1 vhid 1 pass m4ling advskew 100"
ifconfig_carp0_alias0="175.103.XX.Y2 vhid 1 pass m4ling advskew 100"
ifconfig_carp0_alias1="175.103.XX.Y3 vhid 1 pass m4ling advskew 100"
ifconfig_em1="inet 192.168.0.10 netmask 255.255.255.0"
haproxy_enable="YES"
haproxy_config="/usr/local/etc/haproxy.conf"
defaultrouter="175.103.XX.1"
hostname="LB2.devbsd.org"
cloned_interfaces="carp0"
ifconfig_em0="inet 175.103.XX.Y5 netmask 255.255.255.0"
ifconfig_carp0="inet 175.103.XX.Y1 vhid 1 pass m4ling advskew 100"
ifconfig_carp0_alias0="175.103.XX.Y2 vhid 1 pass m4ling advskew 100"
ifconfig_carp0_alias1="175.103.XX.Y3 vhid 1 pass m4ling advskew 100"
ifconfig_em1="inet 192.168.0.10 netmask 255.255.255.0"
haproxy_enable="YES"
haproxy_config="/usr/local/etc/haproxy.conf"
##############end config CARP pada LB2 ###########################
################start config haproxy LB1 dan LB2 ####################
global
log 127.0.0.1 local0
log 127.0.0.1 syslog debug
maxconn 8192
user www
group www
daemon
nbproc 4
global
log 127.0.0.1 local0
log 127.0.0.1 syslog debug
maxconn 8192
user www
group www
daemon
nbproc 4
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
stats enable
stats scope .
stats uri /haproxy?stats
stats auth admin:pasW0rd
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
stats enable
stats scope .
stats uri /haproxy?stats
stats auth admin:pasW0rd
listen WebFarm 0.0.0.0:80
mode http
balance roundrobin
cookie SERVERID insert indirect
option forwardfor
option httpchk HEAD /check.txt HTTP/1.0
mode http
balance roundrobin
cookie SERVERID insert indirect
option forwardfor
option httpchk HEAD /check.txt HTTP/1.0
server krn1 192.168.0.206 cookie krn1 check inter 2000 rise 2 fall 5
server krn2 192.168.0.207 cookie krn2 check inter 2000 rise 2 fall 5
server krn3 192.168.0.212 cookie krn7 check inter 2000 backup
server krn4 192.168.0.213 cookie krn8 check inter 2000 backup
#####################end of config haproxy LB1 dan LB2######################
server krn2 192.168.0.207 cookie krn2 check inter 2000 rise 2 fall 5
server krn3 192.168.0.212 cookie krn7 check inter 2000 backup
server krn4 192.168.0.213 cookie krn8 check inter 2000 backup
#####################end of config haproxy LB1 dan LB2######################
##################################/etc/sysctl.conf####################
net.inet.carp.allow=1
net.inet.carp.preempt=1
net.inet.carp.log=1
################################################################
Shoutz:net.inet.carp.preempt=1
net.inet.carp.log=1
################################################################
~~~~~~~
~ bagan, dono, apay, ping2, hky89, yopi, fuyumi, mrlemonade, ogeb, 1stlink@dalnet
Contact:
~~~~~~~~
~~~~~~~~
erika || MCS|staff || erika[at]devbsd[dot]org
COMMENTS