Haproxy配置MQ集群负载均衡

2024-07-28 20:50

Haproxy配置MQ集群负载均衡

HAProxy代理服务器

HAProxy是一款提供高可用性、负载均衡以及基于TCP(第四层)和HTTP(第七层)应用的代理软件,支持虚拟主机,它是免费、快速并且可靠的一种解决方案。

RabbitMQ集群镜像模式中,HAProxy用于做Tcp,提供节点负载均衡(LB-LoadBalance)与故障发现。

yum install haproxy
find / -name haproxy.cfg

haproxy.cfg

haproxy.cfg配置详解

listen rabbitmq_cluster
	bind 0.0.0.0:5672 #通过5672对M1、M2进行映射
	option tcplog #记录tcp 连接的状态和时间
	mode tcp #四层协议代理,即对TCP协议转发
	option clitcpka #开启TCP的Keep Alive(长连接模式)
	timeout connect 1s #haproxy与mq建立连接的超时时间
	timeout client 10s #客户端与haproxy最大空闲时间。
	timeout server 10s #服务器与haproxy最大空闲时间。
	balance roundrobin #采用轮询转发消息
	#每5秒发送一次心跳包,如连续两次有响应则代表状态良好,
	#如连续三次没有响应,则视为服务故障,该节点将被剔除。
	server node1 192.168.132.137:5672 check inter 5s rise 2 fall 3
	server node2 192.168.132.139:5672 check inter 5s rise 2 fall 3
listen http_front
	#监听端口
	bind 0.0.0.0:1080
	#统计页面自动刷新时间
	stats refresh 30s
	#统计页面url
	stats uri /haproxy?stats
	#统计页面用户名和密码设置
	stats auth admin:admin

启动haproxy

haproxy -f xxx/haproxy.cfg

image.png

image.png

客户端访问rabbitmq集群

private static ConnectionFactory connectionFactory = new ConnectionFactory();
	static {
		connectionFactory.setHost("192.168.132.142");//haproxy ip
		connectionFactory.setPort(5672);//5672是haproxy转发mq请求的端口
		connectionFactory.setUsername("guest");
		connectionFactory.setPassword("guest");
		connectionFactory.setVirtualHost("/");
	}
}
相关新闻
热点
视频
投票
查看结果
Tags

站点地图 在线访客: 今日访问量: 昨日访问量: 总访问量:

© 2025 个人网站 版权所有

备案号:苏ICP备2024108837号

苏公网安备32011302322151号