RabbitMQ的安装及集群搭建方法

RabbitMQ安装

1 安装erlang

下载地址:http://www.erlang.org/downloads

博主这里采用的是otp_src_19.1.tar.gz (200MB+)

[[email protected] util]# tar zxvf  otp_src_19.1.tar.gz
[[email protected] util]# cd otp_src_19.1
[[email protected] otp_src_19.1]# ./configure --prefix=/opt/erlang
[[email protected] otp_src_19.1]# make
[[email protected] otp_src_19.1]# make install

修改/etc/profile文件,添加下面的环境变量:

ERLANG_HOME=/opt/erlang
export PATH=$PATH:$ERLANG_HOME/bin
export ERLANG_HOME

最后执行source /etc/profile让文件生效。

2 安装simpleJson

下载地址:https://pypi.python.org/pypi/simplejson/

博主这里采用的是simplejson-3.10.0.tar.gz

[[email protected] util]# tar zxvf simplejson-3.10.0.tar.gz
[[email protected] util]# cd simplejson-3.10.0
[[email protected] simplejson-3.10.0]# python setup.py install

3 安装rabbitmq

下载地址:http://www.rabbitmq.com/releases/rabbitmq-server/

博主这里用的版本就有很多了,比如2.7.0, 3.4.0, 3.4.1, 3.4.2, 3.4.3, 3.5.7, 3.6.0等等,不过都是用的rabbitmq-server-generic-unix-..*.tar.gz的版本。

这里以3.5.7举例:

[[email protected] util]# tar zvxf rabbitmq-server-generic-unix-3.5.7.tar.gz -C /opt
[[email protected] util]# cd /opt
[[email protected] util]# mv rabbitmq_server-3.5.7 rabbitmq

修改/etc/profile文件,添加下面的环境变量:

export PATH=$PATH:/opt/rabbitmq/sbin

最后执行source /etc/profile让文件生效。

运行:rabbitmq-server -detached

之后运行rabbitmqctl status查看rabbitmq是否正常启动:

