原文地址 http://soft.dog/2016/04/20/RabbitMQ-cli-rabbitmqadmin/
前言
RabbitMQ 是一个使用 Erlang 编写的开源消息队列中间件,被广泛使用在各种应用场景中
一般对于它的监控和管理可以通过web来完成,详细可以参考 RabbitMQ 监控
但生产环境中经常没有访问web管理界面的条件,只提供了CLI界面,或者有些自动化的需求通过web界面无法完成,这时有没有一种直接在CLI环境下进行管理的方法呢,官方提供的 rabbitmqadmin 命令正好可以满足这类需求
对于运维来说,个人感觉更倾向使用CLI的方式,因为虽然web的界面更友好,但是明显不如CLI快捷,CLI也可以结合其它命令进行更进一步的处理,比如将关键信息查出来后提供给集中的监控系统以触发报警
目前 rabbitmqadmin 可以完成以下任务:
- 列出 exchanges, queues, bindings, vhosts, users, permissions, connections and channels
- 看到汇总信息
- 申明和清除 exchanges, queues, bindings, vhosts, users and permissions
- 发布和获取消息
- 关闭连接和清空队列
- 导入导出配置
这里分享一下 rabbitmqadmin 的基本操作,详细可以参考 官方文档
Tip: 当前的最新版本为 RabbitMQ 3.6.1 发布于 01 Mar 2016 ,当前最新的 Erlang 版本为 erlang 18.3, RabbitMQ 3.6.1 依赖于
>= R16B-03
的 Erlang[root@h102 rabbitmq]# rpm -ivh rabbitmq-server-3.6.1-1.noarch.rpm warning: rabbitmq-server-3.6.1-1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 056e8e56: NOKEY error: Failed dependencies: erlang >= R16B-03 is needed by rabbitmq-server-3.6.1-1.noarch [root@h102 rabbitmq]#
概要
环境
[root@h102 rabbitmq]# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m
[root@h102 rabbitmq]# uname -a
Linux h102.temp 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@h102 rabbitmq]#
升级Erlang
最新版的 Erlang 可以在 Erlang下载地址 里找到
如果之前没安装过 Erlang ,可以直接下载
[root@h102 rabbitmq]# wget https://packages.erlang-solutions.com/erlang/esl-erlang/FLAVOUR_1_general/esl-erlang_18.3-1~centos~6_amd64.rpm
--2016-04-18 16:45:35-- https://packages.erlang-solutions.com/erlang/esl-erlang/FLAVOUR_1_general/esl-erlang_18.3-1~centos~6_amd64.rpm
Resolving packages.erlang-solutions.com... 31.172.186.53
Connecting to packages.erlang-solutions.com|31.172.186.53|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 44480824 (42M) [application/x-redhat-package-manager]
Saving to: “esl-erlang_18.3-1~centos~6_amd64.rpm”
100%[===================================================================================================>] 44,480,824 350K/s in 4m 54s
2016-04-18 16:50:31 (148 KB/s) - “esl-erlang_18.3-1~centos~6_amd64.rpm” saved [44480824/44480824]
[root@h102 rabbitmq]#
但是建议还是使用仓库的方式,特别是在已经安装有Erlang的情况下,因为如果添加删除包的过程中有依赖,让 YUM 自动去解决是最省心的
如下:
[root@h102 rabbitmq]# rpm -ivh esl-erlang_18.3-1~centos~6_amd64.rpm
Preparing... ########################################### [100%]
file /usr/bin/epmd from install of esl-erlang-18.3-1.x86_64 conflicts with file from package erlang-erts-R14B-04.3.el6.x86_64
file /usr/bin/erl from install of esl-erlang-18.3-1.x86_64 conflicts with file from package erlang-erts-R14B-04.3.el6.x86_64
file /usr/bin/erlc from install of esl-erlang-18.3-1.x86_64 conflicts with file from package erlang-erts-R14B-04.3.el6.x86_64
file /usr/bin/escript from install of esl-erlang-18.3-1.x86_64 conflicts with file from package erlang-erts-R14B-04.3.el6.x86_64
file /usr/bin/run_erl from install of esl-erlang-18.3-1.x86_64 conflicts with file from package erlang-erts-R14B-04.3.el6.x86_64
file /usr/bin/run_test from install of esl-erlang-18.3-1.x86_64 conflicts with file from package erlang-erts-R14B-04.3.el6.x86_64
file /usr/bin/to_erl from install of esl-erlang-18.3-1.x86_64 conflicts with file from package erlang-erts-R14B-04.3.el6.x86_64
file /usr/bin/dialyzer from install of esl-erlang-18.3-1.x86_64 conflicts with file from package erlang-dialyzer-R14B-04.3.el6.x86_64
file /usr/bin/typer from install of esl-erlang-18.3-1.x86_64 conflicts with file from package erlang-typer-R14B-04.3.el6.x86_64
[root@h102 rabbitmq]# rpm -e erlang-erts-R14B-04.3.el6.x86_64
error: Failed dependencies:
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-crypto-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-kernel-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-hipe-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-syntax_tools-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-stdlib-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-compiler-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-runtime_tools-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-mnesia-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-snmp-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-xmerl-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-public_key-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-ssl-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-inets-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-orber-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-cosEvent-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-cosTime-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-cosNotification-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-cosProperty-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-edoc-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-ssh-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-otp_mibs-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-asn1-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-docbuilder-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-cosFileTransfer-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-cosEventDomain-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-cosTransactions-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-percept-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-inviso-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-parsetools-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-eunit-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-diameter-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed by (installed) erlang-ic-R14B-04.3.el6.x86_64
erlang-erts(x86-64) = R14B-04.3.el6 is needed