为rabbitmq配置HAProxy [英] Configure HAProxy for rabbitmq
问题描述
我想将HAProxy用作负载均衡器。我想把两个rabbitmq服务器放在haproxy后面。 rabbitmq服务器都在EC2的不同实例上。我已按照此参考资料<配置HAProxy服务器一>。我的工作但问题是消息不以roundrobin模式发布。消息仅在一台服务器上发布。我的要求是否有任何不同的配置?
I want to use HAProxy as a load balancer. I want to put two rabbitmq server behind haproxy. Both the rabbitmq server are on different instance of EC2. I have configure HAProxy server by following this reference. I works but the problem is messages are not published in roundrobin pattern. Messages are publish only on one server. Is there any different configuration for my requirement?
我在/etc/haproxy/haproxy.cfg中的配置
My configureation in /etc/haproxy/haproxy.cfg
listen rabbitmq 0.0.0.0:5672
mode tcp
stats enable
balance roundrobin
option tcplog
no option clitcpka
no option srvtcpka
server rabbit01 46.XX.XX.XX:5672 check
server rabbit02 176.XX.XX.XX:5672 check
listen web-service *:80
mode http
balance roundrobin
option httpchk HEAD / HTTP/1.0
option httpclose
option forwardfor
option httpchk OPTIONS /health_check.html
stats enable
stats refresh 10s
stats hide-version
stats scope .
stats uri /lb?stats
stats realm LB2\ Statistics
stats auth admin:Adm1nn
更新:
我对此做了一些R& D,发现HAProxy是循环连接在rabbitmq服务器上。例如:如果我请求10个连接,那么它将在我的2个rabbitmq服务器上循环10个连接并发布消息。
I have made some R&D on this and found that HAProxy is round robin the connection on the rabbitmq server. for ex: if i request for 10 connections then it will round robin the 10 connection over my 2 rabbitmq servers and publish the message.
但问题是我想要循环消息,而不是它应该由HAProxy服务器管理的连接。即如果我一次向HAProxy发送1000 msg,那么500 msg应该转到兔子服务器1,500 msg应该转到兔子服务器2。我必须遵循的配置是什么?
But the problem is I want to round robin the messages, not connection it should be manage by HAProxy server. i.e if i send 1000 msg at a time to HAProxy then 500 msg should go to rabbit server1 and 500 msg should go to rabbit server2. What should be the configuration that i have to follow?
更新:
我还测试了lessconn的平衡,但HAProxy的行为是出乎意料的。我已在 serverfault.com 上发布了该问题/ p>
I have also test with leastconn in balancing but HAProxy behavior in unexpected. I have posted that question on serverfault.com
推荐答案
消息发布到将路由到队列的交易所。
Messages get published to an exchange which will route to a queue.
您可能没有使用{x-ha-policy,all}配置队列。基于交换路由在两个节点上工作的事实,这可能是您所缺少的。
You probably didn't configure you queues with {"x-ha-policy","all"}. Based on the fact that the exchange routing is working on both nodes this is probably all you are missing.
注意:Pre Rabbit 3.0您将使用x-声明队列ha-policy论证,它将被反映出来。使用Rabbit 3.0,您需要应用策略(ha-mode = all)。您可以通过api或api工具(rabbitmqctl,management gui)设置策略。 ie
Note: Pre Rabbit 3.0 you would declare a queue with the x-ha-policy argument and it would be mirrored. With rabbit 3.0 you need to apply a policy (ha-mode = all). You can set policies through the api or the api tools (rabbitmqctl, management gui). i.e.
rabbitmqctl set_policy -p'/'MirrorAllQueues'。+''{ha-mode:all}'
这篇关于为rabbitmq配置HAProxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!