使用 Cloudsmith Apt 仓库安装

RabbitMQ 团队在 Cloudsmith 上维护两个apt 存储库,这是一个包托管服务。他们为最新的 RabbitMQ 和现代 Erlang 版本提供包。

Cloudsmith 提供存储库设置说明,其中包括方便的单行代码:

  • 对于现代 Erlang 存储库
  • 对于RabbitMQ 存储库

请始终检查从 Internet 下载并通过特权 shell 执行的脚本!

本指南将重点介绍一种更传统、更明确的方式来设置额外的 apt 存储库和安装包。

除非另有说明,否则下面涵盖的所有步骤都是强制性的。

Cloudsmith 快速启动脚本

下面是执行这些步骤的 shell 片段。在Shell脚本后是对脚本执行步骤的说明。

#!/usr/bin/sh

sudo apt-get install curl gnupg apt-transport-https -y

## Team RabbitMQ's main signing key
curl -1sLf "https://keys.openpgp.org/vks/v1/by-fingerprint/0A9AF2115F4687BD29803A206B73A36E6026DFCA" | sudo gpg --dearmor | sudo tee /usr/share/keyrings/com.rabbitmq.team.gpg > /dev/null
## Cloudsmith: modern Erlang repository
curl -1sLf https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/io.cloudsmith.rabbitmq.E495BB49CC4BBE5B.gpg > /dev/null
## Cloudsmith: RabbitMQ repository
curl -1sLf https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/gpg.9F4587F226208342.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/io.cloudsmith.rabbitmq.9F4587F226208342.gpg > /dev/null

