环境和版本
ubuntu18, 最新的MQ版本
how
- 使用apt软件仓库, 可能会有版本的延迟
- 手动安装,使用dpkg -i, 需要手动安装所有依赖
Erlang安装
Rabbit Mq是使用Erlang编写,需要安装合适的版本,最简单的是使用apt安装。
标准的debian和ubuntu仓库可能会提供过期的版本,但是RMQ团队维持了一个Erlang/OTP版本供apt安装。
安装步骤如下
- 导入仓库签名key
为了可以使用这个仓库,我们需要添加apt-key Rmq签名的key,使得apt信任该软件包。这部分工作可以使用一个key server(可能容易过载)或者直接使用下载的key(推荐)。
- 下载key
https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | sudo apt-key add -
原站勘误
- 使用key server
sudo apt-key adv --keyserver "hkps.pool.sks-keyservers.net" --recv-keys "0x6B73A36E6026DFCA"
开启apt https 传输
sudo apt-get install apt-transport-https
- 添加仓库资源列表
所有的第三方apt仓库,都需要有一个文件来描述,并且存放在/etc/apt/source.list.d/目录下,建议存放在/etc/apt/source.list.d/bintray.erlang.list
资源仓库的定义文件使用下面的模式:
# This repository provides RabbitMQ packages
# See below for supported distribution and component values
deb https://dl.bintray.com/rabbitmq/debian $distribution $component
不得不说国外网站讲解的真是细致,国内快猛操的模式,导致大家干啥都很浮躁,没有这种好的态度,不得不说人家只凭这种态度还是值得我们学习的。(什么狗屁的崇洋媚外,在这点我不得不一吐为快,rabbitMQ你值得拥有,当然也不一概而论,我准备在Linux上放弃Vmare了,ubuntu18搭建centos7的nat(wifi网卡)搞得我图血,网站上一点都搜不到相关的知识,有了解的同学可以留言,网上搜出来的不对题的麻烦不要留言,我玩了一整天,看到一万遍c-p。不然今天应该是centos7+rabbitMq了)。下面的我就不翻译了,大家膜拜一下原汁原味的态度吧。
The next couple of sections discuss what distribution and component values are supported.
Distribution
In order to set up an apt repository that provides the correct package, a few decisions have to be made. One is determining the distribution name. It comes from the Debian or Ubuntu release used:
- bionic for Ubuntu 18.04
- xenial for Ubuntu 16.04
- buster for Debian Buster
- stretch for Debian Stretch
Erlang/OTP Version
Another is what Erlang/OTP release version should be provisioned. It is possible to track a specific series (e.g. 21.x) or install the most recent version available. The choice determines what Debian repository component will be configured.
Consider the following repository file at /etc/apt/sources.list.d/bintray.erlang.list:
# Installs the latest 21.x version available in the repository.
deb http://dl.bintray.com/rabbitmq-erlang/debian bionic erlang-21.x
It configures apt to install the most recent Erlang 21.x version available in the repository and use packages for Ubuntu 18.04 (Bionic).
For Debian Stretch the file would look like this:
# Installs the latest 21.x version available in the repository.
deb http://dl.bintray.com/rabbitmq-erlang/debian stretch erlang-21.x
To use the most recent 20.x patch release available, switch the component to erlang-20.x:
# Installs the latest 20.x version available in the repository.
deb http://dl.bintray.com/rabbitmq-erlang/debian bionic erlang-20.x
erlang-21.x, erlang-19.x, and erlang-16.x are the components for Erlang 21.x, 19.x and R16B03, respectively.
The erlang component installs the most recent version available:
# Installs the latest version available in the repository.
# Consider using version pinning.
deb http://dl.bintray.com/rabbitmq-erlang/debian bionic erlang
That version may or may not be supported by RabbitMQ, so version pinning is highly recommended.
- 更新包metadata
sudo apt-get update -y
- 安装合适的Erlang包
# This is recommended. Metapackages such as erlang and erlang-nox must only be used
# with apt version pinning. They do not pin their dependency versions.
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
包版本和仓库锁定(apt pinning)感兴趣的同学可以自行google
至此我们已经安装完成了Erlang,what?那MQ呢... heihei,同学你已经一只脚迈向了地球(welcome earth, Allies),欢迎来到MQ的地球
使用apt安装rabbit mq
磨刀不误砍柴工,既然你看了上面的安装过程,下面一样
#!/bin/sh
## Install RabbitMQ signing key
curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | sudo apt-key add -
## Install apt HTTPS transport
sudo apt-get install apt-transport-https
## Add Bintray repositories that provision latest RabbitMQ and Erlang 21.x releases
sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list <<EOF
deb https://dl.bintray.com/rabbitmq-erlang/debian bionic erlang-21.x
deb https://dl.bintray.com/rabbitmq/debian bionic main
EOF
## Update package indices
sudo apt-get update -y
## Install rabbitmq-server and its dependencies
sudo apt-get install rabbitmq-server -y --fix-missing
再次五体投地原汁原味膜拜网站小哥的态度,颤抖吧 E.T
The next couple of sections discusses what distribution and component values are supported.
Distribution
In order to set up an apt repository that provides the correct package, a few decisions have to be made. One is determining the distribution name. It comes from the Debian or Ubuntu release used:
- bionic (Ubuntu 18.04)
- artful
- trusty
- sid
- buster
- stretch
- xenial (Ubuntu 16.04)
- yakkety
- zesty
To add the apt repository to the source list directory (/etc/apt/sources.list.d), use:
>echo "deb https://dl.bintray.com/rabbitmq/debian {distribution} main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list
where {distribution} is the name of the Debian or Ubuntu distribution used (see above).
So, on Ubuntu 18.04 the above command becomes
>echo "deb https://dl.bintray.com/rabbitmq/debian bionic main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list
and on Ubuntu 16.04 it would be
>echo "deb https://dl.bintray.com/rabbitmq/debian xenial main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list
It is possible to list multiple repositories, for example, one that provides RabbitMQ and one that provides Erlang/OTP packages. On Ubuntu 18.04 that can be done by modifying the command in the above example like so:
>sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list <<EOF
deb https://dl.bintray.com/rabbitmq-erlang/debian bionic erlang-21.x
deb https://dl.bintray.com/rabbitmq/debian bionic main
EOF
and on Ubuntu 16.04 it would be
>sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list <<EOF
deb https://dl.bintray.com/rabbitmq-erlang/debian xenial erlang-21.x
deb https://dl.bintray.com/rabbitmq/debian xenial main
EOF
Install RabbitMQ Package
After updating the list of apt sources it is necessary to run apt-get update:
>sudo apt-get update -y
Then install the package with
>sudo apt-get install -y rabbitmq-server
(手动安装我已不翻译了)
Manual Installation with Dpkg
In some cases it may easier to download the package directly from GitHub and install it manually using sudo dpkg -i. Below is a download link.
Description | Download | Signature |
---|---|---|
.deb for Debian-based Linux (from GitHub) | rabbitmq-server_3.7.17-1_all.deb | Signature |
When installing manually with dpkg, it is necessary to install package dependencies first. dpkg, unlike apt, does not resolve or manage dependencies.
Here's an example that does that, installs wget, downloads the RabbitMQ package and installs it:
# sync package metadata
sudo apt-get update
# install dependencies manually
sudo apt-get -y install socat logrotate init-system-helpers adduser
# download the package
sudo apt-get -y install wget
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.17/rabbitmq-server_3.7.17-1_all.deb
# install the package with dpkg
sudo dpkg -i rabbitmq-server_3.7.17-1_all.deb
rm rabbitmq-server_3.7.17-1_all.deb
Installation via apt repositories on Bintray and Package Cloud is recommended over downloading the package directly and installing via dpkg -i. When the RabbitMQ package is installed manually with dpkg -i the operator is responsible for making sure that all package dependencies are met.
User Privilege Requirements
RabbitMQ Debian package will require sudo privileges to install and manage. In environments where sudo isn't available, consider using the generic binary build instead.
让MQ run 起来
安装时,rabbit mq默认以守护进程启动,并且使用没有权限的用户 rabbitmq
可以使用super user的service命令启动。关闭、和查看rabbitmq-server状态
sudo service rabbitmq-server status[start| stop | restart]
端口获取
rabbitMq节点绑定有个开放的tcp端口,用来接受client端和CLI工具的链接。其他的工具或者进程可能占用或者阻止端口,竟会出现错误。要保证一下的端口可用性,因为Firewalls和SeLinux会屏蔽端口连接。
- 4369: epmd, a peer discovery service used by RabbitMQ nodes and CLI tools
- 5672, 5671: used by AMQP 0-9-1 and 1.0 clients without and with TLS
- 25672: used for inter-node and CLI tools communication (Erlang distribution server port) and is allocated from a dynamic range (limited to a single port by default, computed as AMQP port + 20000). Unless external connections on these ports are really necessary (e.g. the cluster uses federation or CLI tools are used on machines outside the subnet), these ports should not be publicly exposed. See networking guide for details.
- 35672-35682: used by CLI tools (Erlang distribution client ports) for communication with nodes and is allocated from a dynamic range (computed as server distribution port + 10000 through server distribution port + 10010). See networking guide for details.
- 15672: HTTP API clients, management UI and rabbitmqadmin (only if the management plugin is enabled)
- 61613, 61614: STOMP clients without and with TLS (only if the STOMP plugin is enabled)
- 1883, 8883: (MQTT clients without and with TLS, if the MQTT plugin is enabled
- 15674: STOMP-over-WebSockets clients (only if the Web STOMP plugin is enabled)
- 15675: MQTT-over-WebSockets clients (only if the Web MQTT plugin is enabled)
It is possible to configure RabbitMQ to use different ports and specific network interfac
默认user access
broker会创建一个user为guest,密码为guest。通常没有配置的clients使用这个凭证。但是默认的这些凭证只能从localhost连接broker,所以你需要配置user用于网络上的连接。
See the documentation on access control for information on how to create more users and delete the guest user.
系统限制
生产级别的rabbitMq可能需要系统limit和内核参数调优到允许处理高并发连接和缓冲队列,主要是ulimit -n参数,生产环境可以调到最大的65535,开发环境4096,下面knee down & suck
With systemd (Recent Linux Distributions)
On distributions that use systemd, the OS limits are controlled via a configuration file at /etc/systemd/system/rabbitmq-server.service.d/limits.conf. For example, to set the max open file handle limit (nofile) to 64000:
[Service]
LimitNOFILE=64000
See systemd documentation to learn about the supported limits and other directives.
With Docker
To configure kernel limits for Docker contains, use the "default-ulimits" key in Docker daemon configuration file. The file has to be installed on Docker hosts at /etc/docker/daemon.json:
{
"default-ulimits": {
"nofile": {
"Name": "nofile",
"Hard": 64000,
"Soft": 64000
}
}
}
Without systemd (Older Linux Distributions)
The most straightforward way to adjust the per-user limit for RabbitMQ on distributions that do not use systemd is to edit the /etc/default/rabbitmq-server (provided by the RabbitMQ Debian package) or rabbitmq-env.conf to invoke ulimit before the service is started.
>ulimit -S -n 4096
This soft limit cannot go higher than the hard limit (which defaults to 4096 in many distributions). The hard limit can be increased via /etc/security/limits.conf. This also requires enabling the pam_limits.so module and re-login or reboot. Note that limits cannot be changed for running OS processes.
For more information about controlling fs.file-max with sysctl, please refer to the excellent Riak guide on open file limit tuning.
验证系统limit(应该只能验证配置参数,系统参数需要系统里面配置)
rabbitnqctl satus
or
cat /proc/$rabbitmq_bean_process_pid/limits
See the CLI tools guide to learn more.
Log Files and Management
Server logs can be found under the configurable directory, which usually defaults to /var/log/rabbitmq when RabbitMQ is installed via a Linux package manager.
RABBITMQ_LOG_BASE can be used to override log directory location.
Assuming a systemd-based distribution, system service logs can be inspected using
journalctl --system
which requires superuser privileges. Its output can be filtered to narrow it down to RabbitMQ-specific entries:
sudo journalctl --system | grep rabbitmq
The output will look similar to this:
Dec 26 11:03:04 localhost rabbitmq-server[968]: ## ##
Dec 26 11:03:04 localhost rabbitmq-server[968]: ## ## RabbitMQ 3.7.16\. Copyright (c) 2007-2019 Pivotal Software, Inc.
Dec 26 11:03:04 localhost rabbitmq-server[968]: ########## Licensed under the MPL. See http://www.rabbitmq.com/
Dec 26 11:03:04 localhost rabbitmq-server[968]: ###### ##
Dec 26 11:03:04 localhost rabbitmq-server[968]: ########## Logs: /var/log/rabbitmq/rabbit@localhost.log
Dec 26 11:03:04 localhost rabbitmq-server[968]: /var/log/rabbitmq/rabbit@localhost_upgrade.log
Dec 26 11:03:04 localhost rabbitmq-server[968]: Starting broker...
Dec 26 11:03:05 localhost rabbitmq-server[968]: systemd unit for activation check: "rabbitmq-server.service"
Dec 26 11:03:06 localhost rabbitmq-server[968]: completed with 6 plugins.
Log Rotation
The broker always appends to the log files, so a complete log history is retained.
logrotate is the recommended way of log file rotation and compression. By default, the package will set up logrotate to run weekly on files located in default /var/log/rabbitmq directory. Rotation configuration can be found in /etc/logrotate.d/rabbitmq-server.
rabbitmq 有很多命令行工具
- rabbitmqctl 服务管理和通常的操作任务
- rabbitmq-diagnostics 诊断额健康检查
- rabbitmq-plugins 插件管理
- rabbitmqadmin http api的操作任务
感兴趣的可以自行查阅doc文档
网友评论