测试环境:VMS00781 VMS00782 VMS00386 (centos5.8)
1.先在三台机器上分别安装RabbitMQ Server

2.读取其中一个节点的cookie,并复制到其他节点(节点间通过cookie确定相互是否可通信)
两者之一均可:
sudo vim /var/lib/rabbitmq/.erlang.cookie
sudo vim $HOME/.erlang.cookie

3.逐个启动节点
sudo service rabbitmq-server start

4.查看各节点中的RabbitMQ brokers
sudo rabbitmqctl cluster_status

5.建集群
分别在VMS00386、VMS00782 上执行
sudo rabbitmqctl stop_app
sudo rabbitmqctl join_cluster --ram rabbit@VMS00781
sudo rabbitmqctl start_app
sudo rabbitmqctl stop_app
sudo rabbitmqctl join_cluster rabbit@VMS00781
sudo rabbitmqctl start_app

6.排错
建集群过程中碰到如下错误:
sudo rabbitmqctl join_cluster --ram rabbit@VMS00386
Clustering node rabbit@VMS00782 with rabbit@VMS00386 ...
Error: unable to connect to nodes [rabbit@VMS00386]: nodedown
DIAGNOSTICS
===========
attempted to contact: [rabbit@VMS00386]
rabbit@VMS00386:
  * unable to connect to epmd (port 4369) on VMS00386: nxdomain (non-existing domain)
current node details:
- node name: 'rabbitmqctl-8666@VMS00782'
- home dir: /var/lib/rabbitmq
- cookie hash: 50YO3zK+HJHos0tab1vHjg==
解决之道:
集群节点间需能互相访问,故每个集群节点的hosts文件应包含集群内所有节点的信息以保证互相解析
vim /etc/hosts
781's IP   VMS00781
782's IP   VMS00782
386's IP   vms00386
之后重启各节点中的rabbitmq

7.其他问题

cluster搭建起来后若在web管理工具中rabbitmq_management的Overview的Nodes部分看到“Node statistics not available”的信息,说明在该节点上web管理插件还未启用。

直接在显示提示信息的节点上运行sudo rabbitmq-plugins enable rabbitmq_management即可。

Error: mnesia_unexpectedly_running
原因:忘记先停止stop_app
解决:sudo rabbitmqctl stop_app

若rabbitmq-server第一次启动后hostname不能被解析或者发生了更改则会导致启动失败
需执行如下操作
sudo rm -rf /var/lib/rabbitmq/mnesia(因为相关信息会记录在此数据库)
重装RabbitMQ Server

#####################################################
RabbitMQ cluster 管理
#####################################################
1.查看集群状态
可分别在集群中各个节点执行
sudo rabbitmqctl cluster_status

2.更改节点类型(内存型或磁盘型)
sudo rabbitmqctl stop_app
sudo rabbitmqctl change_cluster_node_type disc

sudo rabbitmqctl change_cluster_node_type ram
sudo rabbitmqctl start_app

3.重启cluster中的节点
停止某个节点或者节点down掉剩余节点不受影响
[op1@vms00386 ~]$ sudo rabbitmqctl stop
Stopping and halting node rabbit@vms00386 ...

[op1@VMS00781 ~]$ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@VMS00781 ...
[{nodes,[{disc,[rabbit@VMS00781,rabbit@VMS00782,rabbit@vms00386]}]},
 {running_nodes,[rabbit@VMS00782,rabbit@VMS00781]},
 {cluster_name,<<"rabbit@VMS00781">>},
 {partitions,[]}]

[op1@VMS00782 ~]$ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@VMS00782 ...
[{nodes,[{disc,[rabbit@VMS00781,rabbit@VMS00782,rabbit@vms00386]}]},
 {running_nodes,[rabbit@VMS00781,rabbit@VMS00782]},
 {cluster_name,<<"rabbit@VMS00781">>},
 {partitions,[]}]

[op1@VMS00782 ~]$ sudo rabbitmqctl stop
Stopping and halting node rabbit@VMS00782 ...

