RabbitMQ系列之高可用集羣

爲了實現高可用,我採用LVS+雙節點RabbitMq , 架構圖以下:node

在RabbitMQ以前放了LVS, LVS 採用 rr 輪詢算法 , 目的是將請求平均分配到兩個真實節點,並配置5672端口監控,異常時轉移到另外的節點。web

在 ,作完以後測試發現,用上LVS以後,測試會報錯,服務器端的隊列名稱都是一致的,可是隊列內容卻並非一致,看來須要作同步。正則表達式

Rabbit提供鏡像功能,須要基於rabbitmq策略來實現,政策是用來控制和修改羣集範圍的某個vhost隊列行爲和Exchange行爲 : 算法

set_policy [-p vhostpath] {name} {pattern} {definition} [priority]服務器

eg. 架構

1 rabbitmqctl set_policy ha-allqueue "^" '{"ha-mode":"all"}'

pattern 是匹配隊列名稱的正則表達式 , 進行區分哪些隊列使用哪些策略less

definition 其實就是一些arguments, 支持以下參數:測試

  1. ha-modeOne of allexactly or nodes (the latter currently not supported by web UI).
  2. ha-paramsAbsent if ha-mode is all, a number if ha-mode is exactly, or an array of strings if ha-mode is nodes.
  3. ha-sync-modeOne of manual or automatic. //若是不指定該參數默認爲manual,這個在高可用集羣測試的時候詳細分析 
  4. federation-upstream-setA string; only if the federation plugin is enabled.

ha-mode 的參數:this

ha-mode ha-params Result
all (absent) Queue is mirrored across all nodes in the cluster. When a new node is added to the cluster, the queue will be mirrored to that node.
exactly count Queue is mirrored to count nodes in the cluster. If there are less than count nodes in the cluster, the queue is mirrored to all nodes. If there are more than countnodes in the cluster, and a node containing a mirror goes down, then a new mirror will not be created on another node. (This is to prevent queues migrating across a cluster as it is brought down.)
nodes node names Queue is mirrored to the nodes listed in node names. If any of those node names are not a part of the cluster, this does not constitute an error. If none of the nodes in the list are online at the time when the queue is declared then the queue will be created on the node that the declaring client is connected to.

在管理policy的時候WebUI是很是不錯:spa

Definition加入兩項:

ha-mode:all 

ha-sync-mode:automatic 

到這裏配置已經完成,接下來進行測試。

兩個節點之間就會開始同步消息了。

這時藉助前面的LVS / HA 就能夠使用高可用了 。

相關文章
相關標籤/搜索