RabbitMQ集群安装
首先参考上一篇文章【CentsOS原生RabbitMQ安装过程】在两到三台机器上先安装单独的RabbitMQ节点
修改一下hostname
1 2 3 4 |
[[email protected] ~]# vim /etc/hosts 172.16.20.110 rnode1 172.16.20.111 rnode2 172.16.20.112 rnode3 |
erlang节点之间通信需要相同的cookie文件,将其中一个机器上的cookie文件copy到另外两个机器
1 2 |
scp /var/lib/rabbitmq/.erlang.cookie rnode2:/var/lib/rabbitmq scp /var/lib/rabbitmq/.erlang.cookie rnode3:/var/lib/rabbitmq |
首先在rnode1上观察一下节点状态如下
1 2 3 4 5 6 7 |
[[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],[]}]}] |
分别在rnode2、rnode3上执行以下命令使其与rnode1组成集群
1 2 3 4 5 6 |
[[email protected] ~]# rabbitmqctl stop_app Stopping rabbit application on node [email protected] [[email protected] ~]# rabbitmqctl join_cluster --ram [email protected] Clustering node [email protected] with [email protected] [[email protected] ~]# rabbitmqctl start_app Starting node [email protected] |
随便选择一台集群观察节点状态发现集群已经搭建完毕
1 2 3 4 5 6 7 |
[[email protected] ~]# rabbitmqctl cluster_status Cluster status of node [email protected] [{nodes,[{disc,[[email protected]]},{ram,[[email protected],[email protected]]}]}, {running_nodes,[[email protected],[email protected],[email protected]]}, {cluster_name,<<"[email protected]">>}, {partitions,[]}, {alarms,[{[email protected],[]},{[email protected],[]},{[email protected],[]}]}] |
安装过程中可能会出现如下问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[[email protected] ~]# rabbitmqctl status Status of node [email protected] Error: unable to connect to node [email protected]: nodedown DIAGNOSTICS =========== attempted to contact: [[email protected]] [email protected]: * connected to epmd (port 4369) on rnode1 * epmd reports: node 'rabbit' not running at all no other nodes on rnode1 * suggestion: start the node current node details: - node name: '[email protected]' - home dir: /var/lib/rabbitmq - cookie hash: DGMyi0De4NLhiCnlJmHsTg== |
此问题停止RabbitMQ的服务再重新启动即可解决
1 2 |
rabbitmq-server stop rabbitmq-server -detached |
推荐阅读
- SpringCloud学习系列汇总
- 为什么一线大厂面试必问redis,有啥好问的?
- 多线程面试必备基础知识汇总
- Java集合源码分析汇总-JDK1.8
- Linux常用命令速查-汇总篇
- JVM系列文章汇总
- MySQL系列文章汇总
博客所有文章首发于公众号《Java学习录》转载请保留
扫码关注公众号即可领取2000GJava学习资源