Docker快速安装RabbitMQ服务

2023-11-06

 

Docker快速安装RabbitMQ服务

 

快速开始

#!/bin/bash
# 建议保存为start.sh脚本执行
docker run -d --hostname my-rabbit --name some-rabbit --restart always -p 15672:15672 -e RABBITMQ_DEFAULT_USER=user -e RABBITMQ_DEFAULT_PASS=password rabbitmq:3-management

PS: 第一次启动要下载rabbitmq镜像,请耐心等待,docker启动完毕后,访问 http:127.0.0.1:15672即可 

 

启动示例

MacdeMacBook-Pro:docker mac$ cd rabbitmq/
MacdeMacBook-Pro:rabbitmq mac$ ls
start.sh
MacdeMacBook-Pro:rabbitmq mac$ vim start.sh 
MacdeMacBook-Pro:rabbitmq mac$ ls
start.sh
MacdeMacBook-Pro:rabbitmq mac$ vim start_always.sh
MacdeMacBook-Pro:rabbitmq mac$ chmod +x start_always.sh 
MacdeMacBook-Pro:rabbitmq mac$ ./start_always.sh 
Unable to find image 'rabbitmq:3-management' locally
3-management: Pulling from library/rabbitmq
f17d81b4b692: Pull complete 
02fe1bd1a85c: Pull complete 
66c15a50f4da: Pull complete 
Digest: sha256:3eb2fa0f83914999846f831f14b900c0c85cea8e5d2db48ff73cf7defa12fe96
Status: Downloaded newer image for rabbitmq:3-management
ff89a5c3bd4f952816b660c9b10e1489332b68537a2c0efd748fa14cab6f460b
MacdeMacBook-Pro:rabbitmq mac$ docker ps
CONTAINER ID        IMAGE                               COMMAND                  CREATED             STATUS              PORTS                                                                                                                                                                    NAMES
ff89a5c3bd4f        rabbitmq:3-management               "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15673->15672/tcp                                                                                                  some-rabbit

 

Web页面

PS: 账户和密码是在start.sh的启动脚本中设置的 user/password

 

支持的tags和相关的Dockerfile

参考资料

RabbitMQ快速入门

RabbitMQ is open source message broker software (sometimes called message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP). The RabbitMQ server is written in the Erlang programming language and is built on the Open Telecom Platform framework for clustering and failover. Client libraries to interface with the broker are available for all major programming languages.

wikipedia.org/wiki/RabbitMQ

logo

 

如何使用RabbitMQ的Docker镜像

Running the daemon

One of the important things to note about RabbitMQ is that it stores data based on what it calls the "Node Name", which defaults to the hostname. What this means for usage in Docker is that we should specify -h/--hostnameexplicitly for each daemon so that we don't get a random hostname and can keep track of our data:

$ docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3

This will start a RabbitMQ container listening on the default port of 5672. If you give that a minute, then do docker logs some-rabbit, you'll see in the output a block similar to:

=INFO REPORT==== 6-Jul-2015::20:47:02 ===
node           : rabbit@my-rabbit
home dir       : /var/lib/rabbitmq
config file(s) : /etc/rabbitmq/rabbitmq.config
cookie hash    : UoNOcDhfxW9uoZ92wh6BjA==
log            : tty
sasl log       : tty
database dir   : /var/lib/rabbitmq/mnesia/rabbit@my-rabbit

Note the database dir there, especially that it has my "Node Name" appended to the end for the file storage. This image makes all of /var/lib/rabbitmq a volume by default.

Memory Limits

RabbitMQ contains functionality which explicitly tracks and manages memory usage, and thus needs to be made aware of cgroup-imposed limits.

The upstream configuration setting for this is vm_memory_high_watermark, and it is described under "Memory Alarms" in the documentation.

