RabbitMQ概念及环境搭建(三)RabbitMQ cluster

测试环境: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 [email protected]

sudo rabbitmqctl start_app

sudo rabbitmqctl stop_app

sudo rabbitmqctl join_cluster [email protected]

sudo rabbitmqctl start_app

6.排错

建集群过程中碰到如下错误:

sudo rabbitmqctl join_cluster --ram [email protected]

Clustering node [email protected] with [email protected] ...

Error: unable to connect to nodes [[email protected]]: nodedown

DIAGNOSTICS

===========

attempted to contact: [[email protected]]

[email protected]:

* unable to connect to epmd (port 4369) on VMS00386: nxdomain (non-existing domain)

current node details:

- node name: ‘[email protected]‘

- 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.其他问题

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掉剩余节点不受影响

[[email protected] ~]$ sudo rabbitmqctl stop

Stopping and halting node [email protected] ...

[[email protected] ~]$ sudo rabbitmqctl cluster_status

Cluster status of node [email protected] ...

[{nodes,[{disc,[[email protected],[email protected],[email protected]]}]},

{running_nodes,[[email protected],[email protected]]},

{cluster_name,<<"[email protected]">>},

{partitions,[]}]

[[email protected] ~]$ sudo rabbitmqctl cluster_status

Cluster status of node [email protected] ...

[{nodes,[{disc,[[email protected],[email protected],[email protected]]}]},

{running_nodes,[[email protected],[email protected]]},

{cluster_name,<<"[email protected]">>},

{partitions,[]}]

[[email protected] ~]$ sudo rabbitmqctl stop

Stopping and halting node [email protected] ...

[[email protected] ~]$ sudo rabbitmqctl cluster_status

Cluster status of node [email protected] ...

[{nodes,[{disc,[[email protected],[email protected],[email protected]]}]},

{running_nodes,[[email protected]]},

{cluster_name,<<"[email protected]">>},

{partitions,[]}]

待节点重启后自动追上其他节点

[[email protected] ~]$ sudo service rabbitmq-server start

Starting rabbitmq-server: SUCCESS

rabbitmq-server.

[[email protected] ~]$ sudo rabbitmqctl cluster_status

Cluster status of node [email protected] ...

[{nodes,[{disc,[[email protected],[email protected],[email protected]]}]},

{running_nodes,[[email protected],[email protected]]},

{cluster_name,<<"[email protected]">>},

{partitions,[]}]

[[email protected] ~]$ sudo service rabbitmq-server start

Starting rabbitmq-server: SUCCESS

rabbitmq-server.

[[email protected] ~]$ sudo rabbitmqctl cluster_status

Cluster status of node [email protected] ...

[{nodes,[{disc,[[email protected],[email protected],[email protected]]}]},

{running_nodes,[[email protected],[email protected],[email protected]]},

{cluster_name,<<"[email protected]">>},

{partitions,[]}]

[[email protected] ~]$ sudo rabbitmqctl cluster_status

Cluster status of node [email protected] ...

[{nodes,[{disc,[[email protected],[email protected],[email protected]]}]},

{running_nodes,[[email protected],[email protected],[email protected]]},

{cluster_name,<<"[email protected]">>},

{partitions,[]}]

[[email protected] ~]$ sudo rabbitmqctl cluster_status

Cluster status of node [email protected] ...

[{nodes,[{disc,[[email protected],[email protected],[email protected]]}]},

{running_nodes,[[email protected],[email protected],[email protected]]},

{cluster_name,<<"[email protected]">>},

{partitions,[]}]

几点注意:

保证集群中至少有一个磁盘类型的节点以防数据丢失,在更改节点类型时尤其要注意。

若整个集群被停掉了,应保证最后一个down掉的节点被最先启动,若不能则要使用forget_cluster_node命令将其移出集群

若集群中节点几乎同时以不可控的方式down了此时在其中一个节点使用force_boot命令重启节点

4.从集群移除节点

