我两年前有类似的配置。
我决定使用Amazon
VPC,默认情况下,我的设计有两个始终运行的RabbitMQ实例,并在集群中配置(称为主节点)。Rabbitmq集群位于内部亚马逊负载均衡器的后面。
我创建了配置了RabbitMQ和管理插件的AMI(称为“ master-AMI”),然后配置了自动缩放规则。
如果发出自动缩放警报,则会启动新的master-AMI。该AMI在第一次执行时执行跟随脚本:
#!/usr/bin/env pythonimport jsonimport urllib2,base64if __name__ == '__main__': prefix ='' from subprocess import call call(["rabbitmqctl", "stop_app"]) call(["rabbitmqctl", "reset"]) try: _url = 'http://internal-myloadbalamcer-xxx.com:15672/api/nodes' print prefix + 'Get json info from ..' + _url request = urllib2.Request(_url) base64string = base64.enprestring('%s:%s' % ('guest', 'guest')).replace('n', '') request.add_header("Authorization", "Basic %s" % base64string) data = json.load(urllib2.urlopen(request)) ##if the script got an error here you can assume that it's the first machine and then ## exit without controll the error. Remember to add the new machine to the balancer print prefix + 'request ok... finding for running node' for r in data: if r.get('running'): print prefix + 'found running node to bind..' print prefix + 'node name: '+ r.get('name') +'- running:' + str(r.get('running')) from subprocess import call call(["rabbitmqctl", "join_cluster",r.get('name')]) break; pass except Exception, e: print prefix + 'error during add node' finally: from subprocess import call call(["rabbitmqctl", "start_app"]) pass脚本使用HTTP API“ http://internal-myloadbalamcer-
xxx.com:15672/api/nodes ”查找节点,然后选择一个节点并将新的AMI绑定到群集。
作为高可用性策略,我决定使用此方法:
rabbitmqctl set_policy ha-two "^two." ^ "{""ha-mode"":""exactly"",""ha-params"":2,"ha-sync-mode":"automatic"}"好了,联接“非常”简单,问题在于确定何时可以从集群中删除节点。
您无法基于自动缩放规则删除节点,因为您可以将消息发送到必须使用的队列。
我决定执行一个定期运行到两个主节点实例的脚本:
- 通过API http:// node:15672 / api / queues检查消息计数
- 如果所有队列的消息计数均为零,则可以从负载均衡器中删除该实例,然后从Rabbitmq集群中删除该实例。
这大致上就是我所做的,希望对您有所帮助。
[编辑]
我编辑了答案,因为有这个插件可以帮助您:
我建议看一下:https :
//github.com/rabbitmq/rabbitmq-
autocluster
该插件已移至官方RabbitMQ存储库,可以轻松解决此类问题



