RabbitMQ

TIP

RabbitMQ 是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件)。 RabbitMQ 服务器是用 Erlangopen in new window 语言编写的,而集群和故障转移是构建在开放电信平台open in new window框架上的。 所有主要的编程语言均有与代理接口通讯的客户端库。

RabbitMQ 官方网站open in new window

安装

推荐参考官方教程(英文):

Debian

下载最新 deb 软件包:

.deb 软件包上传到 Debian 主机,或在主机上使用 wget 指令下载软件包:

wget https://packages.erlang-solutions.com/erlang/debian/pool/esl-erlang_23.2.1-1~debian~stretch_amd64.deb
wget --content-disposition https://packagecloud.io/rabbitmq/rabbitmq-server/packages/ubuntu/disco/rabbitmq-server_3.8.11-1_all.deb/download.deb

执行以下指令安装 ErLang 与 RabbitMQ:

sudo dpkg --install esl-erlang_23.2.1-1~debian~stretch_amd64.deb
sudo dpkg --install rabbitmq-server_3.8.11-1_all.deb

通过插件开启 Web 管理界面,并重启 RabbitMQ 服务:

sudo rabbitmq-plugins enable rabbitmq_management
sudo systemctl restart rabbitmq-server.service

现在可以通过浏览器访问 http://localhost:15672open in new window 访问 Web 管理界面。

登入

现代浏览器可能会强制使用 https 链接,可参考 配置 > 配置 SSL(https)或暂时使用 IE 浏览器。

参考 配置 > 配置管理员账户

配置

配置管理员账户

  1. 添加用户:

    sudo rabbitmqctl add_user <用户名> <密码>
    

    查看 rabbitmqctl add_user 命令open in new window

  2. 添加用户标签:

    • none 无标签
    • management 管理员
    • monitoring 监控员
    • administrator 超级管理员
    sudo rabbitmqctl set_user_tags <用户名> administrator
    

    查看 rabbitmqctl set_user_tags 命令open in new window

  3. 赋予所有权限:

    sudo rabbitmqctl set_permissions -p / <用户名> ".*" ".*" ".*"
    

    查看 rabbitmqctl set_permissions 命令open in new window

配置 SSL(https)

建议参考官方文档 TLS 支持(英文)open in new window

常用指令

rabbitmqctl status

查询当前 RabbitMQ 状态

Runtime

OS PID: 457
OS: Linux
Uptime (seconds): 178
Is under maintenance?: false
RabbitMQ version: 3.8.11
Node name: rabbit@VM-0-5-debian
Erlang configuration: Erlang/OTP 23 [erts-11.1.5] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe]
Erlang processes: 441 used, 1048576 limit
Scheduler run queue: 1
Cluster heartbeat timeout (net_ticktime): 60

Plugins

Enabled plugin file: /etc/rabbitmq/enabled_plugins
Enabled plugins:

 * rabbitmq_management
 * amqp_client
 * rabbitmq_web_dispatch
 * cowboy
 * cowlib
 * rabbitmq_management_agent

Data directory

Node data directory: /var/lib/rabbitmq/mnesia/rabbit@VM-0-5-debian
Raft data directory: /var/lib/rabbitmq/mnesia/rabbit@VM-0-5-debian/quorum/rabbit@VM-0-5-debian

Config files


Log file(s)

 * /var/log/rabbitmq/rabbit@VM-0-5-debian.log
 * /var/log/rabbitmq/rabbit@VM-0-5-debian_upgrade.log

Alarms

(none)

Memory

Total memory used: 0.0965 gb
Calculation strategy: rss
Memory high watermark setting: 0.4 of available memory, computed to: 0.3642 gb

code: 0.033 gb (34.25 %)
other_proc: 0.0319 gb (33.06 %)
other_system: 0.0126 gb (13.05 %)
allocated_unused: 0.0066 gb (6.87 %)
reserved_unallocated: 0.0057 gb (5.93 %)
other_ets: 0.0033 gb (3.43 %)
atom: 0.0015 gb (1.51 %)
plugins: 0.0013 gb (1.39 %)
mgmt_db: 0.0002 gb (0.16 %)
binary: 0.0001 gb (0.14 %)
mnesia: 0.0001 gb (0.09 %)
metrics: 0.0001 gb (0.07 %)
msg_index: 0.0 gb (0.03 %)
quorum_ets: 0.0 gb (0.02 %)
connection_other: 0.0 gb (0.0 %)
connection_channels: 0.0 gb (0.0 %)
connection_readers: 0.0 gb (0.0 %)
connection_writers: 0.0 gb (0.0 %)
queue_procs: 0.0 gb (0.0 %)
queue_slave_procs: 0.0 gb (0.0 %)
quorum_queue_procs: 0.0 gb (0.0 %)

File Descriptors

Total: 2, limit: 32671
Sockets: 0, limit: 29401

Free Disk Space

Low free disk space watermark: 0.05 gb
Free disk space: 45.1227 gb

Totals

Connection count: 0
Queue count: 0
Virtual host count: 1

Listeners

Interface: [::], port: 15672, protocol: http, purpose: HTTP API
Interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0

rabbitmq-plugins list

查询当前插件配置/状态

 配置:E = 显示启用;e = 隐式启用
 | 状态:* = 运行于 rabbit@VM-0-5-debian
 |/
[e*] amqp_client                       3.6.6
[  ] cowboy                            1.0.3
[  ] cowlib                            1.0.1
[e*] mochiweb                          2.13.1
[  ] rabbitmq_amqp1_0                  3.6.6
[  ] rabbitmq_auth_backend_ldap        3.6.6
[  ] rabbitmq_auth_mechanism_ssl       3.6.6
[  ] rabbitmq_consistent_hash_exchange 3.6.6
[  ] rabbitmq_event_exchange           3.6.6
[  ] rabbitmq_federation               3.6.6
[  ] rabbitmq_federation_management    3.6.6
[  ] rabbitmq_jms_topic_exchange       3.6.6
[E*] rabbitmq_management               3.6.6
[e*] rabbitmq_management_agent         3.6.6
[  ] rabbitmq_management_visualiser    3.6.6
[  ] rabbitmq_mqtt                     3.6.6
[  ] rabbitmq_recent_history_exchange  1.2.1
[  ] rabbitmq_sharding                 0.1.0
[  ] rabbitmq_shovel                   3.6.6
[  ] rabbitmq_shovel_management        3.6.6
[  ] rabbitmq_stomp                    3.6.6
[  ] rabbitmq_top                      3.6.6
[  ] rabbitmq_tracing                  3.6.6
[  ] rabbitmq_trust_store              3.6.6
[e*] rabbitmq_web_dispatch             3.6.6
[  ] rabbitmq_web_stomp                3.6.6
[  ] rabbitmq_web_stomp_examples       3.6.6
[  ] sockjs                            0.3.4
[e*] webmachine                        1.10.3