云原生之Docker实战使用Docker部署Rabbitmq集群
Posted 江湖有缘
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了云原生之Docker实战使用Docker部署Rabbitmq集群相关的知识,希望对你有一定的参考价值。
【云原生之Docker实战】使用Docker部署Rabbitmq集群
- 一、Rabbitmq介绍
- 二、检查本地dokcer状态
- 三、创建容器前准备工作
- 四、创建第一个rabbitmq容器
- 五、再次创建二个rabbitmq容器
- 六、将rabbitmq容器加入到集群中
- 七、查看rabbitmq集群状态
- 八、进入rabbitmq的web控制台
- 九、用户配置
- 十、在其余节点查看新建用户
一、Rabbitmq介绍
1.Rabbitmq简介
RabbitMQ 是基于 AMQP 实现的一个开源消息组件,主要用于在分布式系统中存储转发消息,由因高性能、高可用以及高扩展而出名的 Erlang 语言写成。
2.Rabbitmq特点
1、高可靠性(Reliability):RabbitMQ 提供了多种多样的特性让你在可靠性和性能之间做出权衡,包括持久化、发送应答、发布确认以及高可用性。
2、高可用队列:支持跨机器集群,支持队列安全镜像备份,消息的生产者与消费者不论哪一方出现问题,均不会影响消息的正常发出与接收。
3、支持消息集群(Clustering):多台RabbitMQ服务器可以组成一个集群,形成一个逻辑Broker。
4、具有高可用性(Highly Available):队列可以在集群中的机器进行镜像,在部分节点出现问题的情况下队列仍然可用。
5、灵活的路由功能(Flexible Routing)所有的消息都会通过路由器转发到各个消息队列中,RabbitMQ 内建了几个常用的路由器,并且可以通过路由器的组合以及自定义路由器插件来完成复杂的路由功能。
6、支持多种协议(Multi-protocol):RabbitMQ除了支持AMQP协议之外,还通过插件方式支持其它消息队列协议,比如STOMP、MQTT等。
7、支持多语言客户端(Many Client):几乎支持所有常用的语言。
8、提供管理界面(Management UI):RabbitMQ提供了一个简单的用户页面,用户可以监控和管理消息。
9、提供跟踪机制(Tracing):RabbitMQ提供了消息跟踪机制,如果消息异常,使用者可以查出发生了什么情况。
10、提供插件机制(Plugin System):RabbitMQ提供了许多插件,从多方面进行扩展,也可以自己编写自己的插件。
3.Rabbitmq的工作机制
二、检查本地dokcer状态
1.检查docker版本
[root@compute-node1 ~]# docker version
Client: Docker Engine - Community
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:05:12 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.6
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 8728dd2
Built: Fri Apr 9 22:43:57 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.6
GitCommit: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc:
Version: 1.1.2
GitCommit: v1.1.2-0-ga916309
docker-init:
Version: 0.19.0
GitCommit: de40ad0
2.查看docker状态
[root@compute-node1 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2022-07-12 09:07:34 CST; 1h 41min ago
Docs: https://docs.docker.com
Main PID: 12046 (dockerd)
Tasks: 11
Memory: 161.9M
CGroup: /system.slice/docker.service
└─12046 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Jul 12 09:07:28 compute-node1 dockerd[12046]: time="2022-07-12T09:07:28.893101144+08:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
Jul 12 09:07:33 compute-node1 dockerd[12046]: time="2022-07-12T09:07:33.092257268+08:00" level=info msg="Loading containers: start."
Jul 12 09:07:34 compute-node1 dockerd[12046]: time="2022-07-12T09:07:34.132643735+08:00" level=info msg="Removing stale sandbox 2a7df4c5f3cc80d6c5fa091ea2d69be44259...fc76af2a6)"
Jul 12 09:07:34 compute-node1 dockerd[12046]: time="2022-07-12T09:07:34.148138951+08:00" level=warning msg="Error (Unable to complete atomic operation, key modified...trying...."
Jul 12 09:07:34 compute-node1 dockerd[12046]: time="2022-07-12T09:07:34.184851297+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172...IP address"
Jul 12 09:07:34 compute-node1 dockerd[12046]: time="2022-07-12T09:07:34.217505045+08:00" level=info msg="Loading containers: done."
Jul 12 09:07:34 compute-node1 dockerd[12046]: time="2022-07-12T09:07:34.699636232+08:00" level=info msg="Docker daemon" commit=8728dd2 graphdriver(s)=overlay2 version=20.10.6
Jul 12 09:07:34 compute-node1 dockerd[12046]: time="2022-07-12T09:07:34.700192614+08:00" level=info msg="Daemon has completed initialization"
Jul 12 09:07:34 compute-node1 systemd[1]: Started Docker Application Container Engine.
Jul 12 09:07:34 compute-node1 dockerd[12046]: time="2022-07-12T09:07:34.778511250+08:00" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.
3.查看docker信息
[root@compute-node1 ~]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
scan: Docker Scan (Docker Inc., v0.17.0)
Server:
Containers: 3
Running: 1
Paused: 0
Stopped: 2
Images: 19
Server Version: 20.10.6
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3a`在这里插入代码片`e1
runc version: v1.1.2-0-ga916309
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-957.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.683GiB
Name: compute-node1
ID: PXGZ:S5WT:B7SN:MY4Q:WRXG:3UUC:7Z67:HF2O:PTCY:DUDH:6Q2C:JO3Q
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://sp4mg57h.mirror.aliyuncs.com/
Live Restore Enabled: false
三、创建容器前准备工作
1.创建数据卷
[root@compute-node1 ~]# docker volume create rabbit_vol
rabbit_vol
2.创建网络
[root@compute-node1 ~]# docker network create rabbit_cluster
17381e371e801206e17dffdcb41e34dca09b1a0dd372444a326835cc04bd1d18
3.查看网络
[root@compute-node1 ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
786395250feb bridge bridge local
d0143498efb1 host host local
76f3e56b6201 none null local
17381e371e80 rabbit_cluster bridge local
四、创建第一个rabbitmq容器
1.拉取rabbitmq镜像
docker pull rabbitmq:3-management
2.创建rabbitmq容器
docker run -d --name rabbitmq01 --hostname node1 --network rabbit_cluster -v rabbit_vol:/var/lib/rabbitmq -p 5672:5672 -p 15672:15672 -e RABBITMQ_NODENAME=r1 rabbitmq:3-management
3.查看容器
[root@compute-node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b203b32d1bd7 rabbitmq:3-management "docker-entrypoint.s…" 53 seconds ago Up 51 seconds 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp rabbitmq01
五、再次创建二个rabbitmq容器
1.创建第二个rabbitmq容器
docker run -d --name rabbitmq02 --hostname node2 --network rabbit_cluster -v rabbit_vol:/var/lib/rabbitmq -p 5673:5672 -p 15673:15672 -e RABBITMQ_NODENAME=r2 rabbitmq:3-management
2.创建第三个rabbitmq容器
docker run -d --name rabbitmq03 --hostname node3 --network rabbit_cluster -v rabbit_vol:/var/lib/rabbitmq -p 5674:5672 -p 15674:15672 -e RABBITMQ_NODENAME=r3 rabbitmq:3-management
3.查看所有rabbitmq容器
[root@compute-node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6305168845f3 rabbitmq:3-management "docker-entrypoint.s…" 12 seconds ago Up 10 seconds 4369/tcp, 5671/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:5674->5672/tcp, :::5674->5672/tcp, 0.0.0.0:15674->15672/tcp, :::15674->15672/tcp rabbitmq03
f5ae9fe7b9f7 rabbitmq:3-management "docker-entrypoint.s…" 22 seconds ago Up 21 seconds 4369/tcp, 5671/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:5673->5672/tcp, :::5673->5672/tcp, 0.0.0.0:15673->15672/tcp, :::15673->15672/tcp rabbitmq02
d01c54133857 rabbitmq:3-management "docker-entrypoint.s…" About a minute ago Up 58 seconds 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp rabbitmq01
六、将rabbitmq容器加入到集群中
1.节点1配置
①.进入rabbitmq容器
[root@compute-node1 ~]# docker exec -it rabbitmq01 /bin/bash
root@node1:/#
②.初始化rabbitmq
root@node1:/# rabbitmqctl stop_app
Stopping rabbit application on node r1@node1 ...
root@node1:/# rabbitmqctl reset
Resetting node r1@node1 ...
root@node1:/# rabbitmqctl start_app
Starting node r1@node1 ...
root@node1:/#
2.节点2配置
[root@compute-node1 ~]# docker exec -it rabbitmq02 /bin/bash
root@node2:/# rabbitmqctl stop_app
Stopping rabbit application on node r2@node2 ...
root@node2:/# rabbitmqctl reset
Resetting node r2@node2 ...
root@node2:/# rabbitmqctl join_cluster --ram r1@node1
Clustering node r2@node2 with r1@node1
03:45:15.689 [warn] Feature flags: the previous instance of this node must have failed to write the `feature_flags` file at `/var/lib/rabbitmq/mnesia/r2@node2-feature_flags`:
03:45:15.689 [warn] Feature flags: - list of previously disabled feature flags now marked as such: [:maintenance_mode_status]
03:45:15.848 [error] Failed to create a tracked connection table for node :r2@node2: :node_not_running, :r2@node2
03:45:15.848 [error] Failed to create a per-vhost tracked connection table for node :r2@node2: :node_not_running, :r2@node2
03:45:15.849 [error] Failed to create a per-user tracked connection table for node :r2@node2: :node_not_running, :r2@node2
root@node2:/# rabbitmqctl start_app
Starting node r2@node2 ...
root@node2:/#
3.节点3配置
[root@compute-node1 ~]# docker exec -it rabbitmq03 /bin/bash
root@node3:/# rabbitmqctl stop_app
Stopping rabbit application on node r3@node3 ...
root@node3:/# rabbitmqctl reset
Resetting node r3@node3 ...
root@node3:/# rabbitmqctl join_cluster --ram r1@node1
Clustering node r3@node3 with r1@node1
03:48:14.827 [warn] Feature flags: the previous instance of this node must have failed to write the `feature_flags` file at `/var/lib/rabbitmq/mnesia/r3@node3-feature_flags`:
03:48:14.827 [warn] Feature flags: - list of previously disabled feature flags now marked as such: [:maintenance_mode_status]
03:48:14.980 [error] Failed to create a tracked connection table for node :r3@node3: :node_not_running, :r3@node3
03:48:14.980 [error] Failed to create a per-vhost tracked connection table for node :r3@node3: :node_not_running, :r3@node3
03:48:14.980 [error] Failed to create a per-user tracked connection table for node :r3@node3: :node_not_running, :r3@node3
root@node3:/# rabbitmqctl start_app
Starting node r3@node3 ...
root@node3:/#
七、查看rabbitmq集群状态
[root@compute-node1 ~]# docker exec -it rabbitmq03 /bin/bash
root@node3:/# rabbitmqctl cluster_status
Cluster status of node r3@node3 ...
Basics
Cluster name: r3@node3
Disk Nodes
r1@node1
RAM Nodes
r2@node2
r3@node3
Running Nodes
r1@node1
r2@node2
r3@node3
Versions
r1@node1: RabbitMQ 3.9.11 on Erlang 24.2
r2@node2: RabbitMQ 3.9.11 on Erlang 24.2
r3@node3: RabbitMQ 3.9.11 on Erlang 24.2
Maintenance status
Node: r1@node1, status: not under maintenance
Node: r2@node2, status: not under maintenance
Node: r3@node3, status: not under maintenance
Alarms
(none)
Network Partitions
(none)
Listeners
Node: r1@node1, interface: [::], port: 15672, protocol: http, purpose: HTTP API
Node: r1@node1, interface: [::], port: 15692, protocol: http/prometheus, purpose: Prometheus exporter API over HTTP
Node: r1@node1, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Node: r1@node1, interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
Node: r2@node2, interface: [::], port: 15672, protocol: http, purpose: HTTP API
Node: r2@node2, interface: [::], port: 15692, protocol: http/prometheus, purpose: Prometheus exporter API over HTTP
Node: r2@node2, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Node: r2@node2, interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
Node: r3@node3, interface: [::], port: 15672, protocol: http, purpose: HTTP API
Node: r3@node3, interface: [::], port: 15692, protocol: http/prometheus, purpose: Prometheus exporter API over HTTP
Node: r3@node3, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Node: r3@node3, interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
Feature flags
Flag: drop_unroutable_metric, state: enabled
Flag: empty_basic_get_metric, state: enabled
Flag: implicit_default_bindings, state: enabled
Flag: maintenance_mode_status, state: enabled
Flag: quorum_queue, state: enabled
Flag: stream_queue, state: enabled
Flag: user_limits, state: enabled
Flag: virtual_host_metadata, state: enabled
云原生之Docker实战使用Docker部署Cloudreve公有云文件系统
云原生之Docker实战使用docker部署Ghost个人博客系统
云原生之Docker实战使用Docker部署jpress开源网站
云原生之Docker实战使用Docker部署speedtest测速平台