本次搭建是在https://www.jianshu.com/p/de5218ad713ehttps://www.jianshu.com/p/c7c178e29af9基础上搭建的下面只是修改的地方。
1、修改haproxy配置文件
vim /usr/local/haproxy/haproxy.cfg
在最后加上

bind  192.168.1.180:5673 ##客户端就是通过这个ip和端口进行连接,这个vip和端口绑定的是rabbitmq5672端口
mode tcp
option tcplog
option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www
balance roundrobin
server rabbitmq_testlinux 192.168.1.111:5672 check port 48710 inter 5s rise 2 fall 3
server rabbitmq_linux 192.168.1.197:5672 check port 48710 inter 5s rise 2 fall 3
server rabbitmq_test 192.168.1.160:5672 check port 48710 inter 5s rise 2 fall 3
timeout server 20000

2、增加一个haproxy检测rabbitmq服务
vim /etc/xinetd.d/rabbitmq_status

service rabbitmq_status
{
flags = REUSE
socket_type = stream
port = 48710
wait = no
user = nobody
server =/usr/local/bin/rabbitmq_status
log_on_failure += USERID
disable = no

vim /usr/local/bin/rabbitmq_status

#!/bin/bash
rabbitmq=`systemctl status rabbitmq-server.service |grep 'active (running)'| wc -l`
if [ "$rabbitmq" = "1" ];
then
/bin/echo -e "HTTP/1.1 200 OK\r\n"
else
/bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"

vim /etc/services
在最后加上

rabbitmq_status 48710/tcp               # rabbit_status

重启xinetd

systemctl restart xinetd.service

打开http://192.168.1.180:48800/admin_stats可以看到负载均衡配置成功

rabbitmq实现高可用负载均衡
image.png

相关文章:

  • 2021-05-22
  • 2021-07-18
  • 2021-04-09
  • 2021-05-19
  • 2021-09-17
  • 2022-01-25
  • 2021-05-25
猜你喜欢
  • 2021-05-01
  • 2021-12-20
  • 2021-09-04
  • 2021-06-11
  • 2021-11-12
相关资源
相似解决方案