雙節點部署rabbitmq集群
阿新 • • 發佈:2019-04-25
emctl lib apr 伸縮 emc start rabbit systemctl 組成 rabbitmq消息隊列簡介
RabbitMQ是實現了高級消息隊列協議(AMQP)的開源消息代理軟件(亦稱面向消息的中間件)
可伸縮性:集群服務
消息持久化:從內存持久化消息到硬盤,再從硬盤加載到內存
安裝rabbitmq
[[email protected] ~]# yum install -y rabbitmq-server
[[email protected] ~]# yum install -y rabbitmq-server
配置監聽地址
[[email protected] ~]# vi /etc/rabbitmq/rabbitmq-env.conf #創建這個文件 RABBITMQ_NODE_IP_ADDRESS=192.168.200.4 RABBITMQ_NODE_PORT=5672 [[email protected] ~]# vi /etc/rabbitmq/rabbitmq-env.conf RABBITMQ_NODE_IP_ADDRESS=192.168.200.5 RABBITMQ_NODE_PORT=5672
啟動服務(只啟動一個節點)
[[email protected] ~]# systemctl start rabbitmq-server
拷貝.erlang.cookie文件到node-2節點
[[email protected] ~]# scp /var/lib/rabbitmq/.erlang.cookie node-2:/var/lib/rabbitmq/ .erlang.cookie 100% 20 0.0KB/s 00:00 [[email protected] ~]# ll /var/lib/rabbitmq/.erlang.cookie -r-------- 1 root root 20 Apr 25 18:39 /var/lib/rabbitmq/.erlang.cookie [[email protected] ~]# chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie [[email protected] ~]# ll /var/lib/rabbitmq/.erlang.cookie -r-------- 1 rabbitmq rabbitmq 20 Apr 25 18:39 /var/lib/rabbitmq/.erlang.cookie
啟動node-2節點的rabbitmq
[[email protected] ~]# systemctl start rabbitmq-server
將node-2與node-1組成集群
[[email protected] ~]# rabbitmqctl stop_app Stopping node ‘[email protected]‘ ... [[email protected] ~]# rabbitmqctl join_cluster [email protected] Clustering node ‘[email protected]‘ with ‘[email protected]‘ ... [[email protected] ~]# rabbitmqctl start_app Starting node ‘[email protected]‘ ...
查看集群狀態
[[email protected] ~]# 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]‘,[]}]}]
#可以看到node-2已經和node-1組成集群
設置鏡像隊列
[[email protected] ~]# rabbitmqctl set_policy ha-all ‘^(?!amq\.).*‘ ‘{"ha-mode": "all"}‘
Setting policy "ha-all" for pattern "^(?!amq\\.).*" to "{\"ha-mode\": \"all\"}" with priority "0" ...
#在哪個節點都可以執行
#將所有隊列設置為鏡像隊列,即隊列會被復制到各個節點,各個節點狀態保持一致。
雙節點部署rabbitmq集群