1. 程式人生 > >Rabbitmq 相關介紹之雙機鏡像模式集群配置

Rabbitmq 相關介紹之雙機鏡像模式集群配置

rabbitmq雙機多機 鏡像隊列集群配置

一、環境介紹

系統: Centos 6.7  2.6.32-573.el6.x86_64
node1  172.16.60.187
node2  172.16.60.188
軟件包 erlang-19.0.4-1.el6.x86_64.rpm   rabbitmq-server-3.6.12-1.el6.noarch.rpm
直接使用rpm包安裝!

二、開始配置普通集群

1、設置hosts,是rabbitmq節點可以順利的互通
在兩臺服務器上配置/etc/hosts,如下:
#cat /etc/hosts
172.16.60.187 node1
172.16.60.188 node2
2、啟動2臺rabbitmq
#service rabbitmq-server start
3、設置不同節點間同一認證的Erlang Cookie 
采用從主節點copy的方式保持Cookie的一致性,這裏將node1節點的cookie拷貝到node2
#scp /var/lib/rabbitmq/.erlang.cookie [email protected]:/var/lib/rabbitmq/
.erlang.cookie
4、查看Cookie情況
[[email protected] ~]# cat /var/lib/rabbitmq/.erlang.cookie 
CLAPXRVVRHOJYFPTZVTB
[[email protected] ~]# cat /var/lib/rabbitmq/.erlang.cookie
CLAPXRVVRHOJYFPTZVTB
5、沒有創建普通集群之前,查看集群狀態
[[email protected] ~]# rabbitmqctl cluster_status
Cluster status of node [email protected]
[{nodes,[{disc,[[email protected]]}]},
 {running_nodes,[[email protected]]},
 {cluster_name,<<"[email protected]">>},
 {partitions,[]},
 {alarms,[{[email protected],[]}]}]
################################################################ 
[[email protected] ~]# rabbitmqctl cluster_status
Cluster status of node [email protected]
[{nodes,[{disc,[[email protected]]}]},
 {running_nodes,[[email protected]]},
 {cluster_name,<<"[email protected]">>},
 {partitions,[]},
 {alarms,[{[email protected],[]}]}]
6、創建並部署集群,以node2為例
[[email protected] rabbitmq]# rabbitmqctl stop_app
Stopping rabbit application on node [email protected]
[[email protected] rabbitmq]# rabbitmqctl join_cluster  [email protected]
Clustering node [email protected] with [email protected]
[[email protected]2 rabbitmq]# rabbitmqctl start_app
Starting node [email protected]
註:根據官方文檔,如果有node3,繼續加入集群那麽就在node3操作,停止app--添加--啟動app
#rabbitmqctl join_cluster  [email protected]
7、查看集群狀態
#rabbitmqctl cluster_status
Cluster status of node [email protected]
[{nodes,[{disc,[[email protected],[email protected]]}]},
 {running_nodes,[[email protected],[email protected]]},
 {cluster_name,<<"[email protected]">>},
 {partitions,[]},
 {alarms,[{[email protected],[]},{[email protected],[]}]}]
 到這裏2臺服務器構成的普通集群就配置好了。
 8、啟動管理界面
[[email protected] ~]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  amqp_client
  cowlib
  cowboy
  rabbitmq_web_dispatch
  rabbitmq_management_agent
  rabbitmq_management

Applying plugin configuration to [email protected] started 6 plugins.
#########################################################################
[[email protected] rabbitmq]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  amqp_client
  cowlib
  cowboy
  rabbitmq_web_dispatch
  rabbitmq_management_agent
  rabbitmq_management

Applying plugin configuration to [email protected] started 6 plugins.
9、配置用戶名和密碼
[[email protected] ~]# rabbitmqctl add_user admin admin123
Creating user "admin"
[[email protected] ~]# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator]
[[email protected] ~]# rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/"

在瀏覽器訪問,並查看建狀態如下:

技術分享一個集群需要至少有一個disc節點,一個RAM節點,那麽我們將node2修改為RAM節點。

在node2節點上操作如下:
[[email protected] ~]# rabbitmqctl stop_app
Stopping rabbit application on node [email protected]
[[email protected] ~]# rabbitmqctl change_cluster_node_type ram
Turning [email protected] into a ram node
[[email protected] ~]# rabbitmqctl start_app
Starting node [email protected]
查看是否修改成功
[[email protected] ~]# rabbitmqctl cluster_status
Cluster status of node [email protected] 
[{nodes,[{disc,[[email protected]]},{ram,[[email protected]]}]},   #修改成功
 {running_nodes,[[email protected],[email protected]]},
 {cluster_name,<<"[email protected]">>},
 {partitions,[]},
 {alarms,[{[email protected],[]},{[email protected],[]}]}]
########################################################
[[email protected] ~]# rabbitmqctl cluster_status
Cluster status of node [email protected]
[{nodes,[{disc,[[email protected]]},{ram,[[email protected]]}]},   #修改成功
 {running_nodes,[[email protected],[email protected]]},
 {cluster_name,<<"[email protected]">>},
 {partitions,[]},
 {alarms,[{[email protected],[]},{[email protected],[]}]}]
同事通過rabbitmq-magagement界面看到的也是一個Disc一個Ram。

三、配置鏡像隊列集群

[[email protected] ~]# rabbitmqctl set_policy mirror_queue1 "^" ‘{"ha-mode":"all","ha-sync-mode":"automatic","ha-promote-on-shutdown":"always"}‘
Setting policy "mirror_queue1" for pattern "^" to "{\"ha-mode\":\"all\",\"ha-sync-mode\":\"automatic\",\"ha-promote-on-shutdown\":\"always\"}" with priority "0"
查看
[[email protected] ~]# rabbitmqctl list_policies
Listing policies
/       mirror_queue1   all     ^       {"ha-mode":"all","ha-sync-mode":"automatic","ha-promote-on-shutdown":"always"}  0
#######################
[[email protected] ~]# rabbitmqctl list_policies
Listing policies
/       mirror_queue1   all     ^       {"ha-mode":"all","ha-sync-mode":"automatic","ha-promote-on-shutdown":"always"}  0

同樣的,添加好鏡像隊列之後,也可以在rabbitmq-management界面看到。


本文出自 “知識體系” 博客,請務必保留此出處http://linuxg.blog.51cto.com/4410110/1967788

Rabbitmq 相關介紹之雙機鏡像模式集群配置