Docker安装RabbitMQ集群

一、安装单机版

1、更新yum源安装 vim、net-tools等工具

 yum update -y
 yum install vim -y
 yum install net-tools -y

2、安装单机版

#创建挂载路径
mkdir /data/rabbitmq -p


#拉取镜像
docker pull rabbitmq:3.9-management


#创建容器并启动
docker run  -d -it  --name rabbitmq \
-v /data/rabbitmq:/var/lib/rabbitmq \
-p 5672:5672 -p 15672:15672 rabbitmq:3.9-management

如果拉取镜像报错

解决方法修改dns解析

vim /etc/resolv.conf

#修改内容如下
#nameserver 192.168.139.2
nameserver 114.114.114.114
nameserver 8.8.8.8

二、安装集群

1、安装容器

#创建挂载目录
mkdir /data/rabbitmq1 -p
mkdir /data/rabbitmq2 -p
mkdir /data/rabbitmq3 -p

#节点1
docker run -d --hostname rabbit1 --name rabbitmq1 \
-p 15672:15672 -p 5672:5672 \
-v /data/rabbitmq1:/var/lib/rabbitmq \
-e RABBITMQ_ERLANG_COOKIE='rabbitmq_cookie' rabbitmq:3.9-management



#节点2
docker run -d --hostname rabbit2 --name rabbitmq2 \
-p 5673:5672 --link rabbitmq1:rabbit1 \
-v /data/rabbitmq2:/var/lib/rabbitmq \
-e RABBITMQ_ERLANG_COOKIE='rabbitmq_cookie' rabbitmq:3.9-management



#节点3
docker run -d --hostname rabbit3 --name rabbitmq3 \
-p 5674:5672 --link rabbitmq1:rabbit1 --link rabbitmq2:rabbit2 \
-v /data/rabbitmq3:/var/lib/rabbitmq \
-e RABBITMQ_ERLANG_COOKIE='rabbitmq_cookie' rabbitmq:3.9-management

2、添加节点

#节点1
[root@localhost data]# docker exec -it rabbitmq1 bash
root@rabbit1:/# rabbitmqctl stop_app
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead.
Stopping rabbit application on node rabbit@rabbit1 ...
root@rabbit1:/# rabbitmqctl reset
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead.
Resetting node rabbit@rabbit1 ...
root@rabbit1:/# rabbitmqctl start_app
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead.
Starting node rabbit@rabbit1 ...
root@rabbit1:/# 



#节点2
root@rabbit2:/# rabbitmqctl stop_app
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead.
Stopping rabbit application on node rabbit@rabbit2 ...
root@rabbit2:/# rabbitmqctl reset
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead.
Resetting node rabbit@rabbit2 ...
root@rabbit2:/# rabbitmqctl join_cluster --ram rabbit@rabbit1 
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead.
Clustering node rabbit@rabbit2 with rabbit@rabbit1
root@rabbit2:/# rabbitmqctl start_app
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead.
Starting node rabbit@rabbit2 ...


#节点3
[root@localhost data]# docker exec -it rabbitmq3 bash
root@rabbit3:/# rabbitmqctl stop_app
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead.
Stopping rabbit application on node rabbit@rabbit3 ...
root@rabbit3:/# rabbitmqctl reset
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead.
Resetting node rabbit@rabbit3 ...
root@rabbit3:/# rabbitmqctl join_cluster --ram rabbit@rabbit1
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead.
Clustering node rabbit@rabbit3 with rabbit@rabbit1

16:39:35.973 [warn]  Feature flags: the previous instance of this node must have failed to write the `feature_flags` file at `/var/lib/rabbitmq/mnesia/rabbit@rabbit3-feature_flags`:

16:39:35.973 [warn]  Feature flags:   - list of previously disabled feature flags now marked as such: [:maintenance_mode_status]

16:39:36.240 [error] Failed to create a tracked connection table for node :rabbit@rabbit3: {:node_not_running, :rabbit@rabbit3}

16:39:36.241 [error] Failed to create a per-vhost tracked connection table for node :rabbit@rabbit3: {:node_not_running, :rabbit@rabbit3}

16:39:36.241 [error] Failed to create a per-user tracked connection table for node :rabbit@rabbit3: {:node_not_running, :rabbit@rabbit3}
root@rabbit3:/# rabbitmqctl start_app
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead.
Starting node rabbit@rabbit3 ...
root@rabbit3:/# 

3、此时登录rabbitmq可视化平台

192.168.139.191:15672 默认账号密码是guest

Docker安装RabbitMQ集群_第1张图片

4、配置镜像集群模式

Docker安装RabbitMQ集群_第2张图片

name:随便取,策略名称
Pattern:^ 匹配符,只有一个^代表匹配所有
Definition:ha-mode=all 为匹配类型,分为3种模式:all(表示所有的queue)。

你可能感兴趣的:(MQ消息中间件,docker,rabbitmq,容器)