HAproxy + Keepalived high-availability server Load balancer deployment
1. Install haproxy Software
Wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.22.tar.gz
Tar zxvf haproxy-1.4.22.tar.gz
Cd haproxy-1.4.22
Make TARGET = linux26 PREFIX =/usr/local/haproxy
Make install PREFIX =/usr/local/haproxy
Cd/usr/local/haproxy
Mkdir conf
Cd conf
2. Create a configuration file (haproxy. cfg) in the/usr/local/haproxy/conf/directory)
Global
Maxconn 20480
Chroot/usr/local/haproxy
Uid 99
Gid 99
Daemon
Quiet
Nbproc 1
Stats socket/usr/local/haproxy. stat mode 666
Log 127.0.0.1 local3
Pidfile/usr/local/haproxy. pid
Ulimit-n 65535
Ults
Log global
Mode http
Maxconn 20480
# Option httplog clf
Option httplog
Option dontlognull
Option httpclose
Option abortonclose
Option redispatch
Retries 3
Monitor-uri/site_status
Contimeout 5000
Clitimeout 50000
Srvtimeout 50000
Frontend WEB-BANMA-cluster
Bind *: 80
Default_backend web_pool
Backend web_pool
Balance source
# Balance leastconn
Cookie SERVERID
Option forwardfor
Option httpchk GET/check.html
Server app1_1 192.168.10.15: 80 cookie app1inst1 check inter 2000 rise 2 fall 5 weight 3
Server app1_2 192.168.10.16: 80 cookie app1inst2 check inter 2000 rise 2 fall 5 weight 6
Stats refresh 5S
Stats uri/status
Stats realm Haproxy \ statistics
Stats auth admin: admin123
Stats admin if TRUE
3. How to add a log record to haproxy
① If CentOS6.0 or earlier is used
I. vi/etc/syslog. conf
Local3. */var/log/haproxy. log
Ii. vi/etc/sysconfig/syslog
SYSLOGD_OPTIONS = "-m 0"
Change
SYSLOGD_OPTIONS = "-r-m 0" # enables logging from remote machines
Iii. Restart
/Etc/init. d/syslog restart
② Centos6.0 or later
1. Configuration log
Vi/etc/rsyslog. conf (remove the comments before the following two rows; otherwise, no logs are recorded)
$ ModLoad imudp. so
$ UDPServerRun 514
# Add Logging
Local3. */var/log/haproxy. log (add the haproxy log record file)
Ii. Restart the service
/Etc/init. d/rsyslog restart
4. Start haproxy and check the logs.
/Usr/local/haproxy/sbin/haporxy-f/usr/local/haproxy/conf/haproxy. cfg
######################################## ######################################## #######
1. Install keepalived in the same way as the Master/Slave machine)
Wget http://rpm5.org/files/popt/popt-1.16.tar.gz
Tar zxvf popt-1.16.tar.gz
Cd popt-1.16
./Configure
Make & make install
Wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
Tar zxvf keepalived-1.2.7.tar.gz
Cd keepalived-1.2.7
./Configure -- prefix =/usr/local/keepalived
Make & make install
Ii. Initialization Script
Cp/usr/local/keepalived/etc/rc. d/init. d/keepalived/etc/init. d/keepalived
Cp/usr/local/keepalived/sbin/keepalived/usr/sbin/
Cp/usr/local/keepalived/etc/sysconfig/
Mkdir-p/etc/keepalived/
Ln-s/usr/local/keepalived/etc/keepalived. conf/etc/keepalived. conf
Chmod + x/etc/init. d/keepalived
3. The host configuration file (vi/etc/keepalived. conf), as long as the backup machine is modified (with comments)
! Configuration File for keepalived
Global_defs {
Router_id LVS_DEVEL
}
Vrrp_script chk_http_port {
Script "/usr/local/keepalived/check_haproxy.sh"
Interval 2
Weight 2
}
Vrrp_instance VI_1 {
State MASTER (slave machine, changed MASTER to BACKUP)
Interface eth0
Virtual_router_id 51
Priority 150 (Backup Machine, changed to 150 to 149)
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Track_script {
Chk_http_port
}
Virtual_ipaddress {
10.1.1.60
}
}
4. Files in haproxy status
Status = $ (ps aux | grep haproxy | grep-v grep | grep-v bash | wc-l)
If ["$ {status}" = "0"]; then
/Etc/init. d/haproxy start
Status2 = $ (ps aux | grep haproxy | grep-v grep | grep-v bash | wc-l)
If ["$ {status2}" = "0"]; then
/Etc/init. d/keepalived stop
Fi
Fi
5. Start keepalived
/Etc/init. d/keepalived start
For details about HAproxy, click here
HAproxy: click here
Recommended reading:
Haproxy + Keepalived build Weblogic high-availability server Load balancer Cluster
Keepalived + HAProxy configure high-availability Load Balancing
Haproxy + Keepalived + Apache configuration notes in CentOS 6.3
Haproxy + KeepAlived WEB Cluster on CentOS 6
Haproxy + Keepalived build high-availability Load Balancing