淘先锋技术网

首页 1 2 3 4 5 6 7

简介

RabbitMQ是由erlang语言开发,基于AMQP(Advanced Message Queue 高级消息队列协议)协议实现的消息队列,它是一种应用程序之间的通信方法,消息队列在分布式系统开发中应用非常广泛。RabbitMQ官方地址:http://www.rabbitmq.com

前期准备工作

[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环境。不过docker中,Erlang环境已经被docker自动安装,我们只需要简单几步操作即可完成RabbitMQ环境地安装+Web页面管理。

端口开放

如果在云服务上部署需在安全组开通一下端口:15672、5672、25672、61613、1883。

15672(UI页面通信口)、5672(client端通信口)、25672(server间内部通信口)、61613(stomp 消息传输)、1883(MQTT消息队列遥测传输)。

查询镜像

[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安装management

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页面

在这里插入图片描述

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