[[email protected] ~]$ sudo rabbitmqctl stop_app

Stopping node [email protected] ...

[[email protected] ~]$ sudo rabbitmqctl reset

Resetting node [email protected] ...

[[email protected] ~]$ sudo rabbitmqctl start_app

Starting node [email protected] ...

[[email protected] ~]$ sudo rabbitmqctl cluster_status

Cluster status of node [email protected] ...

[{nodes,[{disc,[[email protected]]}]},

{running_nodes,[[email protected]]},

{cluster_name,<<"[email protected]">>},

{partitions,[]}]

[[email protected] ~]$ sudo 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,[]}]

[[email protected] ~]$ sudo 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,[]}]

可见[email protected]成为了独立的节点,原集群只剩[email protected],[email protected]了

也可在某个节点移除集群中其他节点

如继续在[email protected]上移除[email protected]

[[email protected] ~]$ sudo rabbitmqctl forget_cluster_node [email protected]

Removing node [email protected] from cluster ...

[[email protected] ~]$ sudo rabbitmqctl cluster_status

Cluster status of node [email protected] ...

[{nodes,[{disc,[[email protected]]}]},

{running_nodes,[[email protected]]},

{cluster_name,<<"[email protected]">>},

{partitions,[]}]

可见集群只剩[email protected]一个节点了

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

[[email protected] ~]$ sudo rabbitmqctl start_app

Starting node [email protected] ...

BOOT FAILED

===========

Error description:

{error,{inconsistent_cluster,"Node [email protected] thinks it‘s clustered with node [email protected], but [email protected] disagrees"}}

Log files (may contain more information):

/var/log/rabbitmq/[email protected]

/var/log/rabbitmq/[email protected]

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 [email protected] thinks it‘s clustered with node [email protected], but [email protected] disagrees"}}}

需要重置一下

[[email protected] ~]$ sudo rabbitmqctl reset

Resetting node [email protected] ...

[[email protected] ~]$ sudo rabbitmqctl start_app

Starting node [email protected] ...

此时三个节点均已成为独立的节点

其中[email protected]、[email protected]均被重置为了新的RabbitMQ broker而[email protected]还保留着原cluster的残留状态可通过如下步骤重置

[[email protected] ~]$ sudo rabbitmqctl stop_app

Stopping node [email protected] ...

[[email protected] ~]$ sudo rabbitmqctl reset

Resetting node [email protected] ...

[[email protected] ~]$ sudo rabbitmqctl start_app

Starting node [email protected] ...

5.自动配置cluster

显然,这是通过配置文件而非命令行工具进行的

首先重置各节点

[[email protected] ~]$ sudo rabbitmqctl stop_app

Stopping node [email protected] ...

[[email protected] ~]$ sudo rabbitmqctl reset

Resetting node [email protected] ...

...

其次调整配置文件

[{rabbit,

[{cluster_nodes, {[‘[email protected]‘, ‘[email protected]‘, ‘[email protected]‘], disc}}]}].

...

之后启动各节点

[[email protected] ~]$ sudo service rabbitmq-server start

Starting rabbitmq-server: SUCCESS

rabbitmq-server.

查看集群状态

[[email protected] ~]$ sudo rabbitmqctl cluster_status

几点注意:

无论通过命令行还是通过配置文件配置,请确保各节点上Erlang和RabbitMQ版本一致

配置文件仅对新鲜节点有效,也即被reset或者第一次启动的节点。因此在重启节点后自动化集群过程并不会发生。也以为这通过rabbitmq进行的改变优先于自动化集群配置。

在一台机器上部署集群,一般用户测试集群特性

这里的关键是已不同的端口可节点名称启动多个rabbitmq-server实例,其余过程同多机器上部署集群类似

其他注意事项:

如防火墙策略等

参考:

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

时间: 2024-10-04 09:35:24

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

[置顶] RabbitMQ概念及环境搭建(三)RabbitMQ cluster

