swoft之路

rabbitmq实现高可用负载均衡

2018-07-17  本文已影响0人  骑着大象去上班

本次搭建是在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可以看到负载均衡配置成功

image.png
上一篇下一篇

猜你喜欢

热点阅读