通过 rabbitmqadmin 管理 rabbitmq

  1. 下载 rabbitmqadmin 工具
[root@yangzhen ~]# wget http://localhost:15672/cli/rabbitmqadmin
--2019-03-22 14:42:56--  http://localhost:15672/cli/rabbitmqadmin
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:15672... failed: Connection refused.
Connecting to localhost (localhost)|127.0.0.1|:15672... connected.
HTTP request sent, awaiting response... 200 OK
Length: 37698 (37K) [application/octet-stream]
Saving to: ‘rabbitmqadmin’

100%[=====================================================================================================================================================>] 37,698      --.-K/s   in 0s      

2019-03-22 14:42:56 (306 MB/s) - ‘rabbitmqadmin’ saved [37698/37698]


  1. 在当前目录下执行如下命令
[root@yangzhen ~]# chmod +x rabbitmqadmin 
[root@yangzhen ~]# mv rabbitmqadmin /usr/bin/
  1. 列出集群用户
[root@yangzhen ~]# rabbitmqadmin list users
+----------+--------------------------------+--------------------------------------------------+---------------+
|   name   |       hashing_algorithm        |                  password_hash                   |     tags      |
+----------+--------------------------------+--------------------------------------------------+---------------+
| guest    | rabbit_password_hashing_sha256 | mxF07YdGV1IuzzGY/0LLDVq9aJIyhniAsybHF/1i9wVFRt3d | administrator |
| test3    | rabbit_password_hashing_sha256 | 0EJ7Rbw3Qv6JGquqCkdPsOzL39u5G07xVLosIPMj2QTqZMGc |               |
| yangzhen | rabbit_password_hashing_sha256 | 9CqKbTiA+PQVD8YH67nNuVrCZb/Ssii2GBrny7CpBCR+s2a+ | administrator |
+----------+--------------------------------+--------------------------------------------------+---------------+

  1. 新建集群用户
[root@yangzhen ~]# rabbitmqadmin declare user name=test4 password=123456 tags=monitoring
user declared

  1. 新增虚拟主机并添加指定用户至该虚拟主机中
[root@yangzhen ~]# rabbitmqadmin declare vhost name=/test4
vhost declared
[root@yangzhen ~]# rabbitmqadmin declare permission vhost=/test4 user=test4 configure=".*" write=".*" read=".*"
permission declared

  1. 列出集群队列
[root@yangzhen ~]# rabbitmqadmin list queues
+--------------+----------+
|     name     | messages |
+--------------+----------+
| oss.test     | 0        |
| oss.url_test | 0        |
| telecom      | 0        |
| test         | 0        |
+--------------+----------+

  1. 列出信息交换机
[root@yangzhen ~]# rabbitmqadmin list exchanges
+--------------------+---------+
|        name        |  type   |
+--------------------+---------+
|                    | direct  |
| amq.direct         | direct  |
| amq.fanout         | fanout  |
| amq.headers        | headers |
| amq.match          | headers |
| amq.rabbitmq.log   | topic   |
| amq.rabbitmq.trace | topic   |
| amq.topic          | topic   |
| oss_test           | direct  |
| test               | direct  |
| yz                 | topic   |
| yz_fanout          | fanout  |
+--------------------+---------+

========

  1. 备份 rabbitmq 配置,在当前目录生成 json 文件
[root@yangzhen ~]# rabbitmqadmin export rabbitmq_back.json
Exported definitions for localhost to "rabbitmq_back.json"

  1. 恢复配置
[root@yangzhen ~]# rabbitmqadmin import   rabbitmq_back.json 
Imported definitions for localhost from "rabbitmq_back.json"

  1. 备份 rabbitmq 数据
    获取数据目录执行如下命令。也即是默认安装目录下。
[root@yangzhen ~]# rabbitmqctl eval 'rabbit_mnesia:dir().'
"/var/lib/rabbitmq/mnesia/rabbit@yangzhen"

  1. 创建存档,为保证数据一致,可以先停止 rabbitmq。
[root@yangzhen mnesia]# pwd
/var/lib/rabbitmq/mnesia
[root@yangzhen mnesia]# tar -zcf rabbitmq_backup.tar.fz rabbit\@yangzhen

  1. 恢复数据比较简单,把压缩档解压至数据目录中即可。恢复到另一节点则不适用,备份同一台机器,然后重启同一台机器。

你可能感兴趣的:(rabbitmq)