[op1@VMS00781 ~]$ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@VMS00781 ...
[{nodes,[{disc,[rabbit@VMS00781,rabbit@VMS00782,rabbit@vms00386]}]},
 {running_nodes,[rabbit@VMS00781]},
 {cluster_name,<<"rabbit@VMS00781">>},
 {partitions,[]}]

待节点重启后自动追上其他节点
[op1@vms00386 ~]$ sudo service rabbitmq-server start
Starting rabbitmq-server: SUCCESS
rabbitmq-server.

[op1@VMS00781 ~]$ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@VMS00781 ...
[{nodes,[{disc,[rabbit@VMS00781,rabbit@VMS00782,rabbit@vms00386]}]},
 {running_nodes,[rabbit@vms00386,rabbit@VMS00781]},
 {cluster_name,<<"rabbit@VMS00781">>},
 {partitions,[]}]

[op1@VMS00782 ~]$ sudo service rabbitmq-server start
Starting rabbitmq-server: SUCCESS
rabbitmq-server.

[op1@VMS00781 ~]$ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@VMS00781 ...
[{nodes,[{disc,[rabbit@VMS00781,rabbit@VMS00782,rabbit@vms00386]}]},
 {running_nodes,[rabbit@VMS00782,rabbit@vms00386,rabbit@VMS00781]},
 {cluster_name,<<"rabbit@VMS00781">>},
 {partitions,[]}]

[op1@VMS00782 ~]$ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@VMS00782 ...
[{nodes,[{disc,[rabbit@VMS00781,rabbit@VMS00782,rabbit@vms00386]}]},
 {running_nodes,[rabbit@VMS00781,rabbit@vms00386,rabbit@VMS00782]},
 {cluster_name,<<"rabbit@VMS00781">>},
 {partitions,[]}]

[op1@vms00386 ~]$ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@vms00386 ...
[{nodes,[{disc,[rabbit@VMS00781,rabbit@VMS00782,rabbit@vms00386]}]},
 {running_nodes,[rabbit@VMS00782,rabbit@VMS00781,rabbit@vms00386]},
 {cluster_name,<<"rabbit@VMS00781">>},
 {partitions,[]}]

几点注意:
保证集群中至少有一个磁盘类型的节点以防数据丢失,在更改节点类型时尤其要注意。
若整个集群被停掉了,应保证最后一个down掉的节点被最先启动,若不能则要使用forget_cluster_node命令将其移出集群
若集群中节点几乎同时以不可控的方式down了此时在其中一个节点使用force_boot命令重启节点

4.从集群移除节点
[op1@vms00386 ~]$ sudo rabbitmqctl stop_app
Stopping node rabbit@vms00386 ...
[op1@vms00386 ~]$ sudo rabbitmqctl reset
Resetting node rabbit@vms00386 ...
[op1@vms00386 ~]$ sudo rabbitmqctl start_app
Starting node rabbit@vms00386 ...

[op1@vms00386 ~]$ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@vms00386 ...
[{nodes,[{disc,[rabbit@vms00386]}]},
 {running_nodes,[rabbit@vms00386]},
 {cluster_name,<<"rabbit@vms00386">>},
 {partitions,[]}]

[op1@VMS00781 ~]$ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@VMS00781 ...
[{nodes,[{disc,[rabbit@VMS00781,rabbit@VMS00782]}]},
 {running_nodes,[rabbit@VMS00782,rabbit@VMS00781]},
 {cluster_name,<<"rabbit@VMS00781">>},
 {partitions,[]}]

[op1@VMS00782 ~]$ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@VMS00782 ...
[{nodes,[{disc,[rabbit@VMS00781,rabbit@VMS00782]}]},
 {running_nodes,[rabbit@VMS00781,rabbit@VMS00782]},
 {cluster_name,<<"rabbit@VMS00781">>},
 {partitions,[]}]
可见rabbit@vms00386成为了独立的节点,原集群只剩rabbit@VMS00781,rabbit@VMS00782了

也可在某个节点移除集群中其他节点
如继续在rabbit@VMS00781上移除rabbit@VMS00782
[op1@VMS00781 ~]$ sudo rabbitmqctl forget_cluster_node rabbit@VMS00782
Removing node rabbit@VMS00782 from cluster ...