## Add apt repositories maintained by Team RabbitMQ
sudo tee /etc/apt/sources.list.d/rabbitmq.list <<EOF
## Provides modern Erlang/OTP releases
##
deb [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.E495BB49CC4BBE5B.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/deb/ubuntu bionic main
deb-src [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.E495BB49CC4BBE5B.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/deb/ubuntu bionic main

## Provides RabbitMQ
##
deb [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.9F4587F226208342.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/deb/ubuntu bionic main
deb-src [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.9F4587F226208342.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/deb/ubuntu bionic main
EOF

## Update package indices
sudo apt-get update -y

## Install Erlang packages
sudo apt-get install -y erlang-base \
                        erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \
                        erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \
                        erlang-runtime-tools erlang-snmp erlang-ssl \
                        erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl

## Install rabbitmq-server and its dependencies
sudo apt-get install rabbitmq-server -y --fix-missing

以下是对上面shell脚本的详细说明。除非另有说明,否则下面涵盖的所有步骤都是强制性的。

Step 1:安装基本依赖项
sudo apt-get update -y

sudo apt-get install curl gnupg -y
Step 2:启用 apt HTTPS 传输

为了 apt 能够从 PackageCloudCloudsmith.ioLaunchpad 等服务下载 RabbitMQ 和 Erlang 包,必须安装apt-transport-https包:

sudo apt-get install apt-transport-https
Step 3:添加存储库签名密钥

Cloudsmith 使用自己的 GPG 密钥对分布式包进行签名,每个存储库一个。

为了使用存储库,必须将其签名密钥添加到系统中。这将使易于信任由该密钥签名的包。

sudo apt-get install curl gnupg apt-transport-https -y

## Team RabbitMQ's main signing key
curl -1sLf "https://keys.openpgp.org/vks/v1/by-fingerprint/0A9AF2115F4687BD29803A206B73A36E6026DFCA" | sudo gpg --dearmor | sudo tee /usr/share/keyrings/com.rabbitmq.team.gpg > /dev/null
## Cloudsmith: modern Erlang repository
curl -1sLf https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/io.cloudsmith.rabbitmq.E495BB49CC4BBE5B.gpg > /dev/null
## Cloudsmith: RabbitMQ repository
curl -1sLf https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/gpg.9F4587F226208342.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/io.cloudsmith.rabbitmq.9F4587F226208342.gpg > /dev/null

请参阅签名指南以了解更多信息。

Step 4:添加源列表文件

与所有第 3 方 apt 存储库一样,描述 RabbitMQ 和 Erlang 包存储库的文件必须放在/etc/apt/sources.list.d/目录下。 /etc/apt/sources.list.d/rabbitmq.list是推荐的位置。

该文件应该有一个使用以下模式的源(存储库)定义行:

## Provides modern Erlang/OTP releases
##
## Replace $distribution with the name of the Ubuntu release used.
## On Debian, "deb/ubuntu" should be replaced with "deb/debian"
deb [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.E495BB49CC4BBE5B.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/deb/ubuntu $distribution main
deb-src [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.E495BB49CC4BBE5B.gpg]  https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/deb/ubuntu $distribution main

## Provides RabbitMQ
##
## Replace $distribution with the name of the Ubuntu release used.
## On Debian, "deb/ubuntu" should be replaced with "deb/debian"
deb [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.9F4587F226208342.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/deb/ubuntu $distribution main
deb-src [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.9F4587F226208342.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/deb/ubuntu $distribution main

接下来的几节讨论支持哪些分布和组件值。

分发

为了设置一个提供正确包的 apt 存储库,必须做出一些决定。一是确定发行版名称。它通常与使用的 Debian 或 Ubuntu 版本相匹配:

  • jammy for Ubuntu 22.04
  • focal for Ubuntu 20.04
  • bionic for Ubuntu 18.04
  • buster for Debian Buster

并非所有发行版都被涵盖(索引)。例如,新发布的通常不会被包托管服务识别。但也有好消息:由于为这些发行版编制索引的包是相同的,因此在实践中,任何合理的最新发行版名称都足够了。例如,Debian Sid 或 Debian Bullseye 的用户都可以使用bullseye作为发行版名称。

下面是应该与 PackageCloud 上的 RabbitMQ apt 存储库一起使用的操作系统版本和分发名称的表格。

发行版本 分发
Ubuntu 22.04 jammy
Ubuntu 20.04 focal
Ubuntu 18.04 bionic
Debian Buster buster
Debian Bullseye bullseye
Debian Sid bullseye

要将 apt 存储库添加到源列表目录 ( /etc/apt/sources.list.d ),请使用:

sudo tee /etc/apt/sources.list.d/rabbitmq.list <<EOF
## Provides modern Erlang/OTP releases
##
## Replace $distribution with the name of the Ubuntu release used.
## On Debian, "deb/ubuntu" should be replaced with "deb/debian"
deb [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.E495BB49CC4BBE5B.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/deb/ubuntu $distribution main
deb-src [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.E495BB49CC4BBE5B.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/deb/ubuntu $distribution main

## Provides RabbitMQ
##
## Replace $distribution with the name of the Ubuntu release used.
## On Debian, "deb/ubuntu" should be replaced with "deb/debian"
deb [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.9F4587F226208342.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/deb/ubuntu $distribution main
deb-src [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.9F4587F226208342.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/deb/ubuntu $distribution main
EOF

其中$distribution是使用的 Debian 或 Ubuntu 发行版的名称(参见上表)。

例如,在 Debian Buster 上它将是

sudo tee /etc/apt/sources.list.d/rabbitmq.list <<EOF
## Provides modern Erlang/OTP releases
##
deb [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.E495BB49CC4BBE5B.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/deb/debian buster main
deb-src [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.E495BB49CC4BBE5B.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/deb/debian buster main

## Provides RabbitMQ
##
deb [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.9F4587F226208342.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/deb/debian buster main
deb-src [signed-by=/usr/share/keyrings/io.cloudsmith.rabbitmq.9F4587F226208342.gpg] https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/deb/debian buster main
EOF
Step 5:安装包

更新apt源列表后,有必要运行apt-get update

sudo apt-get update -y
## Install Erlang packages
sudo apt-get install -y erlang-base \
                        erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \
                        erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \
                        erlang-runtime-tools erlang-snmp erlang-ssl \
                        erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl

## Install rabbitmq-server and its dependencies
sudo apt-get install rabbitmq-server -y --fix-missing
Debian 软件包版本和存储库固定

版本固定是一个可选步骤。如果不使用,apt将安装可用的最新版本。

当同一包(例如erlang-base)可从多个 apt 存储库获得时,操作员需要有一种方法来指示应该首选哪个存储库。可能还需要限制 Erlang 版本以避免不需要的升级。 apt 包固定功能可用于解决这两个问题。

包固定配置有一个放在/etc/apt/preferences.d/目录下的文件,例如/etc/apt/preferences.d/erlang。更新 apt 首选项后,有必要运行apt-get update

sudo apt-get update -y

以下首选项文件示例将配置 apt 从 Cloudsmith.io安装erlang-*包,而不是标准的 Debian 或 Ubuntu 存储库:

# /etc/apt/preferences.d/erlang
Package: erlang*
Pin: origin dl.cloudsmith.io
Pin-Priority: 1000

以下与上面的示例类似,但更喜欢 Launchpad:

# /etc/apt/preferences.d/erlang
Package: erlang*
Pin: origin ppa.launchpad.net
Pin-Priority: 1000

可以验证有效的包固定策略

sudo apt-cache policy

以下首选项文件示例会将所有erlang-*包固定到25.3 (假设包的包纪元为 1):

# /etc/apt/preferences.d/erlang
Package: esl-erlang
Pin: version 1:24.3.1
Pin-Priority: 1000

以下首选项文件示例将rabbitmq-server包固定到3.11.13 (假设包的包纪元为 1):

# /etc/apt/preferences.d/rabbitmq
Package: rabbitmq-server
Pin: version 1:3.11.13
Pin-Priority: 1000

在下面的示例中,esl-erlang 包固定到24.3.1 (假设包的包纪元为 1):

# /etc/apt/preferences.d/erlang
Package: esl-erlang
Pin: version 1:24.3.1
Pin-Priority: 1000
作者:Jeebiz  创建时间:2023-04-11 00:37
最后编辑:Jeebiz  更新时间:2024-09-23 10:03