http://blog.csdn.net/zyz511919766/article/details/41896747 测试环境:VMS00781 VMS00782 VMS00386 (centos5.8)1.先在三台机器上分别安装RabbitMQ Server 2.读取其中一个节点的cookie,并复制到其他节点(节点间通过cookie确定相互是否可通信)两者之一均可:sudo vim /var/lib/rabbitmq/.erlang.cookiesudo vim $HOME/.erlang.

RabbitMQ概念及环境搭建(一)单节点安装与配置

############################################### #异步.分布式消息处理模型 ############################################### binding  +----------+    +----------------+ /------------+ queue +---+ consumer + +---------------+   +----------------+   |            +---

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

#################################################### RabbitMQ High Availability #################################################### 1.高可用queue 默认情况下RabbitMQ cluster中的queues位于单独的节点(queues被首次声明的节点),而exchanges和bindings存在于cluster中各节点.因而每个节点失效exchanges和b

RabbitMQ概念及环境搭建(二)RabbitMQ Broker管理

rabbitmqctl [-n node] [-q] {command} [command options...] 1.停Server rabbitmqctl stop 2.查看状态 rabbitmqctl status 其他常用项 sudo rabbitmqctl list_queues sudo rabbitmqctl list_exchanges sudo rabbitmqctl list_bindings ... 3.UI rabbitmq-management plugin 基于HTT

RabbitMQ概念及环境搭建(五)与web的整合

#################################### rabbitmq_web_stomp #################################### 处于试验阶段,同伙WebSocket兼容层SockJS时 Web Browser与RabbitMQ(rabbitmq-stomp)实时通讯,可用于实时的WEB应用 安装 sudo rabbitmq-plugins enable rabbitmq_web_stomp 测试 http://127.0.0.1:1567

BootStrap之基础-1 BootStrap起步(基本概念、环境搭建)

一.基本概念 Bootstrap 简介 - 移动设备优先 - 所有的主流浏览器都支持Bootstrap 它既是由动态CSS语言Less写成 Github热门开源项目 包括NASA的MSNBC(微软全国广播公司)的Breaking News都使用了该项目 够成 Bootstrap 目录说明 - CSS目录--用于存放Bootstrap框架使用的样式文件 - bootstrap.css文件: Bootstrap框架的样式文件 - bootstrap.min.css文件:Bootstrap框架的样式压

ExtJS之基本概念、环境搭建

一.基本概念 ExtJS 简介 - ExtJS 是一个兼容各浏览器的纯 JavaScript 应用程序框架,使用它可以创建最佳跨平台互联网应用程序 为什么 ExtJS 原因 二.环境搭建 目录结构 - 推荐下面这种目录结构 使用ExtJS 动态加载 引入库的方法 发布 Containers容器 Panel Layouts布局 布局系统如何工作 组件component 别名和延迟初始化 显示和隐藏 浮动组件 数据 模型和存储(Model & Stores) 创建一个模型 Model 创建一个存储S

AngularJS之基础-1 简介(基本概念、环境搭建)

一.基本概念 软件设计原则 - 不论是桌面应用还是Web应用,在进行设计编码时应该遵守一定的设计原则 软件设计模式 - 设计模式 Design Pattern,是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性.毫无疑问,设计模式用于已于他人于系统都是多赢的;设计模式使代码编制真正工程化;设计模式是软件工程的基石脉络,如同大厦的结构一样 - 23+1中设计模式 工厂模式.抽象工厂模式.建造者模式.原型模式.单例

[LAMP环境搭建三]PHP安装

****说明:先全部看一遍,再开始安装**** 获取PHP源码包 http://cn2.php.net/get/php-5.5.10.tar.gz/from/this/mirrorwget 安装libxml2:wget ftp://xmlsoft.org/libxml2/libxml2-2.9.1.tar.gz./configure --prefix=/usr/local/libxml2# yum -y install python-devel 安装zlib:wget http://zlib.n