由于某些因素的限制,有时候你不得不在一台机器上去搭建一个rabbitmq集群,当然这种集群只适合自己玩玩,验证下结论,这个有点类似zookeeper的单机版。真实生成环境还是要配成多机集群的。有关怎么配置多机集群的可以参考其他的资料,这里主要论述如何在单机中配置多个rabbitmq实例。

主要参考官方文档:https://www.rabbitmq.com/clustering.html

前提

配置的前提是你的rabbitmq可以运行起来,比如”ps aux|grep rabbitmq”你能看到相关进程,又比如运行“rabbitmqctl status”你可以看到类似如下信息,而不报错:

[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl status
Status of node 'rabbit@hiddenzhu-8drdc' ...
[{pid,13014},
 {running_applications,[{rabbit,"RabbitMQ","3.4.0"},
                        {mnesia,"MNESIA  CXC 138 12","4.14.1"},
                        {os_mon,"CPO  CXC 138 46","2.4.1"},
                        {xmerl,"XML parser","1.3.12"},
                        {sasl,"SASL  CXC 138 11","3.0.1"},
                        {stdlib,"ERTS  CXC 138 10","3.1"},
                        {kernel,"ERTS  CXC 138 10","5.1"}]},
 {os,{unix,linux}},
 {erlang_version,"Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:30] [hipe] [kernel-poll:true]\n"},
 {memory,[{total,37276536},
          {connection_readers,0},
          {connection_writers,0},
          {connection_channels,0},
          {connection_other,2832},
          {queue_procs,2832},
          {queue_slave_procs,0},
          {plugins,0},
          {other_proc,13331064},
          {mnesia,66248},
          {mgmt_db,0},
          {msg_index,41184},
          {other_ets,778528},
          {binary,23152},
          {code,14637029},
          {atom,654241},
          {other_system,7739426}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,3301929779},
 {disk_free_limit,50000000},
 {disk_free,37108654080},
 {file_descriptors,[{total_limit,924},
                    {total_used,3},
                    {sockets_limit,829},
                    {sockets_used,1}]},
 {processes,[{limit,1048576},{used,126}]},
 {run_queue,0},
 {uptime,2143}]

为了简单化,这里也要保证rabbitmq的plugin没有开启(因为开启之后要占用一些端口,多实例配置起来会更加复杂,这里简单问题简化说明)。

情景

假设有三个rabbitmq节点,分别为rabbit1, rabbit2和rabbit3

主要开启命令如下:

RABBITMQ_NODE_PORT=5672 RABBITMQ_NODENAME=rabbit1 rabbitmq-server -detached
RABBITMQ_NODE_PORT=5673 RABBITMQ_NODENAME=rabbit2 rabbitmq-server -detached
RABBITMQ_NODE_PORT=5674 RABBITMQ_NODENAME=rabbit3 rabbitmq-server -detached

结束命令如下:

rabbitmqctl -n rabbit1 stop
rabbitmqctl -n rabbit2 stop
rabbitmqctl -n rabbit3 stop

rabbit1

[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit1 stop_app
Stopping node 'rabbit1@hiddenzhu-8drdc' ...
...done.
[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit1 reset
Resetting node 'rabbit1@hiddenzhu-8drdc' ...
...done.
[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit1 cluster
Clustering node 'rabbit1@hiddenzhu-8drdc' with [] ...
...done.
[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit1 start_app
Starting node 'rabbit1@hiddenzhu-8drdc' ...
...done.

TIPS

有些版本(比如3.4.0)在第一个节点(主节点)运行“rabbitmqctl -n rabbit1 cluster” 时会遇到:

Error: could not recognise command

的错误,可以不运行“rabbitmqctl -n rabbit1 cluster”这句。然后在从节点运行:

rabbitmqctl -n rabbit2 join_cluster rabbit1@`hostname -s`

这一句。

主要原因是:有些版本不识别cluster这个命令

rabbit2

[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit2 stop_app
Stopping node 'rabbit2@hiddenzhu-8drdc' ...
...done.
[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit2 reset
Resetting node 'rabbit2@hiddenzhu-8drdc' ...
...done.
[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit2 cluster rabbit1@`hostname -s`
Clustering node 'rabbit2@hiddenzhu-8drdc' with ['rabbit1@hiddenzhu-8drdc'] ...
...done.
[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit2 start_app
Starting node 'rabbit2@hiddenzhu-8drdc' ...
...done.

TIPS

如果略去“rabbitmqctl -n rabbit2 reset”这一句,可能会报错:

Error: {ok,already_member}

查看cluster信息

[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit1 cluster_status
Cluster status of node 'rabbit1@hiddenzhu-8drdc' ...
[{nodes,[{disc,['rabbit1@hiddenzhu-8drdc']},
         {ram,['rabbit2@hiddenzhu-8drdc']}]},
 {running_nodes,['rabbit2@hiddenzhu-8drdc','rabbit1@hiddenzhu-8drdc']}]
...done.
[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit2 cluster_status
Cluster status of node 'rabbit2@hiddenzhu-8drdc' ...
[{nodes,[{disc,['rabbit1@hiddenzhu-8drdc']},
         {ram,['rabbit2@hiddenzhu-8drdc']}]},
 {running_nodes,['rabbit1@hiddenzhu-8drdc','rabbit2@hiddenzhu-8drdc']}]
...done.

加入节点rabbit3

[root@hiddenzhu-8drdc rabbitmq]# RABBITMQ_NODE_PORT=5674 RABBITMQ_NODENAME=rabbit3 rabbitmq-server -detached
Activating RabbitMQ plugins ...
0 plugins activated:

[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit3 stop_app
Stopping node 'rabbit3@hiddenzhu-8drdc' ...
...done.
[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit3 reset
Resetting node 'rabbit3@hiddenzhu-8drdc' ...
...done.
[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit3 cluster rabbit1@`hostname -s`
Clustering node 'rabbit3@hiddenzhu-8drdc' with ['rabbit1@hiddenzhu-8drdc'] ...
...done.
[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit3 start_app
Starting node 'rabbit3@hiddenzhu-8drdc' ...
...done.

最终查看集群状态

[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit3 cluster_status
Cluster status of node 'rabbit3@hiddenzhu-8drdc' ...
[{nodes,[{disc,['rabbit1@hiddenzhu-8drdc']},
         {ram,['rabbit3@hiddenzhu-8drdc','rabbit2@hiddenzhu-8drdc']}]},
 {running_nodes,['rabbit1@hiddenzhu-8drdc','rabbit2@hiddenzhu-8drdc',
                 'rabbit3@hiddenzhu-8drdc']}]
...done.

TIPS

有可能遇到这样的情况:

[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl status -n rabbit2
Status of node 'rabbit2@hiddenzhu-8drdc' ...
Error: {badarith,[{rabbit_vm,bytes,1,[]},
                  {rabbit_vm,'-mnesia_memory/0-lc$^0/1-0-',1,[]},
                  {rabbit_vm,mnesia_memory,0,[]},
                  {rabbit_vm,memory,0,[]},
                  {rabbit,status,0,[]},
                  {rpc,'-handle_call_call/6-fun-0-',5,
                       [{file,"rpc.erl"},{line,187}]}]}

有一种解决版本是将“/var/lib/rabbitmq/mnesia/”目录下的所有内容删掉(rm -rf *),然后重新启动再配置。

And….

很多时候也会遇到这样的情况:

[root@hiddenzhu-8drdc rabbitmq]# rabbitmqctl -n rabbit2 status
Status of node 'rabbit2@hiddenzhu-8drdc' ...
Error: unable to connect to node 'rabbit2@hiddenzhu-8drdc': nodedown
diagnostics:
- nodes and their ports on hiddenzhu-8drdc: [{rabbit1,44494},
                                             {rabbitmqctl2271,60458}]
- current node: 'rabbitmqctl2271@hiddenzhu-8drdc'
- current node home dir: /root
- current node cookie hash: VCwbL3S9/ydrGgVsrLjVkA==

这说明rabbitmq节点并未启动起来,需要进一步查看排除异常。

End…

RabbitMQ单机多实例配置的更多相关文章

  1. MySQL 5.5.35 单机多实例配置详解

    一.前言 二.概述 三.环境准备 四.安装MySQL 5.5.35 五.新建支持多实例的配置文件(我这里配置的是四个实例) 六.初始化多实例数据库 七.提供管理脚本 mysqld_multi.serv ...

  2. Tomcat 的单机多实例配置

    有时候需要在一个服务器上部署多个Tomcat,通过不同的端口进行区分,比如,反向代理.但是不想简单的通过复制Tomcat来实现,这样既不方便以后的升级也不方便管理,那么这时候就需要配置Tomcat的单 ...

  3. tomcat之 Tomcat 7.0.78 单机多实例配置

    前言:JDK(JavaDevelopment Kit)是Sun Microsystems针对Java开发员的产品.自从Java推出以来,JDK已经成为使用最广泛的javaSDK. JDK是整个Java ...

  4. mysql单机多实例配置

    Windows上配置多个mysql实例,主要改下配置文件即可,mysql目录如下: my2中主要改两个配置内容 datadir = D:/Program Files/Mysql/mysql-5.7.2 ...

  5. mysql 单机多实例配置

    如果你想在一台机器上进行主从配置实验,本篇可以帮助你实现愿望 [client] #password = your_password port = 3306 socket = /tmp/mysql.so ...

  6. Redis集群(单机多实例)

    Redis介绍   Redis是一个分布式缓存数据库服务器,提供基于内存访问的缓存服务,并且无论是在单服务器还是服务器集群上都有着较为灵活方便的扩展能力.   单个的Redis实例是单进程单线程的,由 ...

  7. MySQL单机多实例安装并配置主从复制

    单机多实例据说可以最大程度提高硬件使用,谁知道呢,但是以前的公司喜欢这样搞,我最近也在学习复制什么的,电脑搞不起两台虚拟机,刚好单机多实例可以解救我.下面就说说步骤. 承上文http://www.cn ...

  8. Elasticsearch单机下多实例配置

    ##################### Elasticsearch Configuration Example ##################### index.cache.field.ty ...

  9. RabbitMQ集群安装配置+HAproxy+Keepalived高可用

    RabbitMQ集群安装配置+HAproxy+Keepalived高可用 转自:https://www.linuxidc.com/Linux/2016-10/136492.htm rabbitmq 集 ...

随机推荐

  1. Spoken English Practice (yesterday) (Look, I just wanted to apologize again for yesterday? It's fine, I know you didn't mean it. / when I say it, I mean it.)

    绿色:连读:                  红色:略读:               蓝色:浊化:               橙色:弱读     下划线_为浊化 口语蜕变(2017/7/12) ...

  2. JQueryiframe页面操作父页面中的元素与方法(实例讲解)

    1)在iframe中查找父页面元素的方法:$('#id', window.parent.document) 2)在iframe中调用父页面中定义的方法和变量:parent.methodparent.v ...

  3. Client IP Address Client Identification

    HTTP The Definitive Guide Early web pioneers tried using the IP address of the client as a form of i ...

  4. Windows系统优化

    1.关闭家庭组,因为这功能会导致硬盘和CPU处于高负荷状态: 关闭方法:windows + R 打开运行,输入services.msc回车,右侧窗格找到“HomeGroup Listener”和“Ho ...

  5. chrome 因js死循环卡住

    chrome因js死循环卡住的解决方法: top命令查看chrome的pid kill -9 pid 杀死整个chrome进程(所有网页都关闭)

  6. pandas.read_csv() 部分参数解释

    read_csv()所有参数 pandas.read_csv( filepath_or_buffer, sep=',', delimiter=None, header='infer', names=N ...

  7. SpringBoot-URL路由:@Controller和@RequestMapping

    SpringBoot定义URL处理方法:@Controller和@RequestMapping @Controller标注的类表示的是一个处理HTTP请求的控制器(即MVC中的C),该类中所有被@Re ...

  8. PHP 基础篇 - PHP 正则官方文档汇总

    一.PCRE 正则语法 下面是 PHP 的 PCRE 正则语法(模式语法)相关文档,详情请查阅相关链接: 简介 分隔符 元字符 转义序列(反斜线) Unicode字符属性 锚 句点 字符类(方括号) ...

  9. opencv:vs2015添加了包含目录依然无法打开‘opencv2/core/core.hpp’ 解决方法

    安装环境 win10 vs2015 出错和改错 按网上的教程,配置好opencv后,包括已经把以下内容添加到'包含目录'了: E:\openCV\opencv\build\include E:\ope ...

  10. python的数据类型的有序无序

    列表有序可变 字典无序不可变 元组不可变 集合无序不可变 数字不可变 字符串不可变