HAproxy+Keepalived高可用负载均衡部署
一、安装haproxy软件
wget
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
二、在/usr/local/haproxy/conf/目录下创建配置文件(haproxy.cfg)
global
maxconn 20480
chroot /usr/local/haproxy
uid 99
gid 99
daemon
quiet
nbproc 1
stats socket /usr/local/haproxy/haproxy.stat mode 666
log 127.0.0.1 local3
pidfile /usr/local/haproxy/haproxy.pid
ulimit-n 65535
defaults
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
三、如何给haproxy添加日志记录
①、如果是CentOS6.0以下版本配置
一、 vi /etc/syslog.conf
local3.* /var/log/haproxy.log
二、vi /etc/sysconfig/syslog
SYSLOGD_OPTIONS="-m 0"
改成
SYSLOGD_OPTIONS="-r -m 0" #enables logging from remote machines
三、重启动
/etc/init.d/syslog restart
②、Centos6.0或centos6.0以上版本
一、配置日志
vi /etc/rsyslog.conf(去掉下面两行前的注释,一定要去掉,否则不记录日志)
$ModLoad imudp.so
$UDPServerRun 514
##添加日志记录
local3.* /var/log/haproxy.log(添加haproxy日志记录文件)
二、重启动服务
/etc/init.d/rsyslog restart
四、启动haproxy,进行检查,并查看日志
/usr/local/haproxy/sbin/haporxy -f /usr/local/haproxy/conf/haproxy.cfg