[op1@VMS00781 ~]$ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@VMS00781 ...
[{nodes,[{disc,[rabbit@VMS00781]}]},
 {running_nodes,[rabbit@VMS00781]},
 {cluster_name,<<"rabbit@VMS00781">>},
 {partitions,[]}]

可见集群只剩rabbit@VMS00781一个节点了

这里有个问题,在远程其他节点中被移除的节点会自认为仍属于集群

[op1@VMS00782 ~]$ sudo rabbitmqctl start_app
Starting node rabbit@VMS00782 ...
BOOT FAILED
===========
Error description:
   {error,{inconsistent_cluster,"Node rabbit@VMS00782 thinks it's
clustered with node rabbit@VMS00781, but rabbit@VMS00781 disagrees"}}
Log files (may contain more information):
   /var/log/rabbitmq/rabbit@VMS00782.log
   /var/log/rabbitmq/rabbit@VMS00782-sasl.log
Stack trace:
   [{rabbit_mnesia,check_cluster_consistency,0},
    {rabbit,'-start/0-fun-0-',0},
    {rabbit,start_it,1},
    {rpc,'-handle_call_call/6-fun-0-',5}]
Error: {rabbit,failure_during_boot,
           {error,
               {inconsistent_cluster,
                   "Node rabbit@VMS00782 thinks it's clustered with node rabbit@VMS00781, but rabbit@VMS00781 disagrees"}}}
需要重置一下
[op1@VMS00782 ~]$ sudo rabbitmqctl reset
Resetting node rabbit@VMS00782 ...
[op1@VMS00782 ~]$ sudo rabbitmqctl start_app
Starting node rabbit@VMS00782 ...

此时三个节点均已成为独立的节点
其中rabbit@vms00386、rabbit@VMS00782均被重置为了新的RabbitMQ broker而rabbit@VMS00781还保留着原cluster的残留状态可通过如下步骤重置
[op1@VMS00781 ~]$ sudo rabbitmqctl stop_app
Stopping node rabbit@VMS00781 ...
[op1@VMS00781 ~]$ sudo rabbitmqctl reset
Resetting node rabbit@VMS00781 ...
[op1@VMS00781 ~]$ sudo rabbitmqctl start_app
Starting node rabbit@VMS00781 ...

5.自动配置cluster
显然,这是通过配置文件而非命令行工具进行的
首先重置各节点
[op1@VMS00781 ~]$ sudo rabbitmqctl stop_app
Stopping node rabbit@VMS00781 ...
[op1@VMS00781 ~]$ sudo rabbitmqctl reset
Resetting node rabbit@VMS00781 ...
...
其次调整配置文件
[{rabbit,
  [{cluster_nodes, {['rabbit@VMS00781', 'rabbit@VMS00782', 'rabbit@vms00386'], disc}}]}].
...
之后启动各节点
[op1@VMS00781 ~]$ sudo service rabbitmq-server start
Starting rabbitmq-server: SUCCESS
rabbitmq-server.

查看集群状态
[op1@VMS00781 ~]$ sudo rabbitmqctl cluster_status

几点注意:
无论通过命令行还是通过配置文件配置,请确保各节点上Erlang和RabbitMQ版本一致
配置文件仅对新鲜节点有效,也即被reset或者第一次启动的节点。因此在重启节点后自动化集群过程并不会发生。也以为这通过rabbitmq进行的改变优先于自动化集群配置。

在一台机器上部署集群,一般用户测试集群特性
这里的关键是已不同的端口可节点名称启动多个rabbitmq-server实例,其余过程同多机器上部署集群类似

其他注意事项:
如防火墙策略等

参考:
http://www.rabbitmq.com/clustering.html

转载:  https://blog.csdn.net/zyz511919766/article/details/41896747

RabbitMQ概念及环境搭建(三)RabbitMQ cluster的更多相关文章

  1. RabbitMQ概念及环境搭建(四)RabbitMQ High Availability

    #################################################### RabbitMQ High Availability #################### ...

  2. odoo开发环境搭建(三):安装odoo依赖的python包

    odoo开发环境搭建(三):安装odoo依赖的python包 http://www.cnblogs.com/jlzhou/p/5940815.html

  3. 从零搭建ES搜索服务(一)基本概念及环境搭建

    一.前言 本系列文章最终目标是为了快速搭建一个简易可用的搜索服务.方案并不一定是最优,但实现难度较低. 二.背景 近期公司在重构老系统,需求是要求知识库支持全文检索. 我们知道普通的数据库 like ...

  4. .Net RabbitMQ系列之环境搭建于RabbitMQ基本介绍

    本系列主要讲解RabbitMQ在.Net环境下的应用,由于Linux环境下,本人Linux功力有限,所以本系列的RabbitMQ跑在Windows环境中.所以的配置之类都在Windows环境中进行. ...

  5. Go语言学习之1 基本概念、环境搭建、第一个Go程序

    一.环境搭建 见我的这篇博客 https://www.cnblogs.com/xuejiale/p/10258244.html 二.golang语言特性1. 垃圾回收    1) 内存自动回收,再也不 ...

  6. Java基础学习之基础概念与环境搭建(1)

    1.Java基础概念 1.1.Java语言的特点 Java语言是简单易学的 Java语言是面向对象(封装.继承和多态) Java语言是平台无关的(一次编译,到处运行) Java语言是可靠的.安全的(异 ...

  7. eclipse中SSH三大框架环境搭建<三>

    相关链接: eclipse中SSH三大框架环境搭建<一> eclipse中SSH三大框架环境搭建<二> 引言:通过上两篇文章我们已经可以掌握struts2和spring的环境的 ...

  8. 【rabbitmq】rabbitmq集群环境搭建

    安装rabbitmq-server 总共有3台虚拟机,都安装有rabbitmq服务,安装过程可参考: [rabbitmq]Centos7 下安装rabbitmq 创建用户和vhost 说明: 此步骤不 ...

  9. RabbitMQ集群环境搭建-4

    确保成功安装好JDK,erlang,RabbitMQ等,并且RabbitMQ能正常启动,多台电脑之间能互相ping得通. 1. 安装 erlang.rabbitmq 如: 192.168.1.1.19 ...

随机推荐

  1. iOS开发--开源库

    图像: 1.图片浏览控件MWPhotoBrowser        实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩 ...

  2. Entity Framework泛型封装

    Entity Framework本身的增删改查其实 已经很方便了,不过做项目的时候用的多了也就觉得有点累了,每个业务实体基本上都涉及到到了增删改查这四个基本的要素,至于封装每个公司可能都不一样,接口, ...

  3. Swap Nodes in Pairs leetcode java

    题目: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1-> ...

  4. eclipse maven 报错Could not get the value for parameter encoding for plugin execution default

    问题描述:更改默认的maven仓库路径完成后.即存maven项目或者新建maven项目的时候出现如下错误 Could not get the value for parameter encoding ...

  5. jquery获得select option的值和对select option的操作

    <body> <select name="month" id="selMonth" onchange="set()"> ...

  6. 应用程序在状态栏展示时间(C#)

    private DispatcherTimer _timer; private void SetTimeElaspInStatusBar() { try { _timer = new Dispatch ...

  7. electron项目中使用jquery不生效的解决方法

    才开始接触electron的时候,本来想用bootstrap快速搞一个demo,无奈有些功能没法用,之后才意识到是jquery没发用,之后找了一些资料,比较简单的方式就是在引入jquery之前加入一下 ...

  8. Diablo 3 Web API

    这是暴雪提供的WebAPI,能够通过网页的方式訪问玩家的用户信息.结构相当清晰,非常有借鉴价值. 应用JSON(JavaScript Object Notation)做数据交换,很好理解. 以我的暗黑 ...

  9. Cocos Studio is EOL'd

    Cocos Studio is EOL'd Cocos Studio has been EOL'd as of April 2016. There will be no more releases o ...

  10. Makefile整理

    Makefile里的subst 用法是$(subst FROM,TO,TEXT),即将TEXT中的东西从FROM变为TO Makefile中的字符串处理函数 格式: $(subst <from& ...