In this image, this value is set via RABBITMQ_VM_MEMORY_HIGH_WATERMARK. The value of this environment variable is interpreted as follows:

  • 0.49 is treated as 49%, just like upstream ({ vm_memory_high_watermark, 0.49 })
  • 56% is treated as 56% (0.56{ vm_memory_high_watermark, 0.56 })
  • 1073741824 is treated as an absolute number of bytes ({ vm_memory_high_watermark, { absolute, 1073741824 } })
  • 1024MiB is treated as an absolute number of bytes with a unit ({ vm_memory_high_watermark, { absolute, "1024MiB" } })

The main behavioral difference is in how percentages are handled. If the current container has a memory limit (--memory/-m), a percentage value will be calculated to an absolute byte value based on the memory limit, rather than being passed to RabbitMQ as-is. For example, a container run with --memory 2048m (and the implied upstream-default RABBITMQ_VM_MEMORY_HIGH_WATERMARK of 40%) will set the effective limit to 819MB (which is 40% of 2048MB).

See the RabbitMQ "Clustering Guide" for more information about cookies and why they're necessary.

For setting a consistent cookie (especially useful for clustering but also for remote/cross-container administration via rabbitmqctl), use RABBITMQ_ERLANG_COOKIE:

$ docker run -d --hostname my-rabbit --name some-rabbit -e RABBITMQ_ERLANG_COOKIE='secret cookie here' rabbitmq:3

This can then be used from a separate instance to connect:

$ docker run -it --rm --link some-rabbit:my-rabbit -e RABBITMQ_ERLANG_COOKIE='secret cookie here' rabbitmq:3 bash
root@f2a2d3d27c75:/# rabbitmqctl -n rabbit@my-rabbit list_users
Listing users ...
guest   [administrator]

Alternatively, one can also use RABBITMQ_NODENAME to make repeated rabbitmqctl invocations simpler:

$ docker run -it --rm --link some-rabbit:my-rabbit -e RABBITMQ_ERLANG_COOKIE='secret cookie here' -e RABBITMQ_NODENAME=rabbit@my-rabbit rabbitmq:3 bash
root@f2a2d3d27c75:/# rabbitmqctl list_users
Listing users ...
guest   [administrator]

If you wish to provide the cookie via a file (such as with Docker Secrets), it needs to be mounted at /var/lib/rabbitmq/.erlang.cookie:

docker service create ... --secret source=my-erlang-cookie,target=/var/lib/rabbitmq/.erlang.cookie ... rabbitmq

