bob体育appRabbitMQ概念及环境搭建(三)RabbitMQ cluster

2019-12-14 03:09栏目:bob体育平台
TAG:

参谋链接:

测验情况:VMS00781 VMS00782 VMS00386 (centos5.8卡塔尔国
1.先在三台机器上各自安装RabbitMQ Server

一、前言
线上的 RabbitMQ用的是单节点,近来由于机械内部存款和储蓄器不足,发生了OOM,业务受到了震慑,故希图换成RabbitMQ集群。RabbitMQ形式有二种,分别是:单一情势、普通情势、镜像情势,镜像方式才是RabbitMQ真正的HA方案,关于更详实的简绍,请移步到官方网站: ,下边是有关RabbitMQ集群的构造进度:

 

2.读取中间二个节点的cookie,并复制到其余节点(节点间通过cookie显著相互是不是可通讯)
两方之生机勃勃均可:
sudo vim /var/lib/rabbitmq/.erlang.cookie
sudo vim $HOME/.erlang.cookie

二、环境
erlang版本:
erlang-19.0.4-1.el7.CentOS.x86_64

所有事手续和参照他事他说加以考察链接雷同。

3.各个运维节点
sudo service rabbitmq-server start

rabbitmq版本:
rabbitmq-server-3.6.6

 

4.查看各节点中的RabbitMQ brokers
bob体育平台,sudo rabbitmqctl cluster_status

服务器主机名:
ip-172-31-13-114  磁盘节点
ip-172-31-15-124 内部存款和储蓄器节点
ip-172-31-11-216 内部存款和储蓄器节点

前八部都寻常,在第九步会报错Error: unable to perform an operation on node 'rabbit1@ClusterNode1',具体如下图:

bob体育app,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

三、安装
1、erlang安装
a、wget
rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
b、rpm --import
c、Add the following lines to some file in /etc/yum.repos.d/:
[erlang-solutions]
name=Centos $releasever - $basearch - Erlang Solutions
baseurl=
gpgcheck=1
gpgkey=
enabled=1
d、yum install erlang esl-erlang

bob体育平台 1

6.排错
建集群进程中境遇如下错误:
sudo rabbitmqctl join_cluster --ram rabbit@VMS00386
Clustering node rabbit@VMS00782 with rabbit@VMS00386 ...
Error: unable to connect to nodes [rabbit@VMS00386]: nodedown

2、RabbitMQ 安装
a、 wget
b、tar -xvf rabbitmq-server-generic-unix-3.6.6.tar.xz
c、 mv rabbitmq_server-3.6.6 /data/rabbitmq
d、cd /data/rabbitmq/;./sbin/rabbitmq-server -detached

ping ClusterNode1结果符合规律:

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 ...

四、配置
1、必要布署host,不然集群没用艺术创设,小编这里用的aws的ec2,用的暗中认可主机名,这里就不变了
2、拷贝.erlang.cookie,RabbitMQ集群重视erlang集群能力专门的学问,所以需求先构建erlang集群,.erlang.cookie文件在起步客户的家目录下,笔者这里是用work客商运维的RabbitMQ,拷贝生机勃勃台服务器的/home/work/.erlang.cookie到任何机器并设置权限
chown work:work  /home/work/.erlang.cookie
chmod 400 /home/work/.erlang.cookie

bob体育平台 2

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实例,别的进程同多机器上配备集群相仿

别的注意事项:
如防火墙战略等

参考:

3、设置集群的形式:镜像
rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'

rabbitmqctl-ClusterNode1.bat运营命令基本都会报与stop_app相仿的错误。

PS:
在随机多少个节点操作就可以,这里在ip-172-31-13-114上操作
4、加入集群(ip-172-31-15-124 、ip-172-31-11-216 )
rabbitmqctl stop_app
rabbitmqctl join_cluster --ram rabbit@ip-172-31-13-114
rabbitmqctl start_app

 

PS:
--ram 钦定内部存款和储蓄器节点类型,--disc钦定磁盘节点类型

查网络erlang.cookie改革没用,因为五个erlang.cookie本来便是同风流浪漫的。查阅了汪洋有关材料后,他们的缓慢解决方案基本都不行。

5、查看集群
rabbitmqctl cluster_status

 

6、启用管理和监理模块
rabbitmq-plugins enable rabbitmq_management

再三检查后自个儿豁然开采HTTP端操作正常,正是不可能用rabbitmqctl-ClusterNode1.bat拓展操作。

7、设置集群的名字
rabbitmqctl set_cluster_name my_mq

版权声明:本文由bob体育app发布于bob体育平台,转载请注明出处:bob体育appRabbitMQ概念及环境搭建(三)RabbitMQ cluster