Docker 安装 RabbitMQ 教程

2023-02-19  本文已影响0人  木叶苍蓝

前期准备工作

[root@localhost ~]# sudo systemctl start docker
[root@localhost ~]# sudo systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2022-10-11 15:04:50 CST; 10s ago
     Docs: https://docs.docker.com
 Main PID: 16970 (dockerd)
    Tasks: 8
   Memory: 27.6M
   CGroup: /system.slice/docker.service
           └─16970 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

一般情况,需要先安装部署 Erlang 环境在安装 RabbitMQ 环境。不过 Erlange 环境已经被 docker 自动安装,我们只需要简单几步操作即可完成 RabbitMQ 安装。

开放端口

如果在云服务器上部署需要在安全组开通以下端口:15672,5672,25672,61613,1883

查询镜像

[root@localhost ~]# docker search rabbitmq
NAME                                                   DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
rabbitmq                                               RabbitMQ is an open source multi-protocol me…   4483      [OK]       
bitnami/rabbitmq                                       Bitnami Docker Image for RabbitMQ               90                   [OK]
nasqueron/rabbitmqadmin                                RabbitMQ management plugin CLI tool Lightwei…   1                    [OK]
bitnami/rabbitmq-exporter                                                                              1                    
rabbitmqoperator/cluster-operator                      The RabbitMQ Cluster Operator Docker Image      1                    
circleci/rabbitmq-delayed                              https://github.com/circleci/rabbitmq-delayed…   1                    
nasqueron/rabbitmq                                     RabbitMQ wth management, MQTT and STOMP plug…   0                    [OK]
itisfoundation/rabbitmq                                                                                0                    
clearlinux/rabbitmq                                    RabbitMQ multi-protocol messaging broker wit…   0                    
rapidfort/rabbitmq                                     RapidFort optimized, hardened image for Rabb…   0                    
corpusops/rabbitmq                                     https://github.com/corpusops/docker-images/     0                    
drud/rabbitmq                                          rabbitmq                                        0                    [OK]
bitnami/rabbitmq-cluster-operator                                                                      0                    
ibmcom/rabbitmq-exporter-ppc64le                                                                       0                    
newrelic/k8s-nri-rabbitmq                              New Relic Infrastructure RabbitMQ Integratio…   0                    
ibmcom/rabbitmq-java-client                                                                            0                    
ibmcom/rabbitmq-server-ppc64le                                                                         0                    
ibmcom/rabbitmq-java-client-ppc64le                                                                    0                    
circleci/rabbitmq                                      This image is for internal use                  0                    
rabbitmqoperator/cluster-operator-dev                                                                  0                    
rabbitmqoperator/messaging-topology-operator                                                           0                    
rabbitmqoperator/messaging-topology-operator-dev                                                       0                    
rabbitmqoperator/default-user-credential-updater-dev                                                   0                    
rabbitmqoperator/default-user-credential-updater                                                       0                    
rabbitmqoperator/single-active-consumer-operator-dev                                                   0                    
[root@localhost ~]# 

安装镜像

[root@localhost ~]# docker pull rabbitmq
Using default tag: latest
latest: Pulling from library/rabbitmq
fb0b3276a519: Pull complete 
4b7e2bc6e42d: Pull complete 
498446f27344: Pull complete 
b2df5a4d5834: Pull complete 
2dfb57eb3a37: Pull complete 
e62da47353ea: Pull complete 
cb81e266b02f: Pull complete 
a71f8bd3b746: Pull complete 
6126e39c0e78: Pull complete 
Digest: sha256:588974c4b11c390a702839cd065f746870c91c4a4d951b05a2a33f485e4bab4a
Status: Downloaded newer image for rabbitmq:latest
docker.io/library/rabbitmq:latest
[root@localhost ~]# 

启动 MQ

docker run -d --name rabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 -p 25672:25672 -p 61613:61613 -p 1883:1883 rabbitmq:management

参数说明:本条命令包括安装 Web 页面管理 rabbitmq:management 组件,账号和密码都是 admin,-p 后面参数表示公网 IP 地址的端口号对应容器内部的端口号。

[root@localhost ~]# docker run -d --name rabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 -p 25672:25672 -p 61613:61613 -p 1883:1883 rabbitmq:management
Unable to find image 'rabbitmq:management' locally
management: Pulling from library/rabbitmq
fb0b3276a519: Already exists 
4b7e2bc6e42d: Already exists 
498446f27344: Already exists 
b2df5a4d5834: Already exists 
2dfb57eb3a37: Already exists 
e62da47353ea: Already exists 
cb81e266b02f: Already exists 
a71f8bd3b746: Already exists 
6126e39c0e78: Already exists 
968223402a5e: Pull complete 
Digest: sha256:6faef1dac75d698b838a9b5b9b3319d2b01ddbf3bcdeaa05a6cf1cf8234b936a
Status: Downloaded newer image for rabbitmq:management
95fa9858292df2d46b299cebb69d72fe2c7ccd6e3d64c5f52104006f651bcb62
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS                                                                                                                                                                                                                                                                               NAMES
95fa9858292d   rabbitmq:management   "docker-entrypoint.s…"   4 minutes ago   Up 4 minutes   4369/tcp, 0.0.0.0:1883->1883/tcp, :::1883->1883/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 15671/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp, 0.0.0.0:25672->25672/tcp, :::25672->25672/tcp, 0.0.0.0:61613->61613/tcp, :::61613->61613/tcp, 15691-15692/tcp   rabbit

访问 RabbitMQ 的 Web 页面

77012a44013c46fd97ea0a6b17b91d72.png

RabbitMQ 默认账号和密码都是:guest ,默认情况只能在 localhost 访问,所以我们需要通过刚才创建的 admin 用户进行登录。输入 http://IP地址:15672 访问,账号密码都是 admin。

上一篇下一篇

猜你喜欢

热点阅读