(Note that it will likely also be necessary to specify uid=XXX,gid=XXX,mode=0600 in order for Erlang in the container to be able to read the cookie file properly. See Docker's --secret documentation for more details.)

Management Plugin

There is a second set of tags provided with the management plugin installed and enabled by default, which is available on the standard management port of 15672, with the default username and password of guest / guest:

$ docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3-management

You can access it by visiting http://container-ip:15672 in a browser or, if you need access outside the host, on port 8080:

$ docker run -d --hostname my-rabbit --name some-rabbit -p 8080:15672 rabbitmq:3-management

You can then go to http://localhost:8080 or http://host-ip:8080 in a browser.

Environment Variables

A small selection of the possible environment variables are defined in the Dockerfile to be passed through the docker engine (listed below). For a list of environment variables supported by RabbitMQ itself, see: https://www.rabbitmq.com/configure.html

For SSL configuration without the management plugin:

RABBITMQ_SSL_CACERTFILE
RABBITMQ_SSL_CERTFILE
RABBITMQ_SSL_DEPTH
RABBITMQ_SSL_FAIL_IF_NO_PEER_CERT
RABBITMQ_SSL_KEYFILE
RABBITMQ_SSL_VERIFY

For SSL configuration using the management plugin:

RABBITMQ_MANAGEMENT_SSL_CACERTFILE
RABBITMQ_MANAGEMENT_SSL_CERTFILE
RABBITMQ_MANAGEMENT_SSL_DEPTH
RABBITMQ_MANAGEMENT_SSL_FAIL_IF_NO_PEER_CERT
RABBITMQ_MANAGEMENT_SSL_KEYFILE
RABBITMQ_MANAGEMENT_SSL_VERIFY

Setting default user and password

If you wish to change the default username and password of guest / guest, you can do so with the RABBITMQ_DEFAULT_USER and RABBITMQ_DEFAULT_PASS environmental variables:

$ docker run -d --hostname my-rabbit --name some-rabbit -e RABBITMQ_DEFAULT_USER=user -e RABBITMQ_DEFAULT_PASS=password rabbitmq:3-management

You can then go to http://localhost:8080 or http://host-ip:8080 in a browser and use user/passwordto gain access to the management console

To source the username and password from files instead of environment variables, add a _FILE suffix to the environment variable names (for example, RABBITMQ_DEFAULT_USER_FILE=/run/secrets/xxx to use Docker Secrets).

Setting default vhost

If you wish to change the default vhost, you can do so with the RABBITMQ_DEFAULT_VHOST environmental variables:

$ docker run -d --hostname my-rabbit --name some-rabbit -e RABBITMQ_DEFAULT_VHOST=my_vhost rabbitmq:3-management

Enabling HiPE

See the RabbitMQ "Configuration" for more information about various configuration options.

For enabling the HiPE compiler on startup use RABBITMQ_HIPE_COMPILE set to 1. Accroding to the official documentation:

Set to true to precompile parts of RabbitMQ with HiPE, a just-in-time compiler for Erlang. This will increase server throughput at the cost of increased startup time. You might see 20-50% better performance at the cost of a few minutes delay at startup.

It is therefore important to take that startup delay into consideration when configuring health checks, automated clustering etc.

Enabling Plugins

Creating a Dockerfile will have them enabled at runtime. To see the full list of plugins present on the image rabbitmq-plugins list

FROM rabbitmq:3.7-management
RUN rabbitmq-plugins enable --offline rabbitmq_mqtt rabbitmq_federation_management rabbitmq_stomp

You can also mount a file at /etc/rabbitmq/enabled_plugins with contents as an erlang list of atoms ending with a period.

Example enabled_plugins

[rabbitmq_federation_management,rabbitmq_management,rabbitmq_mqtt,rabbitmq_stomp].

Additional Configuration

If additional configuration is required, it is recommended to supply an appropriate /etc/rabbitmq/rabbitmq.conf file (see the "Configuration File(s)" section of the RabbitMQ documentation for more details), for example via bind-mount, Docker Configs, or a short Dockerfile with a COPY instruction.

Alternatively, it is possible to use the RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS environment variable, whose syntax is described in section 7.8 ("Configuring an Application") of the Erlang OTP Design Principles User's Guide (the appropriate value for -ApplName is -rabbit), this method requires a slightly different reproduction of its equivalent entry in rabbitmq.conf. For example, configuring channel_max would look something like -e RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS="-rabbit channel_max 4007". Where the space between the variable channel_max and its value 4007 correctly becomes a comma when translated in the environment.

Additional configuration keys would be specified as a list. For example, configuring both channel_max and auth_backends would look something like -e RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS="-rabbit channel_max 4007 auth_backends [rabbit_auth_backend_ldap,rabbit_auth_backend_internal]". Note that some variables such as for auth_backends require their value(s) to be enclosed in brackets, and for multiple values explicitly including the comma as a delimiter.

Connecting to the daemon

$ docker run --name some-app --link some-rabbit:rabbit -d application-that-uses-rabbitmq

Image Variants

The rabbitmq images come in many flavors, each designed for a specific use case.

rabbitmq:<version>

This is the defacto image. If you are unsure about what your needs are, you probably want to use this one. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of.

rabbitmq:<version>-alpine

This image is based on the popular Alpine Linux project, available in the alpine official image. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.

This variant is highly recommended when final image size being as small as possible is desired. The main caveat to note is that it does use musl libc instead of glibc and friends, so certain software might run into issues depending on the depth of their libc requirements. However, most software doesn't have an issue with this, so this variant is usually a very safe choice. See this Hacker News comment thread for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images.

To minimize image size, it's uncommon for additional related tools (such as git or bash) to be included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the alpine image description for examples of how to install packages if you are unfamiliar).

License

View license information for the software contained in this image.

As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).