[[email protected] rabbitmq]# rabbitmqctl status
Status of node ‘[email protected]‘ ...
[{pid,25020},
 {running_applications,
     [{rabbitmq_management,"RabbitMQ Management Console","3.5.7"},
      {rabbitmq_management_agent,"RabbitMQ Management Agent","3.5.7"},
      {rabbit,"RabbitMQ","3.5.7"},
      {mnesia,"MNESIA  CXC 138 12","4.14.1"},
      {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.5.7"},
      {webmachine,"webmachine","1.10.3-rmq3.5.7-gite9359c7"},
      {mochiweb,"MochiMedia Web Server","2.7.0-rmq3.5.7-git680dba8"},
      {os_mon,"CPO  CXC 138 46","2.4.1"},
      {amqp_client,"RabbitMQ AMQP Client","3.5.7"},
      {inets,"INETS  CXC 138 49","6.3.3"},
      {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:64] [hipe] [kernel-poll:true]\n"},
 {memory,
     [{total,60110136},
      {connection_readers,0},
      {connection_writers,0},
      {connection_channels,0},
      {connection_other,5664},
      {queue_procs,1028160},
      {queue_slave_procs,1576056},
      {plugins,8008840},
      {other_proc,6115560},
      {mnesia,197760},
      {mgmt_db,14219256},
      {msg_index,58288},
      {other_ets,1181200},
      {binary,633896},
      {code,17650127},
      {atom,711593},
      {other_system,8723736}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,3301929779},
 {disk_free_limit,50000000},
 {disk_free,35754786816},
 {file_descriptors,
     [{total_limit,924},{total_used,6},{sockets_limit,829},{sockets_used,1}]},
 {processes,[{limit,1048576},{used,195}]},
 {run_queue,0},
 {uptime,139660}]

RabbitMQ集群搭建方法

这里展示的是多机集群的部署,如果机器受限,可以选择单机集群部署,详细可以参考《RabbitMQ单机多实例配置》。

这里选用三台主机,主机名分别是hidden1, hidden2, hidden3

1 在这三台机器中安装rabbitmq-server, 参考上面。

2 读取其中一个节点的cookie, 并复制到其他节点(节点之间通过cookie确定相互是否可通信)。

cookie存放在/var/lib/rabbitmq/.erlang.cookie或者$HOME/.erlang.cookie中。

3 逐个启动节点 rabbitmq-server -detached

4 查看各节点的状态: rabbitmqctl status, rabbitmqctl cluster_status

5 配置各节点的hosts文件( vim /etc/hosts)

xxx.xxx.xxx.xxx hidden1

xxx.xxx.xxx.xxx hidden2

xxx.xxx.xxx.xxx hidden3

6 建立集群

以hidden1为主节点,在hidden2上:

rabbitmqctl stop_app

rabbitmqctl reset

rabbitmqctl join_cluster [email protected]

rabbitmqctl start_app

hidden3上的操作与hidden2的雷同。

最后通过rabbitmqctl cluster_status查看集群的状态信息:

[{nodes,[{disc,[[email protected],‘[email protected]‘,‘[email protected]‘]}]},
 {running_nodes,[[email protected],‘[email protected]‘,‘[email protected]‘]},
 {cluster_name,<<"[email protected]">>},
 {partitions,[]}]

7 在访问web(http://xxx.xxx.xxx.xxx:15672)时, 如果在Overview中的Nodes部分看到“Node statistics not available”的信息,说明在该节点上web管理插件还未启用。直接运行rabbitmq-plugins enable rabbitmq_management即可。

rabbitmq搭建集群踩坑记

三台节点启动之后,想要使用s146作为集群主节点,在s151上将该节点加入s146集群时,报如下错误。

[[email protected] rabbitmq]# rabbitmqctl join_cluster [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]:
  * connected to epmd (port 4369) on s146
  * epmd reports node ‘rabbit‘ running on port 25672
  * TCP connection succeeded but Erlang distribution failed
  * suggestion: hostname mismatch?
  * suggestion: is the cookie set correctly?
  * suggestion: is the Erlang distribution using TLS?

current node details:
- node name: ‘[email protected]‘
- home dir: /root
- cookie hash: X8M4gNn7BBuuU5WV1cHdhw==

我在网上看到了很多人都碰到了这个错误,错误提示中也说了三种解决方案。

suggestion: hostname mismatch?

hostname配置是否正确,对于hostname的配置可以参考https://my.oschina.net/mingshashan/blog/741988

suggestion: is the cookie set correctly?

.erlang.cookie设置是否正确,.erlang.cookie文件里面的字符串相当于一个密钥一样,一个节点想要加入某个集群,必须要和这个机器中的所有节点的.erlang.cookie内容一样,所以通常将主节点的.erlang.cookie文件分发给其它节点即可,关键是这个节点可能出现在两个位置/var/lib/rabbitmq/.erlang.cookie或者$HOME/.erlang.cookie。这样一来如何确定自己的.erlang.cookie文件在哪儿呢?这个要看rabbitmq的日志文件,如下所示:

=INFO REPORT==== 9-Apr-2018::14:57:21 ===
node           : [email protected]
home dir       : /root
config file(s) : /opt/rabbitmq/sbin/../etc/rabbitmq/rabbitmq.config (not found)
cookie hash    : HfR3DHABJqfPDV+hBgdzXQ==
log            : /opt/rabbitmq/sbin/../var/log/rabbitmq/[email protected]
sasl log       : /opt/rabbitmq/sbin/../var/log/rabbitmq/[email protected]
database dir   : /opt/rabbitmq/sbin/../var/lib/rabbitmq/mnesia/[email protected]

其中的home dir就是你的.erlang.cookie文件存放的目录,而这个cookie hash就是.erlang.cookie里面的值hash转换得到的,你可以比较cookie hash的值是不是一致来判断你的.erlang.cookie是否一致。我之前一直以为我的.erlang.cookie文件在/var/lib/rabbitmq/下,所以屡次操作都失败了,看了日志后发现节点的cookie hash不一致,才发现原来一直将.erlang.cookie这个文件的位置搞错了,所以看日志很重要。

suggestion: is the Erlang distribution using TLS?

这种情况目前好像还没碰到过。

参考: https://blog.csdn.net/u013256816/article/details/53524766

https://blog.csdn.net/u012062455/article/details/79867080

原文地址:https://www.cnblogs.com/tongxiaoda/p/9132676.html

时间: 2024-08-03 16:22:14

RabbitMQ的安装及集群搭建方法的相关文章

Hadoop2.7.2安装与集群搭建

1.环境准备 jdk需要1.7以上版本64位. 创建hadoop用户. 在hadoop用户目录下解压安装包hadoop-2.7.2.tar.gz 2.配置免密码登录 各节点分别执行 生成公钥和私钥:ssh-keygen -t rsa 四次enter. 将公钥添加进公钥库:cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 修改authorized_keys权限:chmod 600 ~/.ssh/authorized_keys 验证:ssh local

Hbase1.2.2安装和集群搭建

1.环境准备 jdk1.7.0_79 Hadoop2.7.2.(匹配Hbase1.2.2) zookeeer3.4.8 hbase-1.2.2-bin.tar.gz 最好和hadoop安装在统一用户下,解压安装包 tar zxvf hbase-1.2.2-bin.tar.gz 2. 修改配置文件 .bashrc(多节点) export JAVA_HOME=/usr/local/jdk1.7.0_79 export HADOOP_HOME=/home/hadoop/hadoop export HB

rabbitmq集群搭建方法简介(测试机linux centos)【转】

本文将介绍四台机器搭建rabbitmq集群: rabbitmq IP和主机名(每台机器已安装RabbitMQ 3.5.6, Erlang 18.1) 192.168.87.73 localhost73 192.168.87.74 localhost74 192.168.87.75 localhost75 192.168.87.76 localhost76 将上述IP和主机名添加到hosts文件( vim /etc/hosts) Rabbitmq的集群是依赖于erlang的集群来工作的,所以必须先

rabbitmq安装、集群搭建

rabbitmq的安装: CentOS上面部署: 首先修改hosts文件 修改hosts文件vi /etc/hosts1.1.1.1 hostname 2.2.2.2 hostname 3.3.3.3 hostname erlang的安装环境:rpm -i http://mirror.bjtu.edu.cn/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpmyum install erlang安装rabbitMQ(RPM链接可以从http://www

rabbitMQ 安装,集群搭建, 编码

RabbitMQ 一.背景 命令行工具: http://www.rabbitmq.com/man/rabbitmqctl.1.man.html 介绍入门文章: http://blog.csdn.net/anzhsoft/article/details/19563091 内容比较清晰: http://www.diggerplus.org/archives/3110 Exchange.Queue producer把消息发送到Exchange(带上route key),consumer声明queue(

Redis安装与集群搭建

1 1.1   安装redis n  版本说明 本教程使用redis3.0版本.3.0版本主要增加了redis集群功能. 安装的前提条件: 需要安装gcc:yum install gcc-c++ 1.下载redis的源码包. 2.把源码包上传到linux服务器 3.解压源码包 tar -zxvf redis-3.0.0.tar.gz 4.Make 5.Make install [[email protected] redis-3.0.0]# make install PREFIX=/usr/lo

十分钟教你学会zookeeper安装和集群搭建(伪集群 )

1. zookeeper介绍 ZooKeeper是一个为分布式应用所设计的分布的.开源的协调服务,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,简化分布式应用协调及其管理的难度,提供高性能的分布式服务.ZooKeeper本身可以以Standalone模式安装运行,不过它的长处在于通过分布式ZooKeeper集群(一个Leader,多个Follower),基于一定的策略来保证ZooKeeper集群的稳定性和可用性,从而实现分布式应用的可靠性. ZooKeeper是作为分布式协调服务,是不

zookeeper3.4.8安装和集群搭建

1.环境准备 创建zookeeper用户. 准备安装包: zookeeper-3.4.8.tar.gz. 拷贝至安装目录并解压 tar zxvf zookeeper-3.3.6.tar.gz mv zookeeper-3.3.6 zookeeper 2.配置文件 zookeeper/conf/zoo.cfg(需手动创建) #zookeeper使用的基本时间单位(ms) tickTime=2000 #leader和follow之间的最长心跳时间(ticktime的倍数) initLimit=5 #

redis集群搭建方法

概念 首先有个概念: Redis需要半数以上投票某个节点挂掉才算挂掉,所以至少需要3个master节点,然后又需要3个slave备份节点,所以共6个.只有主备机才会同步数据,平行的三个节点数据是不一样的,只是你连接任意一点,然后根据hash算法选择跳转到那一台. 以上是在使用了哨兵的情况下,本文不存在哨兵,只是集群,当master节点挂掉后,还是需要手动切换 推荐阅读:https://blog.csdn.net/qq_42815754/article/details/82912130 原文地址: