我想默认为所有队列定义镜像。节点启动后,我目前必须使用rabbitmqctl
:
rabbitmqctl set_policy ha-all "" '{"ha-mode":"all"}'
如果我的一个节点发生故障,则必须记住在重新启动时重新执行该代码。
有没有一种方法可以自动将节点配置为使用镜像队列?
最佳答案
可以在定义文件中指定策略,该文件可以从您的配置文件中引用。
我如何设置特定策略的示例(不确定是否可以在策略中指定ha):
/etc/rabbitmq/rabbitmq.config
[
{rabbit,
[{vm_memory_high_watermark, 0.8}]
},
{rabbitmq_management,
[{listener, [{port, 15672}]},
{load_definitions, "/etc/rabbitmq/rabbitmq_definitions.json"},
{http_log_dir, "/var/log/rabbitmq/management_http.log"}]
}
].
/etc/rabbitmq/rabbitmq_definitions.json
{ "users":[
{"name":"rabbot","password_hash":"Cvse5iGOg20UqUq7Za9D1tatOJnMVDru4GHtxqc02g7zj5ur","tags":""},
{"name":"rabnet","password_hash":"CqqG2fwvH6xz64NpibGJx2M7ZCyFnR1BQBM+C0KH2qRPmVxF","tags":"administrator"}],
"vhosts":[
{"name":"/"}],
"permissions":[
{"user":"viabot","vhost":"VIA","configure":".*","write":".*","read":".*"},
{"user":"vianet","vhost":"VIA","configure":".*","write":".*","read":".*"}],
"parameters":[],
"policies":[
{"vhost":"VIA","name":"DLX","pattern":".*","apply-to":"queues","definition":{"dead-letter-exchange":"dead_letter"},"priority":0}
],
"queues":[
{"name":"store_to_es","vhost":"VIA","durable":true,"auto_delete":false,"arguments":{}},
{"name":"store_to_mongodb","vhost":"VIA","durable":true,"auto_delete":false,"arguments":{}}
],
"exchanges":[
{"name":"data_incoming","vhost":"VIA","type":"fanout","durable":true,"auto_delete":false,"internal":false,"arguments":{}},
{"name":"sms_incoming","vhost":"VIA","type":"fanout","durable":true,"auto_delete":false,"internal":false,"arguments":{}}
],
"bindings":[
{"source":"data_incoming","vhost":"VIA","destination":"store_to_es","destination_type":"queue","routing_key":"","arguments":{}},
{"source":"sms_incoming","vhost":"VIA","destination":"store_to_mongodb","destination_type":"queue","routing_key":"","arguments":{}}
]
}
我正在共享此配置文件和定义文件,因为无法从RabbitMQ网站上找到它。
注意:此配置适用于在Ubuntu 14.04上运行的RabbitMQ 3.6.1
关于rabbitmq - 在配置文件中定义Rabbitmq策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31662727/