Some additional license information which was able to be auto-detected might be found in the repo-inforepository's rabbitmq/ directory.

As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.

 

转载来源:Docker官网

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Docker快速安装RabbitMQ服务 的相关文章

  • 使用Camel的spring-rabbitmq组件时如何自动声明交换?

    我正在尝试从 Camel 3 x 迁移到 Camel 4 x 版本 因此我需要从rabbitmq替换组件spring rabbitmq With rabbitmq我正在使用的组件declare https camel apache org
  • RabbitMQ C# API:如何检查绑定是否存在?

    使用 RabbitMQ C API 我如何检查给定队列到给定交换是否存在绑定 很多 RabbitMQ 调用都是幂等的 所以有些人可能会说在这些情况下检查是不必要的 但我认为它们在测试中很有用 您可以使用他们的 REST API 来调用并查看
  • 无法从 docker 将 RabbitMQ 连接到我的应用程序 [重复]

    这个问题在这里已经有答案了 我目前被这个问题困扰了大约一周 确实找不到合适的解决方案 问题是 当我尝试连接到 dockerized RabbitMQ 时 它每次都会给出相同的错误 wordofthedayapp wordofthedayap
  • Celery 与rabbitmq 创建结果多个队列

    我已经用 RabbitMQ 安装了 Celery 问题是 对于返回的每个结果 Celery 都会在 Rabbit 中创建队列 并在交换 celeryresults 中使用任务 ID 我仍然想得到结果 但在一个队列上 我的芹菜配置 from
  • RabbitMQ 管理插件窗口呈现为空白页面

    I have installed Erlang RabbitMQ and configured the management plugin as per the instructions on the website https www r
  • RabbitMQ:如何创建和恢复备份

    我是 RabbitMQ 的新手 我需要一些帮助 如何备份和恢复到RabbitMQ 以及我需要保存哪些重要数据 谢谢 如果您安装了管理插件 您可以在Overview页 在底部你会看到导入 导出定义您可以使用它来下载代理的 JSON 表示形式
  • 面向服务的架构 - AMQP 或 HTTP

    一点背景 非常大的整体 Django 应用程序 所有组件都使用相同的数据库 我们需要分离服务 以便我们可以独立升级系统的某些部分而不影响其余部分 我们使用 RabbitMQ 作为 Celery 的代理 现在我们有两个选择 使用 REST 接
  • RabbitMQ - 无法联系统计数据库。消息速率和队列长度将不会显示

    我已经设置了一个兔子经纪人集群 并且在管理门户插件中我收到以下消息 无法联系统计数据库 消息速率和队列长度将不会显示 我已经搜索过这个错误 但谷歌并不友善 任何人都可以阐明这一点吗 我最近在旧安装的RabbitMQ 2 8 7 上遇到了同样
  • rabbitmq 的 REST API

    有没有办法从 ajax 向 RabbitMQ 发送数据 我的应用程序由数千个 Web 客户端 用 js 编写 和 WCF REST 服务组成 现在我试图弄清楚如何为我的应用程序创建可扩展点 这个想法是有一个rabbitmq实例 它从放置在一
  • 如何使用 Java 在 RabbitMQ 中实现标头交换?

    我是一个新手 试图在java客户端中实现标头交换 我知道这就是 x match 绑定参数的用途 当 x match 参数设置为 any 时 只需一个匹配的标头值就足够了 或者 将 x match 设置为 all 强制所有值必须匹配 但任何人
  • 从 RabbitMQ 迁移到 Amazon SQS [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 我们的初创公司目前正在使用RabbitMQ with Python Django 对于消息队列 现在我们计划转移到Amazon SQS其高可用性
  • RabbitMQ 中的 celeryev 队列变得非常大

    我在rabbitmq上使用celery 我已经向队列发送了数千条消息 它们正在成功处理 一切正常 然而 几个rabbitmq队列中的消息数量增长得相当大 队列中有数十万个项目 队列被命名为celeryev 见下面的截图 这是适当的行为吗 这
  • Celery 广播 vs RabbitMQ 扇出

    我最近一直在使用 Celery 但我不喜欢它 它的配置很混乱 过于复杂并且文档记录很少 我想用 Celery 从单个生产者向多个消费者发送广播消息 让我困惑的是 Celery 术语和底层传输 RabbitMQ 术语之间的差异 在 Rabbi
  • RabbitMQ 中 Pub/Sub 与工作队列的混合

    我正在评估使用 RabbitMQ 作为消息队列 消息总线 并一直在查看示例教程 https www rabbitmq com getstarted html在 RabbitMQ 页面上 我正在寻找教程中未涵盖的特定场景 并且我不确定是否以及
  • celery任务eta已关闭,使用rabbitmq

    我使用教程中的默认设置和在 ubuntu 上运行的rabbitmq 使 Celery 任务正常进行 当我毫不延迟地安排任务时 一切都很好 但是当我给他们一个预计时间时 他们会被安排在未来 就好像我的时钟在某个地方关闭了一样 下面是一些请求任
  • 启动时加载 RabbitMQ 配置

    如何在启动时加载 RabbitMQ 配置以确认已创建代理对象 队列 交换 绑定 用户 虚拟主机 权限和参数 根据 RabbitMQ 文档 可以通过以下方式完成load definitions http www rabbitmq com ma
  • RabbitMQ HTTP API 请求 401 未经授权

    我正在尝试访问 RabbitMQ Rest 但收到 401 未经授权的错误 我想访问队列信息并获取消息编号 我发现这是一个解决方案 DefaultHttpClient httpClient new DefaultHttpClient Htt
  • 具有重新排队功能的 BasicReject 实际上去了哪里?

    这似乎是一个简单的问题 但我很难找到明确的答案 如果在 RabbitMQ 3 6 1 中我有一个如下所示的队列 5 4 3 2 1 lt head 我使用消息 1 然后执行以下操作 channel BasicReject ea Delive
  • 使用 Spring Boot 的多个 Rabbitmq 队列

    来自 Spring Boot 教程 https spring io guides gs messaging rabbitmq https spring io guides gs messaging rabbitmq 他们给出了创建 1 个队
  • 如何让Spring RabbitMQ创建一个新的队列?

    根据我对rabbit mq的 有限 经验 如果您为尚不存在的队列创建新的侦听器 则会自动创建该队列 我正在尝试将 Spring AMQP 项目与rabbit mq 一起使用来设置侦听器 但出现错误 这是我的 xml 配置

随机推荐

  • osgEarth的Rex引擎原理分析(四十六)如何定制椭球体并进行椭球体间坐标转换

    目标 目标 四十五 中的108 可以用于CGCS2000和WGS84的坐标转换 osg EllipsoidModel默认创建wgs84椭球体 将CGCS2000和WGS84的经纬高坐标分别转换为XYZ 然后比较其差值 osg Coordin
  • 重装mac显示未能恢复服务器取得联系,mac重开电脑后显示重装提示解决办法

    nodejs定义函数的方法 test 163 home exenode part3 module exports more calc js module exports sum function var r hdu 1789 Doing H
  • auto类型推导

    auto的作用 auto是我在编码中经常使用到的C 11新特性之一 主要用于变量的自动类型推导 如auto num 3 则推导出num的类型为int32 t auto的优势 相较于原始的显式类型去声明变量类型 auto的优势有以下几点 au
  • java全局异常捕获处理

    description TODO Author Administrator Date 2021 3 29 Version 1 0 ControllerAdvice public class YjzdyExceptionHandler Exc
  • Windows10电脑文件自动同步备份工具有哪些?

    对于工作中的重要数据人们一般都会有备份的习惯 但是如果都是人工手动复制粘贴 那效率会非常低下 Windows10中电脑文件自动同步备份工作有哪些 工具1 FileYee 推荐值 软件优势 可同百度网盘 移动硬盘实现自动同步备份 功能说明 F
  • 浏览器同源策略

    什么是同源 如果两个 URL 的协议 protocol 端口 port 域名 host 都相同的话 则这两个 URL 是同源的 下表给出了与 URL http store company com dir page html 的源进行对比的示
  • 11.python解答2020年蓝桥杯省赛python组 寻找2020

    11 python解答2020年蓝桥杯省赛python组 寻找2020 问题描述 小蓝有一个数字矩阵 里面只包含数字 0 和 2 小蓝很喜欢 2020 他想找到这个数字矩阵中有多少个 2020 小蓝只关注三种构成 2020 的方式 同一行里
  • 爬虫逆向实战(34)-某视综数据(MD5、AES)

    一 数据接口分析 主页地址 某视综 1 抓包 通过抓包可以发现数据接口是 rank waiting fans 2 判断是否有加密参数 请求参数是否加密 通过查看 载荷 模块可以发现有一个sign参数 请求头是否加密 无 响应是否加密 通过查
  • C语言,实现字符串排序

    实现字符串排序 include
  • leaftlet 点击事件与取消事件

    var layerNear var mapClick function map on click getRange var getRange function e e latlng地图上点击的点 layerNear L marker e l
  • js 数组遍历的几种方式

    js数组 表示的是有序的数据集合 是一种特殊的对象 对象是无序的数据结合 for循环 for in for each for of es6中数组实例的keys values entries map everyvery等函数 1 for循环
  • [Pyhon大数据分析] 二.PyEcharts绘制全国各地区、某省各城市地图及可视化分析

    思来想去 虽然很忙 但还是挤时间针对这次YQ写个Python大数据分析系列博客 包括网络爬虫 可视化分析 GIS地图显示 情感分析 舆情分析 主题挖掘 威胁情报溯源 知识图谱 预测预警及AI和NLP应用等 希望该系列线上远程教学对您有所帮助
  • win下C++通过Clion部署yolov5——libtorch+yolov5

    libtorch yolov5 一 环境配置 二 下载官网例子 三 测试 3 1 创建项目 3 2 cmakelist txt编写 3 3 运行测试 一 环境配置 需要配置libtorch OpenCV 此处参考博文 clion配置libt
  • 3D扫描技术概览

    3D扫描技术概览 复制链接 楼主 eseedo 发表于 2016 11 22 17 14 26 408 0 只看该作者 内容概要 1 使
  • 黑马程序员 JAVA学习笔记 ——— 多线程

    android培训 java培训 期待与您交流 首先 先介绍一下 熟悉的进程 按下 ctrl alt del就可以看到进程这一选项卡 进程是一个正在执行中的程序 每个进程执行都有一个执行顺序 该顺序是一个执行路径 或叫做一个控制单元 而今天
  • Scala基础语法之Trait详解

    Scala系列学习笔记 Scala概述与开发环境配置 Scala基础学习之运算符 Scala基础学习之for循环和while循环 一文掌握scala中的方法和函数 Scala基础 类和对象 访问修饰符和构造器 Scala的继承和抽象类 本章
  • database Derby initial

    surf the site http db apache org derby derby downloads html you ll get more but first is download the lastest Derby derb
  • Linux 网络通讯 : smbd 命令详解

    smbd命令用于Samba服务器程序 smbd为Samba服务器程序 可分享文件与打印机等网络资源供Windows相关的用户端程序存取 语法 1 smbd aDhoP d lt 排错层级 gt i lt 范围 gt l lt 记录文件 gt
  • FPGA(三)——基于FPGA的SPI通讯协议实现

    一 SPI通讯基本原理 1 SPI通讯介绍 SPI Serial Perripheral Interface 串行外围设备接口 是 Motorola 公司推出的一种同步串行接口技术 SPI 总线在物理上是通过接在外围设备微控制器 PICmi
  • Docker快速安装RabbitMQ服务

    Docker快速安装RabbitMQ服务 快速开始 bin bash 建议保存为start sh脚本执行 docker run d hostname my rabbit name some rabbit restart always p 1