haproxy 安装部署

前言

本篇主要介绍haproxy安装部署,以及通过rabbitmq集群高可用案例,简单的介绍了haproxy的配置,启动及关闭等基本操作。

安装过程

下载haproxy-1.5.8.tar.gz
cd /usr/local/
wget http://www.haproxy.org/download/1.5/src/haproxy-1.5.8.tar.gz

tar -zxvf haproxy-1.5.8.tar.gz
cd haproxy-1.5.8/
uname –a //查看linux内核版本及位数
#linux2.6以上的版本,TARGET=linux26,ARCH操作系统位数,PREFIX安装目录。
make TARGET=linux26 ARCH=x86_64 PREFIX=/usr/local/haproxy/
make install PREFIX=/usr/local/haproxy/

cd /usr/local/haproxy/
mkdir conf log
cp haproxy-1.5.8/examples/haproxy.cfg haproxy/conf/

#清除无用源文件
rm -rf haproxy-1.5.8/

rabbitmq集群配置(TCP四层代理)

#修改/usr/local/haproxy/conf/haproxy.cfg配置文件
global
daemon
maxconn 128
nbproc 1
uid 500
gid 500
chroot /usr/local/haproxy
pidfile /usr/local/haproxy/log/haproxy.pid
log 127.0.0.1 local3 err
defaults
mode http
maxconn 128
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms

retries 3
balance roundrobin
option httplog
option httpclose
option abortonclose
option redispatch
log 127.0.0.1 local3 err

#rabbitmq集群监控界面
listen rabbitmq-monitor
bind 0.0.0.0:15672
mode http
balance source
option httpchk GET /
server rabbitmq-node1 10.116.84.117:15673 cookie rabbitmq-node1 check inter 3000 rise 3 fall 3 weight 1
server rabbitmq-node2 10.116.84.117:15674 cookie rabbitmq-node2 check inter 3000 rise 3 fall 3 weight 1

#rabbitmq集群访问入口
listen rabbitmq-cluster
bind 0.0.0.0:5672
mode tcp
balance roundrobin
option tcplog
option tcpka
server rabbitmq-node1 10.116.84.117:5673 check inter 3000 rise 3 fall 3 weight 1
# rabbitmq-node2作为备份节点,当rabbitmq-node1宕机之后,rabbitmq-node2开始对外提供服务
server rabbitmq-node2 10.116.84.117:5674 check inter 3000 rise 3 fall 3 weight 1 backup

#haproxy监控界面
listen web-stats
bind 0.0.0.0:1080
#log global
stats refresh 30s
stats uri /web-stats
stats realm HaproxyMonitor
stats auth root:123456
stats hide-version
#stats admin if TRUE

启动/关闭

#启动
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
#关闭
pkill haproxy 或 killall haproxy

image

参考链接

  1. http://www.haproxy.org
  2. http://cbonte.github.io/haproxy-dconv/1.7/intro.html
  3. http://cbonte.github.io/haproxy-dconv/1.7/management.html