docker+haproxy 配置rabbitmq负载均衡

1>创建haproxy配置文件

vi /docker/HAProxy/conf

2>编辑配置文件

global
maxconn 10000 #默认最大连接数
log 127.0.0.1 local0 #[err warning info debug]
chroot /usr/local/sbin #chroot运行的路径
daemon #以后台形式运行haproxy
pidfile /var/run/haproxy.pid #haproxy的pid存放路径,启动进程的用户必须有权限访问此文件
defaults
log 127.0.0.1 local3
mode http #所处理的类别 (#7层 http;4层tcp )
maxconn 10000 #最大连接数
option dontlognull #不记录健康检查的日志信息
option redispatch #serverId对应的服务器挂掉后,强制定向到其他健康的服务器
#stats refresh 30 #统计页面刷新间隔
retries 3 #3次连接失败就认为服务不可用,也可以通过后面设置
balance roundrobin #默认的负载均衡的方式,轮询方式
#balance source #默认的负载均衡的方式,类似nginx的ip_hash
#balance leastconn #默认的负载均衡的方式,最小连接
timeout connect 5000 #连接超时
timeout client 50000 #客户端超时
timeout server 50000 #服务器超时
timeout check 2000 #心跳检测超时
####################################################################
listen http_front
bind 0.0.0.0:5669 #监听端口
stats refresh 30s #统计页面自动刷新时间
stats uri /haproxy?stats #统计页面url
stats realm Haproxy Manager #统计页面密码框上提示文本
stats auth admin:admin #统计页面用户名和密码设置
#stats hide-version #隐藏统计页面上HAProxy的版本信息
#####################我把RabbitMQ的管理界面也放在HAProxy后面了###############################
listen rabbitmq_admin
bind 0.0.0.0:5671 #通过访问外网IP:5671进入rabbitmq管理界面
server rabbitmq4 外网IP:15675
server rabbitmq3 外网IP:15674
server rabbitmq2 外网IP:15673
server rabbitmq1 外网IP:15672
####################################################################
listen rabbitmq_cluster
bind 0.0.0.0:5670
option tcplog
mode tcp
timeout client 3h
timeout server 3h
option clitcpka
balance roundrobin #负载均衡算法(#banlance roundrobin 轮询,balance source 保存session值,支持static-rr,leastconn,first,uri等参数)
#balance url_param userid
#balance url_param session_id check_post 64
#balance hdr(User-Agent)
#balance hdr(host)
#balance hdr(Host) use_domain_only
#balance rdp-cookie
#balance leastconn
#balance source //ip
server rabbitmq4 外网IP:5675 check inter 5s rise 2 fall 3
server rabbitmq3 外网IP:5674 check inter 5s rise 2 fall 3 #check inter 2000 是检测心跳频率,rise 2是2次正确认为服务器可用,fall 3是3次失败认为服务器不可用
server rabbitmq2 外网IP:5673 check inter 5s rise 2 fall 3
server rabbitmq1 外网IP:5672 check inter 5s rise 2 fall 3

3>创建容器

docker run -d -p 5669-5671:5669-5671 -v /docker/HAProxy/conf/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg --name=haproxy haproxy:latest

4>打开haproxy web管理界面

外围IP :5669/haproxy?stats

猜你喜欢

转载自www.cnblogs.com/caihuaxing/p/11081491.html