訊息型中介軟體之RabbitMQ基礎使用

1874發表於2020-08-26

  1、概念

  RabbitMQ是AMQP(高階訊息佇列協議)協議的實現主要功能用於分散式應用當中的各元件間解耦。在傳統C/S架構中,如果客戶端傳送一個請求訊息,服務端必須得線上,有了中介軟體,客戶端不是非得要服務端線上才可傳送請求,客戶端只需將請求訊息傳送給中介軟體,中介軟體負責儲存和轉發請求訊息,此時如果服務端不線上,依然不妨礙客戶端的請求可以發出,而客戶端的請求此時有可能還會被正常服務;而對於訊息型中介軟體最核心的元件有3個,分別是exchange(交換器)、binding(繫結器)、queue(佇列);其中交換器的作用是把訊息發出一方(簡稱生產者)發出的訊息,通過交換器把訊息傳送給繫結器,繫結器根據匹配路由規則把訊息路由給後端佇列,然後訂閱者再到對應的佇列上取出訊息進行消費,通常一個訂閱者(訊息消費者,或者叫使用者也行)對應一個或多個佇列;而訂閱者與佇列之間的通道(傳遞訊息的通道)我們稱之為channel(頻道);也就說訂閱者可以訂閱一個或多個頻道,一旦對應頻道有訊息產生,對應訂閱者都會收到;一個訊息該如何傳送到對應的佇列,這取決於我們的路由模式,路由模式通常我們通過繫結器進行定義;也就是說繫結器的主要作用就是用來定義交換器收到訊息後該把訊息傳送到那個給佇列;而對於路由模式來講,它有多種,常見的有direct(點到點的直接路由)、topic(話題型過濾)、fan-out(刪除)、headers(基於訊息首部過濾);這些路由模式主要是用來過濾訊息的,把符合我們定義的路由規則的訊息過濾出來,傳送到指定佇列,所以我們也可以把路由模式稱之為訊息過濾器;簡單點講路由規則就是把交換器上的某一類訊息繫結一個或多個佇列;對於AMQP來講,除了上面的4中路由模式以外,它還定義一個virtualhost的概念,所謂virtualhost就是虛擬主機,這裡的虛擬主機主要是用來應用隔離,一個虛擬主機內部可以有exchange、binding、queue;它相當於一個單獨broker,所以虛擬主機它可以將一個物理的broker劃分成多個不同應用的broker;

  2、RabbitMQ架構

  提示:上圖主要描述了生產者把訊息通過交換器匹配路由規則(繫結器)把不同型別的訊息通過繫結器把訊息路由到不同的佇列上,然後消費者根據自身訂閱的頻道,到不同頻道對應的佇列上取出訊息進行消費的一個過程;

  3、RabbitMQ的安裝配置

  在centos7上rabbitmq的安裝非常簡單,我們只需要配置好epel源,然後yum安裝即可;

[root@node1 ~]# yum repolist
已載入外掛:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
源標識                                       源名稱                                                              狀態
!base/7/x86_64                               CentOS-7 - Base - mirrors.aliyun.com                                10,070
!docker-ce-stable/x86_64                     Docker CE Stable - x86_64                                               79
!epel/x86_64                                 Extra Packages for Enterprise Linux 7 - x86_64                      13,426
!extras/7/x86_64                             CentOS-7 - Extras - mirrors.aliyun.com                                 413
!updates/7/x86_64                            CentOS-7 - Updates - mirrors.aliyun.com                              1,112
repolist: 25,100
[root@node1 ~]# yum install rabbitmq-server
已載入外掛:fastestmirror, langpacks
base                                                                                            | 3.6 kB  00:00:00     
docker-ce-stable                                                                                | 3.5 kB  00:00:00     
epel                                                                                            | 4.7 kB  00:00:00     
extras                                                                                          | 2.9 kB  00:00:00     
updates                                                                                         | 2.9 kB  00:00:00     
(1/2): epel/x86_64/updateinfo                                                                   | 1.0 MB  00:00:00     
(2/2): epel/x86_64/primary_db                                                                   | 6.9 MB  00:00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解決依賴關係
--> 正在檢查事務
---> 軟體包 rabbitmq-server.noarch.0.3.3.5-34.el7 將被 安裝
--> 正在處理依賴關係 erlang-erts >= R12B-3,它被軟體包 rabbitmq-server-3.3.5-34.el7.noarch 需要
……省略部分內容……
已安裝:
  rabbitmq-server.noarch 0:3.3.5-34.el7                                                                                

作為依賴被安裝:
  erlang-asn1.x86_64 0:R16B-03.18.el7                      erlang-compiler.x86_64 0:R16B-03.18.el7                    
  erlang-crypto.x86_64 0:R16B-03.18.el7                    erlang-erts.x86_64 0:R16B-03.18.el7                        
  erlang-hipe.x86_64 0:R16B-03.18.el7                      erlang-inets.x86_64 0:R16B-03.18.el7                       
  erlang-kernel.x86_64 0:R16B-03.18.el7                    erlang-mnesia.x86_64 0:R16B-03.18.el7                      
  erlang-os_mon.x86_64 0:R16B-03.18.el7                    erlang-otp_mibs.x86_64 0:R16B-03.18.el7                    
  erlang-public_key.x86_64 0:R16B-03.18.el7                erlang-runtime_tools.x86_64 0:R16B-03.18.el7               
  erlang-sasl.x86_64 0:R16B-03.18.el7                      erlang-sd_notify.x86_64 0:0.1-1.el7                        
  erlang-snmp.x86_64 0:R16B-03.18.el7                      erlang-ssl.x86_64 0:R16B-03.18.el7                         
  erlang-stdlib.x86_64 0:R16B-03.18.el7                    erlang-syntax_tools.x86_64 0:R16B-03.18.el7                
  erlang-tools.x86_64 0:R16B-03.18.el7                     erlang-xmerl.x86_64 0:R16B-03.18.el7                       

完畢!
[root@node1 ~]# 

  提示:rabbitmq是erlang語言研發,所以安裝rabbitmq-server這個包,它會依賴很多erlang包,而這些包都來自epel倉庫,所以安裝之前一定要先配置好epel源;

  檢視rabbitmq-server安裝生成了哪些檔案

[root@node1 ~]# rpm -ql rabbitmq-server
/etc/logrotate.d/rabbitmq-server
/etc/rabbitmq
/etc/rabbitmq/rabbitmq.config
/usr/lib/ocf/resource.d/rabbitmq/rabbitmq-server
/usr/lib/rabbitmq/bin
/usr/lib/rabbitmq/bin/rabbitmq-defaults
/usr/lib/rabbitmq/bin/rabbitmq-env
/usr/lib/rabbitmq/bin/rabbitmq-plugins
/usr/lib/rabbitmq/bin/rabbitmq-server
/usr/lib/rabbitmq/bin/rabbitmqctl
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/ebin
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/ebin/app_utils.beam
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/ebin/background_gc.beam
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/ebin/credit_flow.beam
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/ebin/delegate.beam
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/ebin/delegate_sup.beam
……省略部分內容……
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/sbin
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/sbin/rabbitmq-defaults
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/sbin/rabbitmq-env
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/sbin/rabbitmq-plugins
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/sbin/rabbitmq-server
/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/sbin/rabbitmqctl
/usr/lib/systemd/system/rabbitmq-server.service
/usr/lib/tmpfiles.d/rabbitmq-server.conf
/usr/sbin/rabbitmq-plugins
/usr/sbin/rabbitmq-server
/usr/sbin/rabbitmqctl
……省略部分內容……
/var/log/rabbitmq
/var/run/rabbitmq
[root@node1 ~]# 

  提示:/usr/sbin/rabbitmqctl 這個工具是命令列工具,主要用來管理rabbitmq;/usr/sbin/rabbitmq-plugins用來管理rabbitmq外掛的命令列工具;/usr/sbin/rabbitmq-server伺服器二進位制主程式;/usr/lib/systemd/system/rabbitmq-server.service這個檔案是它的基於systemd啟動的unit file;/usr/lib/rabbitmq/bin/rabbitmq-defaults這個檔案用於定義預設環境變數配置;/var/log/rabbitmq用於存放rabbitmq日誌目錄;/etc/rabbitmq/rabbitmq.config這個是rabbitmq的主配置檔案,主要定義個元件訪問許可權,資源限制,外掛及叢集相關配置;rabbitmq的配置方式分3中,第一種是環境變數的方式,該方式主要用來定義網路引數以及配置檔案路徑相關配置;其次是配置檔案的方式,配置檔案主要定義伺服器各元件間的訪問許可權,資源限制,外掛以及叢集相關配置;最後一種是執行時引數,這種方式主要用於定義rabbitmq叢集的執行時引數;

  比較常用的環境變數

    RABBITMQ_BASE:用來指定rabbitmq的安裝目錄,這個目錄主要存放rabbitmq資料庫和日誌相關檔案。(一般用於windows,類unix上不常用)

    RABBITMQ_CONFIG_FILE:用於指定配置檔案路徑;

    RABBITMQ_LOGS:用於單獨指定日誌檔案;

    RABBITMQ_NODE_IP_ADDRESS:用於指定節點監聽的ip地址;

    RABBITMQ_NODE_PORT:用於指定節點監聽的埠;

    RABBITMQ_NODE_NAME:用於指定節點名稱;

    RABBITMQ_PLUGINS_DIR:用於指定外掛目錄;

  rabbitmq預設配置檔案相關變數說明

    auth_mechanisms:用於定義rabbitmq的認證機制;

    default_user:定義預設使用者;預設是guest;

    default_pass:定義預設使用者的預設密碼;預設是guest;

    default_premission:定義預設使用者的預設許可權;預設是".*" ".*" ".*";

    default_user_tags:定義預設使用者的標籤,預設是administrator;

    default_vhost:定義預設虛擬主機;預設是“/”;

    disk_free_limit:定義磁碟最少預留空間;預設50M;

    hearbeat:定義檢測各元件存活的訊息時長(心跳值);預設600秒;

    hipe_compile:用於指定是否使用hipe編譯器編譯程式;預設是true,表示使用hipe編譯器;

    log_levels:用於指定日誌級別,這裡的日誌級別只有四種,分別是none,error,warning,info;

    tcp_listeners:定義監聽的地址和埠;預設是本機的所有地址的5672;

    ssl_listeners:定義基於ssl協議通訊監聽的地址和埠;預設是本機的所有地址的5672;

    vm_memory_high_watermark:定義記憶體的高水位標記,所謂高水位標記,就是用來指定記憶體的最少空閒記憶體空間;

  啟動rabbitmq-server

  提示:以預設配置檔案啟動rabbitmq,它會監聽5672和25672,25672是用來叢集通訊的埠;5672是rabbitmq的管理介面;除了這兩個埠,如果開啟了rabbitmq-management外掛,它還會監聽15672;rabbitmq-management這個外掛主要提供了web圖形化管理介面;

  4、rabbitmqctl使用

  rabbitmqctl幫助資訊

[root@node1 ~]# rabbitmqctl -h
Error: could not recognise command
Usage:
rabbitmqctl [-n <node>] [-q] <command> [<command options>] 

Options:
    -n node
    -q

Default node is "rabbit@server", where server is the local host. On a host 
named "server.example.com", the node name of the RabbitMQ Erlang node will 
usually be rabbit@server (unless RABBITMQ_NODENAME has been set to some 
non-default value at broker startup time). The output of hostname -s is usually 
the correct suffix to use after the "@" sign. See rabbitmq-server(1) for 
details of configuring the RabbitMQ broker.

Quiet output mode is selected with the "-q" flag. Informational messages are 
suppressed when quiet mode is in effect.

Commands:
    stop [<pid_file>]
    stop_app
    start_app
    wait <pid_file>
    reset
    force_reset
    rotate_logs <suffix>

    join_cluster <clusternode> [--ram]
    cluster_status
    change_cluster_node_type disc | ram
    forget_cluster_node [--offline]
    update_cluster_nodes clusternode
    sync_queue queue
    cancel_sync_queue queue
    set_cluster_name name

    add_user <username> <password>
    delete_user <username>
    change_password <username> <newpassword>
    clear_password <username>
    set_user_tags <username> <tag> ...
    list_users

    add_vhost <vhostpath>
    delete_vhost <vhostpath>
    list_vhosts [<vhostinfoitem> ...]
    set_permissions [-p <vhostpath>] <user> <conf> <write> <read>
    clear_permissions [-p <vhostpath>] <username>
    list_permissions [-p <vhostpath>]
    list_user_permissions <username>

    set_parameter [-p <vhostpath>] <component_name> <name> <value>
    clear_parameter [-p <vhostpath>] <component_name> <key>
    list_parameters [-p <vhostpath>]

    set_policy [-p <vhostpath>] [--priority <priority>] [--apply-to <apply-to>] 
<name> <pattern>  <definition>
    clear_policy [-p <vhostpath>] <name>
    list_policies [-p <vhostpath>]

    list_queues [-p <vhostpath>] [<queueinfoitem> ...]
    list_exchanges [-p <vhostpath>] [<exchangeinfoitem> ...]
    list_bindings [-p <vhostpath>] [<bindinginfoitem> ...]
    list_connections [<connectioninfoitem> ...]
    list_channels [<channelinfoitem> ...]
    list_consumers [-p <vhostpath>]
    status
    environment
    report
    eval <expr>

    close_connection <connectionpid> <explanation>
    trace_on [-p <vhost>]
    trace_off [-p <vhost>]
    set_vm_memory_high_watermark <fraction>

<vhostinfoitem> must be a member of the list [name, tracing].

The list_queues, list_exchanges and list_bindings commands accept an optional 
virtual host parameter for which to display results. The default value is "/".

<queueinfoitem> must be a member of the list [name, durable, auto_delete, 
arguments, policy, pid, owner_pid, exclusive_consumer_pid, 
exclusive_consumer_tag, messages_ready, messages_unacknowledged, messages, 
consumers, consumer_utilisation, memory, slave_pids, synchronised_slave_pids, 
status].

<exchangeinfoitem> must be a member of the list [name, type, durable, 
auto_delete, internal, arguments, policy].

<bindinginfoitem> must be a member of the list [source_name, source_kind, 
destination_name, destination_kind, routing_key, arguments].

<connectioninfoitem> must be a member of the list [pid, name, port, host, 
peer_port, peer_host, ssl, ssl_protocol, ssl_key_exchange, ssl_cipher, 
ssl_hash, peer_cert_subject, peer_cert_issuer, peer_cert_validity, state, 
channels, protocol, auth_mechanism, user, vhost, timeout, frame_max, 
channel_max, client_properties, recv_oct, recv_cnt, send_oct, send_cnt, 
send_pend].

<channelinfoitem> must be a member of the list [pid, connection, name, number, 
user, vhost, transactional, confirm, consumer_count, messages_unacknowledged, 
messages_uncommitted, acks_uncommitted, messages_unconfirmed, prefetch_count, 
global_prefetch_count].


[root@node1 ~]# 

  提示:從上面的幫助資訊可以瞭解到rabbitmqctl這個工具有很多子命令;主要有對應用到管理相關子命令,對虛擬主機相關管理的,許可權,使用者,叢集,策略等等;

  stop [<pid_file>]:停止rabbitmq-server;

[root@node1 ~]# rabbitmqctl stop
Stopping and halting node rabbit@node1 ...
...done.
[root@node1 ~]# ss -tnl
State       Recv-Q Send-Q              Local Address:Port                             Peer Address:Port              
LISTEN      0      5                   192.168.122.1:53                                          *:*                  
LISTEN      0      128                             *:22                                          *:*                  
LISTEN      0      128                     127.0.0.1:631                                         *:*                  
LISTEN      0      100                     127.0.0.1:25                                          *:*                  
LISTEN      0      100                     127.0.0.1:64667                                       *:*                  
LISTEN      0      128                             *:8000                                        *:*                  
LISTEN      0      128                             *:8001                                        *:*                  
LISTEN      0      5                       127.0.0.1:8010                                        *:*                  
LISTEN      0      128                             *:111                                         *:*                  
LISTEN      0      128                             *:80                                          *:*                  
LISTEN      0      128                            :::22                                         :::*                  
LISTEN      0      128                           ::1:631                                        :::*                  
LISTEN      0      100                           ::1:25                                         :::*                  
LISTEN      0      128                            :::111                                        :::*                  
LISTEN      0      128                            :::80                                         :::*                  
[root@node1 ~]# 

  提示:rabbitmqctl stop 就相當於把rabbitmq服務給殺死,停止服務;

  stop_app:停止rabbitmq-server上的所有應用;

[root@node1 ~]# rabbitmqctl status   
Status of node rabbit@node1 ...
[{pid,18223},
 {running_applications,[{rabbit,"RabbitMQ","3.3.5"},
                        {os_mon,"CPO  CXC 138 46","2.2.14"},
                        {mnesia,"MNESIA  CXC 138 12","4.11"},
                        {xmerl,"XML parser","1.3.6"},
                        {sasl,"SASL  CXC 138 11","2.3.4"},
                        {stdlib,"ERTS  CXC 138 10","1.19.4"},
                        {kernel,"ERTS  CXC 138 10","2.16.4"}]},
 {os,{unix,linux}},
 {erlang_version,"Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:30] [hipe] [kernel-poll:true]\n"},
 {memory,[{total,36262168},
          {connection_procs,2800},
          {queue_procs,5600},
          {plugins,0},
          {other_proc,13729216},
          {mnesia,60144},
          {mgmt_db,0},
          {msg_index,21880},
          {other_ets,756824},
          {binary,19048},
          {code,16707498},
          {atom,602729},
          {other_system,4356429}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,1581588480},
 {disk_free_limit,50000000},
 {disk_free,39834275840},
 {file_descriptors,[{total_limit,924},
                    {total_used,3},
                    {sockets_limit,829},
                    {sockets_used,1}]},
 {processes,[{limit,1048576},{used,127}]},
 {run_queue,0},
 {uptime,367}]
...done.
[root@node1 ~]# rabbitmqctl stop_app
Stopping node rabbit@node1 ...
...done.
[root@node1 ~]# rabbitmqctl status  
Status of node rabbit@node1 ...
[{pid,18223},
 {running_applications,[{xmerl,"XML parser","1.3.6"},
                        {sasl,"SASL  CXC 138 11","2.3.4"},
                        {stdlib,"ERTS  CXC 138 10","1.19.4"},
                        {kernel,"ERTS  CXC 138 10","2.16.4"}]},
 {os,{unix,linux}},
 {erlang_version,"Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:30] [hipe] [kernel-poll:true]\n"},
 {memory,[{total,35566624},
          {connection_procs,0},
          {queue_procs,0},
          {plugins,0},
          {other_proc,13300856},
          {mnesia,0},
          {mgmt_db,0},
          {msg_index,0},
          {other_ets,607888},
          {binary,12600},
          {code,16707498},
          {atom,602729},
          {other_system,4335053}]},
 {alarms,[]},
 {listeners,[]},
 {processes,[{limit,1048576},{used,46}]},
 {run_queue,0},
 {uptime,384}]
...done.
[root@node1 ~]# ss -tnl
State       Recv-Q Send-Q              Local Address:Port                             Peer Address:Port              
LISTEN      0      5                   192.168.122.1:53                                          *:*                  
LISTEN      0      128                             *:22                                          *:*                  
LISTEN      0      128                     127.0.0.1:631                                         *:*                  
LISTEN      0      100                     127.0.0.1:25                                          *:*                  
LISTEN      0      100                     127.0.0.1:64667                                       *:*                  
LISTEN      0      128                             *:8000                                        *:*                  
LISTEN      0      128                             *:8001                                        *:*                  
LISTEN      0      128                             *:25672                                       *:*                  
LISTEN      0      5                       127.0.0.1:8010                                        *:*                  
LISTEN      0      128                             *:111                                         *:*                  
LISTEN      0      128                             *:80                                          *:*                  
LISTEN      0      128                             *:4369                                        *:*                  
LISTEN      0      128                            :::22                                         :::*                  
LISTEN      0      128                           ::1:631                                        :::*                  
LISTEN      0      100                           ::1:25                                         :::*                  
LISTEN      0      128                            :::111                                        :::*                  
LISTEN      0      128                            :::80                                         :::*                  
LISTEN      0      128                            :::4369                                       :::*                  
[root@node1 ~]# 

  提示:rabbitmqctl stop_app這個命令只是停止rabbitmq上的應用,而非停止rabbitmq服務;所以監聽的埠資訊都還在;rabbitmqctl status是檢視rabbitmq的狀態資訊;

  start_app:啟動已有應用;

[root@node1 ~]# rabbitmqctl status
Status of node rabbit@node1 ...
[{pid,18223},
 {running_applications,[{xmerl,"XML parser","1.3.6"},
                        {sasl,"SASL  CXC 138 11","2.3.4"},
                        {stdlib,"ERTS  CXC 138 10","1.19.4"},
                        {kernel,"ERTS  CXC 138 10","2.16.4"}]},
 {os,{unix,linux}},
 {erlang_version,"Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:30] [hipe] [kernel-poll:true]\n"},
 {memory,[{total,35564488},
          {connection_procs,0},
          {queue_procs,0},
          {plugins,0},
          {other_proc,13299600},
          {mnesia,0},
          {mgmt_db,0},
          {msg_index,0},
          {other_ets,607888},
          {binary,12600},
          {code,16707498},
          {atom,602729},
          {other_system,4334173}]},
 {alarms,[]},
 {listeners,[]},
 {processes,[{limit,1048576},{used,46}]},
 {run_queue,0},
 {uptime,495}]
...done.
[root@node1 ~]# rabbitmqctl start_app
Starting node rabbit@node1 ...
...done.
[root@node1 ~]# rabbitmqctl status   
Status of node rabbit@node1 ...
[{pid,18223},
 {running_applications,[{rabbit,"RabbitMQ","3.3.5"},
                        {os_mon,"CPO  CXC 138 46","2.2.14"},
                        {mnesia,"MNESIA  CXC 138 12","4.11"},
                        {xmerl,"XML parser","1.3.6"},
                        {sasl,"SASL  CXC 138 11","2.3.4"},
                        {stdlib,"ERTS  CXC 138 10","1.19.4"},
                        {kernel,"ERTS  CXC 138 10","2.16.4"}]},
 {os,{unix,linux}},
 {erlang_version,"Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:30] [hipe] [kernel-poll:true]\n"},
 {memory,[{total,36211968},
          {connection_procs,2800},
          {queue_procs,5600},
          {plugins,0},
          {other_proc,13678784},
          {mnesia,60144},
          {mgmt_db,0},
          {msg_index,21928},
          {other_ets,756792},
          {binary,19048},
          {code,16707530},
          {atom,602729},
          {other_system,4356613}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,1581588480},
 {disk_free_limit,50000000},
 {disk_free,39833972736},
 {file_descriptors,[{total_limit,924},
                    {total_used,3},
                    {sockets_limit,829},
                    {sockets_used,1}]},
 {processes,[{limit,1048576},{used,127}]},
 {run_queue,0},
 {uptime,513}]
...done.
[root@node1 ~]# 

  提示:可以看到application中多了mnesia,rabbit,os_mon這3個app的資訊;

  reset:重置;

  force_reset:強制重置;

  使用者管理相關子命令

    list_users:檢視使用者列表;

[root@node1 ~]# rabbitmqctl list_users
Listing users ...
guest   [administrator]
...done.
[root@node1 ~]# 

  提示:預設只有grest使用者,這個使用者的標籤是administrator,表示這是一個管理員;

    add_user <username> <password>:新增使用者;

[root@node1 ~]# rabbitmqctl add_user qiuhom test
Creating user "qiuhom" ...
...done.
[root@node1 ~]# rabbitmqctl list_users          
Listing users ...
guest   [administrator]
qiuhom  []
...done.
[root@node1 ~]# 

  提示:新增使用者必須指定使用者名稱和密碼;預設新增到使用者都是普通使用者,就是沒有任何標籤的使用者;

    delete_user <username>:刪除指定使用者;

[root@node1 ~]# rabbitmqctl delete_user qiuhom
Deleting user "qiuhom" ...
...done.
[root@node1 ~]# rabbitmqctl list_users        
Listing users ...
guest   [administrator]
...done.
[root@node1 ~]# 

  提示:刪除使用者只需指定使用者名稱即可;

    change_password <username> <newpassword>:修改指定使用者密碼;

[root@node1 ~]# rabbitmqctl change_password guest admin
Changing password for user "guest" ...
...done.
[root@node1 ~]# 

  提示:以上表示修改guest使用者的命名為admin;如果我們開啟了web管理介面就可以來測試guest使用者的密碼,如果使用admin能夠登入到管理介面說明密碼修改成功了,不能說明沒有修改成功,guest使用者的預設密碼是guest;

  驗證:開啟rabbitmq-management外掛,看看對應guest使用者的密碼是否更改了?

[root@node1 ~]# rabbitmq-plugins list
[ ] amqp_client                       3.3.5
[ ] cowboy                            0.5.0-rmq3.3.5-git4b93c2d
[ ] eldap                             3.3.5-gite309de4
[ ] mochiweb                          2.7.0-rmq3.3.5-git680dba8
[ ] rabbitmq_amqp1_0                  3.3.5
[ ] rabbitmq_auth_backend_ldap        3.3.5
[ ] rabbitmq_auth_mechanism_ssl       3.3.5
[ ] rabbitmq_consistent_hash_exchange 3.3.5
[ ] rabbitmq_federation               3.3.5
[ ] rabbitmq_federation_management    3.3.5
[ ] rabbitmq_management               3.3.5
[ ] rabbitmq_management_agent         3.3.5
[ ] rabbitmq_management_visualiser    3.3.5
[ ] rabbitmq_mqtt                     3.3.5
[ ] rabbitmq_shovel                   3.3.5
[ ] rabbitmq_shovel_management        3.3.5
[ ] rabbitmq_stomp                    3.3.5
[ ] rabbitmq_test                     3.3.5
[ ] rabbitmq_tracing                  3.3.5
[ ] rabbitmq_web_dispatch             3.3.5
[ ] rabbitmq_web_stomp                3.3.5
[ ] rabbitmq_web_stomp_examples       3.3.5
[ ] sockjs                            0.3.4-rmq3.3.5-git3132eb9
[ ] webmachine                        1.10.3-rmq3.3.5-gite9359c7
[root@node1 ~]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  mochiweb
  webmachine
  rabbitmq_web_dispatch
  amqp_client
  rabbitmq_management_agent
  rabbitmq_management
Plugin configuration has changed. Restart RabbitMQ for changes to take effect.
[root@node1 ~]# rabbitmq-plugins list
[e] amqp_client                       3.3.5
[ ] cowboy                            0.5.0-rmq3.3.5-git4b93c2d
[ ] eldap                             3.3.5-gite309de4
[e] mochiweb                          2.7.0-rmq3.3.5-git680dba8
[ ] rabbitmq_amqp1_0                  3.3.5
[ ] rabbitmq_auth_backend_ldap        3.3.5
[ ] rabbitmq_auth_mechanism_ssl       3.3.5
[ ] rabbitmq_consistent_hash_exchange 3.3.5
[ ] rabbitmq_federation               3.3.5
[ ] rabbitmq_federation_management    3.3.5
[E] rabbitmq_management               3.3.5
[e] rabbitmq_management_agent         3.3.5
[ ] rabbitmq_management_visualiser    3.3.5
[ ] rabbitmq_mqtt                     3.3.5
[ ] rabbitmq_shovel                   3.3.5
[ ] rabbitmq_shovel_management        3.3.5
[ ] rabbitmq_stomp                    3.3.5
[ ] rabbitmq_test                     3.3.5
[ ] rabbitmq_tracing                  3.3.5
[e] rabbitmq_web_dispatch             3.3.5
[ ] rabbitmq_web_stomp                3.3.5
[ ] rabbitmq_web_stomp_examples       3.3.5
[ ] sockjs                            0.3.4-rmq3.3.5-git3132eb9
[e] webmachine                        1.10.3-rmq3.3.5-gite9359c7
[root@node1 ~]# 

  提示:啟用外掛需要用rabbitmq-plugins命令,enable表示啟用指定外掛,disable表示禁用指定外掛,list表示列出外掛列表;其中列出外掛列表前邊中括號中的大寫E表示手動開啟的外掛,小寫e表示手動開啟外掛依賴的外掛,自動開啟的;

  重啟rabbitmq-server服務

  提示:啟用了外掛,必須要重啟服務才能夠正常使用外掛,從上的資訊可以看到我們啟用了rabbitmq-mangement外掛,重啟rabbitmq-server服務後,對應的15672埠就處於監聽狀態了;

  登入宿主機的15672埠,訪問web管理介面

  提示:用guest使用者使用admin密碼是能夠登入到管理介面,說明我們更改密碼成功了;其實很多命令列能夠管理的,我們都可以基於這個web管理介面進行管理;

    set_user_tags <username> <tag> ...:設定指定使用者的標籤;

[root@node1 ~]# rabbitmqctl add_user qiuhom test
Creating user "qiuhom" ...
...done.
[root@node1 ~]# rabbitmqctl list_users
Listing users ...
guest   [administrator]
qiuhom  []
...done.
[root@node1 ~]# rabbitmqctl set_user_tags qiuhom administrator
Setting tags for user "qiuhom" to [administrator] ...
...done.
[root@node1 ~]# rabbitmqctl list_users
Listing users ...
guest   [administrator]
qiuhom  [administrator]
...done.
[root@node1 ~]# rabbitmqctl set_user_tags qiuhom 
Setting tags for user "qiuhom" to [] ...
...done.
[root@node1 ~]# rabbitmqctl list_users           
Listing users ...
guest   [administrator]
qiuhom  []
...done.
[root@node1 ~]# 

  提示:如果使用者名稱後面不指定任何標籤,相當於把原有的標籤資訊清空;標籤為administrator的使用者擁有登入web管理介面的許可權;

    clear_password <username>:清空指定使用者的密碼;

[root@node1 ~]# rabbitmqctl clear_password qiuhom
Clearing password for user "qiuhom" ...
...done.
[root@node1 ~]#

  虛擬主機相關管理子命令

    list_vhosts [<vhostinfoitem> ...]:列出虛擬主機列表;

[root@node1 ~]# rabbitmqctl list_vhosts
Listing vhosts ...
/
...done.
[root@node1 ~]#

  提示:預設只有“/”這個虛擬主機;

    add_vhost <vhostpath>:新增虛擬主機;

[root@node1 ~]# rabbitmqctl add_vhost /qiuhom/test
Creating vhost "/qiuhom/test" ...
...done.
[root@node1 ~]# rabbitmqctl list_vhosts           
Listing vhosts ...
/
/qiuhom/test
...done.
[root@node1 ~]# 

    delete_vhost <vhostpath>:刪除虛擬主機;

[root@node1 ~]# rabbitmqctl delete_vhost /qiuhom/test
Deleting vhost "/qiuhom/test" ...
...done.
[root@node1 ~]# rabbitmqctl list_vhosts              
Listing vhosts ...
/
...done.
[root@node1 ~]# 

  許可權相關管理子命令

    list_permissions [-p <vhostpath>]:列出指定虛擬主機許可權,不指定表示檢視預設虛擬主機的許可權(這個是以虛擬主機檢視許可權);

[root@node1 ~]# rabbitmqctl list_permissions
Listing permissions in vhost "/" ...
guest   .*      .*      .*
...done.
[root@node1 ~]# rabbitmqctl add_vhost /qiuhom/test
Creating vhost "/qiuhom/test" ...
...done.
[root@node1 ~]# rabbitmqctl list_permissions      
Listing permissions in vhost "/" ...
guest   .*      .*      .*
...done.
[root@node1 ~]# rabbitmqctl list_permissions -p /qiuhom/test
Listing permissions in vhost "/qiuhom/test" ...
...done.
[root@node1 ~]# 

  提示:預設虛擬主機上“/”,guest使用者對“/”這個虛擬主機以下的所有元件有訪問許可權;其中第一個.*表示配置檔案,第二個.*表示寫許可權,第三個是讀許可權;

    list_user_permissions <username>:列出指定使用者的許可權(能夠對那些虛擬主機進行哪些操作,這個是以使用者名稱去檢視許可權)

[root@node1 ~]# rabbitmqctl list_user_permissions guest
Listing permissions for user "guest" ...
/       .*      .*      .*
...done.
[root@node1 ~]# 

  提示:以上表示檢視guest這個使用者所有虛擬主機上的許可權;這裡需要注意一點虛擬主機都是以/開始的樹狀結構,且支援繼承,所謂繼承就表示一某個虛擬主機開始一下所有子虛擬主機都有相同的許可權;以上guest就對所有虛擬主機有訪問許可權;

    set_permissions [-p <vhostpath>] <user> <conf> <write> <read>:設定許可權,不指定虛擬主機表示給預設虛擬主機設定許可權;

[root@node1 ~]# rabbitmqctl list_users
Listing users ...
guest   [administrator]
qiuhom  []
...done.
[root@node1 ~]# rabbitmqctl list_vhosts
Listing vhosts ...
/
/qiuhom/test
...done.
[root@node1 ~]# rabbitmqctl set_permissions qiuhom ".*" ".*" ".*"  
Setting permissions for user "qiuhom" in vhost "/" ...
...done.
[root@node1 ~]# rabbitmqctl list_permissions  
Listing permissions in vhost "/" ...
guest   .*      .*      .*
qiuhom  .*      .*      .*
...done.
[root@node1 ~]# rabbitmqctl set_permissions -p /qiuhom/test qiuhom ".*" ".*" ".*"
Setting permissions for user "qiuhom" in vhost "/qiuhom/test" ...
...done.
[root@node1 ~]# rabbitmqctl list_permissions                                     
Listing permissions in vhost "/" ...
guest   .*      .*      .*
qiuhom  .*      .*      .*
...done.
[root@node1 ~]#rabbitmqctl list_permissions  -p /qiuhom/test
Listing permissions in vhost "/qiuhom/test" ...
qiuhom  .*      .*      .*
...done.
[root@node1 ~]# 

    clear_permissions [-p <vhostpath>] <username>:清空指定使用者對某虛擬主機的許可權,預設不指定虛擬主機表示預設虛擬主機;

[root@node1 ~]# rabbitmqctl list_permissions  -p /qiuhom/test
Listing permissions in vhost "/qiuhom/test" ...
qiuhom  .*      .*      .*
...done.
[root@node1 ~]# rabbitmqctl list_user_permissions  qiuhom    
Listing permissions for user "qiuhom" ...
/       .*      .*      .*
/qiuhom/test    .*      .*      .*
...done.
[root@node1 ~]# rabbitmqctl clear_permissions -p / qiuhom
Clearing permissions for user "qiuhom" in vhost "/" ...
...done.
[root@node1 ~]# rabbitmqctl list_user_permissions  qiuhom    
Listing permissions for user "qiuhom" ...
/qiuhom/test    .*      .*      .*
...done.
[root@node1 ~]# rabbitmqctl list_permissions  -p /
Listing permissions in vhost "/" ...
guest   .*      .*      .*
...done.
[root@node1 ~]# rabbitmqctl clear_permissions -p /qiuhom/test qiuhom 
Clearing permissions for user "qiuhom" in vhost "/qiuhom/test" ...
...done.
[root@node1 ~]# rabbitmqctl list_permissions  -p /qiuhom/test       
Listing permissions in vhost "/qiuhom/test" ...
...done.
[root@node1 ~]# 

  元件檢視類子命令

    list_queues [-p <vhostpath>] [<queueinfoitem> ...]:列出佇列;

[root@node1 ~]# rabbitmqctl list_queues     
Listing queues ...
...done.
[root@node1 ~]#

    list_exchanges [-p <vhostpath>] [<exchangeinfoitem> ...]:列出交換器;

[root@node1 ~]# rabbitmqctl list_exchanges  
Listing exchanges ...
        direct
amq.direct      direct
amq.fanout      fanout
amq.headers     headers
amq.match       headers
amq.rabbitmq.log        topic
amq.rabbitmq.trace      topic
amq.topic       topic
...done.
[root@node1 ~]#

    list_bindings [-p <vhostpath>] [<bindinginfoitem> ...]:列出繫結器;

[root@node1 ~]# rabbitmqctl list_bindings   
Listing bindings ...
...done.
[root@node1 ~]#

    list_connections [<connectioninfoitem> ...]:列出連線列表

[root@node1 ~]# rabbitmqctl list_connections
Listing connections ...
...done.
[root@node1 ~]# 

    list_channels [<channelinfoitem> ...]:列出頻道

[root@node1 ~]# rabbitmqctl list_channels   
Listing channels ...
...done.
[root@node1 ~]#

  提示:上面這些元件我們除了可以在命令列通過子命令的方式檢視,其實在web管理介面也給我們提供了一個api訪問介面;

  在web介面訪問api介面檢視虛擬主機

  在web介面檢視使用者列表

  提示:需要檢視某類元件的資訊,可以在api後面加上對應元件的名稱作為rui即可訪問,當然有了這個api介面,程式設計師就可以呼叫這個介面從而對rabbitmq進行操作;具體操作文件可訪問對應宿主機的15672/api檢視示例;

    list_consumers [-p <vhostpath>]:列出消費者

[root@node1 ~]# rabbitmqctl list_consumers  
Listing consumers ...
...done.
[root@node1 ~]# 

    status:檢視rabbitmq的狀態資訊;

[root@node1 ~]# rabbitmqctl status
Status of node rabbit@node1 ...
[{pid,20202},
 {running_applications,
     [{rabbitmq_management,"RabbitMQ Management Console","3.3.5"},
      {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.3.5"},
      {webmachine,"webmachine","1.10.3-rmq3.3.5-gite9359c7"},
      {mochiweb,"MochiMedia Web Server","2.7.0-rmq3.3.5-git680dba8"},
      {rabbitmq_management_agent,"RabbitMQ Management Agent","3.3.5"},
      {rabbit,"RabbitMQ","3.3.5"},
      {os_mon,"CPO  CXC 138 46","2.2.14"},
      {inets,"INETS  CXC 138 49","5.9.8"},
      {mnesia,"MNESIA  CXC 138 12","4.11"},
      {amqp_client,"RabbitMQ AMQP Client","3.3.5"},
      {xmerl,"XML parser","1.3.6"},
      {sasl,"SASL  CXC 138 11","2.3.4"},
      {stdlib,"ERTS  CXC 138 10","1.19.4"},
      {kernel,"ERTS  CXC 138 10","2.16.4"}]},
 {os,{unix,linux}},
 {erlang_version,
     "Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:30] [hipe] [kernel-poll:true]\n"},
 {memory,
     [{total,40816096},
      {connection_procs,5600},
      {queue_procs,5600},
      {plugins,432624},
      {other_proc,13494248},
      {mnesia,64144},
      {mgmt_db,45376},
      {msg_index,34528},
      {other_ets,1085424},
      {binary,119600},
      {code,20229052},
      {atom,711569},
      {other_system,4588331}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,1581588480},
 {disk_free_limit,50000000},
 {disk_free,39831085056},
 {file_descriptors,
     [{total_limit,924},{total_used,3},{sockets_limit,829},{sockets_used,1}]},
 {processes,[{limit,1048576},{used,181}]},
 {run_queue,0},
 {uptime,5271}]
...done.
[root@node1 ~]# 

    environment:檢視環境變數;

[root@node1 ~]# rabbitmqctl environment
Application environment of node rabbit@node1 ...
[{auth_backends,[rabbit_auth_backend_internal]},
 {auth_mechanisms,['PLAIN','AMQPLAIN']},
 {backing_queue_module,rabbit_variable_queue},
 {channel_max,0},
 {channel_operation_timeout,70000},
 {cluster_nodes,{[],disc}},
 {cluster_partition_handling,ignore},
 {collect_statistics,fine},
 {collect_statistics_interval,5000},
 {default_permissions,[<<".*">>,<<".*">>,<<".*">>]},
 {default_user,<<"guest">>},
 {default_user_tags,[administrator]},
 {default_vhost,<<"/">>},
 {delegate_count,16},
 {disk_free_limit,50000000},
 {enabled_plugins_file,"/etc/rabbitmq/enabled_plugins"},
 {error_logger,{file,"/var/log/rabbitmq/rabbit@node1.log"}},
 {frame_max,131072},
 {halt_on_upgrade_failure,true},
 {heartbeat,580},
 {hipe_compile,false},
 {hipe_modules,[rabbit_reader,rabbit_channel,gen_server2,rabbit_exchange,
                rabbit_command_assembler,rabbit_framing_amqp_0_9_1,
                rabbit_basic,rabbit_event,lists,queue,priority_queue,
                rabbit_router,rabbit_trace,rabbit_misc,rabbit_binary_parser,
                rabbit_exchange_type_direct,rabbit_guid,rabbit_net,
                rabbit_amqqueue_process,rabbit_variable_queue,
                rabbit_binary_generator,rabbit_writer,delegate,gb_sets,lqueue,
                sets,orddict,rabbit_amqqueue,rabbit_limiter,gb_trees,
                rabbit_queue_index,rabbit_exchange_decorator,gen,dict,ordsets,
                file_handle_cache,rabbit_msg_store,array,
                rabbit_msg_store_ets_index,rabbit_msg_file,
                rabbit_exchange_type_fanout,rabbit_exchange_type_topic,mnesia,
                mnesia_lib,rpc,mnesia_tm,qlc,sofs,proplists,credit_flow,pmon,
                ssl_connection,tls_connection,ssl_record,tls_record,gen_fsm,
                ssl]},
 {included_applications,[]},
 {log_levels,[{connection,info}]},
 {loopback_users,[]},
 {msg_store_file_size_limit,16777216},
 {msg_store_index_module,rabbit_msg_store_ets_index},
 {plugins_dir,"/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/sbin/../plugins"},
 {plugins_expand_dir,"/var/lib/rabbitmq/mnesia/rabbit@node1-plugins-expand"},
 {queue_index_max_journal_entries,65536},
 {reverse_dns_lookups,false},
 {sasl_error_logger,{file,"/var/log/rabbitmq/rabbit@node1-sasl.log"}},
 {server_properties,[]},
 {ssl_apps,[asn1,crypto,public_key,ssl]},
 {ssl_cert_login_from,distinguished_name},
 {ssl_listeners,[]},
 {ssl_options,[]},
 {tcp_listen_options,[binary,
                      {packet,raw},
                      {reuseaddr,true},
                      {backlog,128},
                      {nodelay,true},
                      {linger,{true,0}},
                      {exit_on_close,false}]},
 {tcp_listeners,[5672]},
 {trace_vhosts,[]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_high_watermark_paging_ratio,0.5}]
...done.
[root@node1 ~]# 

    report:生成系統狀態報告;

[root@node1 ~]# rabbitmqctl report
Reporting server status on {{2020,8,25},{16,18,8}}

 ...
Status of node rabbit@node1 ...
[{pid,20202},
 {running_applications,
     [{rabbitmq_management,"RabbitMQ Management Console","3.3.5"},
      {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.3.5"},
      {webmachine,"webmachine","1.10.3-rmq3.3.5-gite9359c7"},
      {mochiweb,"MochiMedia Web Server","2.7.0-rmq3.3.5-git680dba8"},
      {rabbitmq_management_agent,"RabbitMQ Management Agent","3.3.5"},
      {rabbit,"RabbitMQ","3.3.5"},
      {os_mon,"CPO  CXC 138 46","2.2.14"},
      {inets,"INETS  CXC 138 49","5.9.8"},
      {mnesia,"MNESIA  CXC 138 12","4.11"},
      {amqp_client,"RabbitMQ AMQP Client","3.3.5"},
      {xmerl,"XML parser","1.3.6"},
      {sasl,"SASL  CXC 138 11","2.3.4"},
      {stdlib,"ERTS  CXC 138 10","1.19.4"},
      {kernel,"ERTS  CXC 138 10","2.16.4"}]},
 {os,{unix,linux}},
 {erlang_version,
     "Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:30] [hipe] [kernel-poll:true]\n"},
 {memory,
     [{total,40510448},
      {connection_procs,5600},
      {queue_procs,5600},
      {plugins,208520},
      {other_proc,13407608},
      {mnesia,64144},
      {mgmt_db,50256},
      {msg_index,34528},
      {other_ets,1085424},
      {binary,119648},
      {code,20229052},
      {atom,711569},
      {other_system,4588499}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,1581588480},
 {disk_free_limit,50000000},
 {disk_free,39831064576},
 {file_descriptors,
     [{total_limit,924},{total_used,3},{sockets_limit,829},{sockets_used,1}]},
 {processes,[{limit,1048576},{used,181}]},
 {run_queue,0},
 {uptime,5347}]

Cluster status of node rabbit@node1 ...
[{nodes,[{disc,[rabbit@node1]}]},
 {running_nodes,[rabbit@node1]},
 {cluster_name,<<"rabbit@node1">>},
 {partitions,[]}]

Application environment of node rabbit@node1 ...
[{auth_backends,[rabbit_auth_backend_internal]},
 {auth_mechanisms,['PLAIN','AMQPLAIN']},
 {backing_queue_module,rabbit_variable_queue},
 {channel_max,0},
 {channel_operation_timeout,70000},
 {cluster_nodes,{[],disc}},
 {cluster_partition_handling,ignore},
 {collect_statistics,fine},
 {collect_statistics_interval,5000},
 {default_permissions,[<<".*">>,<<".*">>,<<".*">>]},
 {default_user,<<"guest">>},
 {default_user_tags,[administrator]},
 {default_vhost,<<"/">>},
 {delegate_count,16},
 {disk_free_limit,50000000},
 {enabled_plugins_file,"/etc/rabbitmq/enabled_plugins"},
 {error_logger,{file,"/var/log/rabbitmq/rabbit@node1.log"}},
 {frame_max,131072},
 {halt_on_upgrade_failure,true},
 {heartbeat,580},
 {hipe_compile,false},
 {hipe_modules,[rabbit_reader,rabbit_channel,gen_server2,rabbit_exchange,
                rabbit_command_assembler,rabbit_framing_amqp_0_9_1,
                rabbit_basic,rabbit_event,lists,queue,priority_queue,
                rabbit_router,rabbit_trace,rabbit_misc,rabbit_binary_parser,
                rabbit_exchange_type_direct,rabbit_guid,rabbit_net,
                rabbit_amqqueue_process,rabbit_variable_queue,
                rabbit_binary_generator,rabbit_writer,delegate,gb_sets,lqueue,
                sets,orddict,rabbit_amqqueue,rabbit_limiter,gb_trees,
                rabbit_queue_index,rabbit_exchange_decorator,gen,dict,ordsets,
                file_handle_cache,rabbit_msg_store,array,
                rabbit_msg_store_ets_index,rabbit_msg_file,
                rabbit_exchange_type_fanout,rabbit_exchange_type_topic,mnesia,
                mnesia_lib,rpc,mnesia_tm,qlc,sofs,proplists,credit_flow,pmon,
                ssl_connection,tls_connection,ssl_record,tls_record,gen_fsm,
                ssl]},
 {included_applications,[]},
 {log_levels,[{connection,info}]},
 {loopback_users,[]},
 {msg_store_file_size_limit,16777216},
 {msg_store_index_module,rabbit_msg_store_ets_index},
 {plugins_dir,"/usr/lib/rabbitmq/lib/rabbitmq_server-3.3.5/sbin/../plugins"},
 {plugins_expand_dir,"/var/lib/rabbitmq/mnesia/rabbit@node1-plugins-expand"},
 {queue_index_max_journal_entries,65536},
 {reverse_dns_lookups,false},
 {sasl_error_logger,{file,"/var/log/rabbitmq/rabbit@node1-sasl.log"}},
 {server_properties,[]},
 {ssl_apps,[asn1,crypto,public_key,ssl]},
 {ssl_cert_login_from,distinguished_name},
 {ssl_listeners,[]},
 {ssl_options,[]},
 {tcp_listen_options,[binary,
                      {packet,raw},
                      {reuseaddr,true},
                      {backlog,128},
                      {nodelay,true},
                      {linger,{true,0}},
                      {exit_on_close,false}]},
 {tcp_listeners,[5672]},
 {trace_vhosts,[]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_high_watermark_paging_ratio,0.5}]

Connections:

Channels:

Queues on /qiuhom/test:

Queues on /:

Exchanges on /qiuhom/test:
name    type    durable auto_delete     internal        arguments       policy
        direct  true    false   false   []
amq.direct      direct  true    false   false   []
amq.fanout      fanout  true    false   false   []
amq.headers     headers true    false   false   []
amq.match       headers true    false   false   []
amq.rabbitmq.trace      topic   true    false   true    []
amq.topic       topic   true    false   false   []

Exchanges on /:
name    type    durable auto_delete     internal        arguments       policy
        direct  true    false   false   []
amq.direct      direct  true    false   false   []
amq.fanout      fanout  true    false   false   []
amq.headers     headers true    false   false   []
amq.match       headers true    false   false   []
amq.rabbitmq.log        topic   true    false   true    []
amq.rabbitmq.trace      topic   true    false   true    []
amq.topic       topic   true    false   false   []

Bindings on /qiuhom/test:

Bindings on /:

Consumers on /qiuhom/test:

Consumers on /:

Permissions on /qiuhom/test:

Permissions on /:
user    configure       write   read
guest   .*      .*      .*

Policies on /qiuhom/test:

Policies on /:

Parameters on /qiuhom/test:

Parameters on /:

...done.
[root@node1 ~]# 

  策略相關管理子命令

    list_policies [-p <vhostpath>]:列出指定虛擬主機的策略;預設不指定是列出預設虛擬主機;

    set_policy [-p <vhostpath>] [--priority <priority>] [--apply-to <apply-to>] <name> <pattern> <definition>:對指定虛擬主機設定策略,沒有指定虛擬主機表示預設虛擬主機;

    clear_policy [-p <vhostpath>] <name>:清楚指定虛擬主機的策略,沒有指定虛擬主機表示對預設虛擬主機操作;

  叢集相關子命令

    join_cluster <clusternode> [--ram]:加入指定節點叢集;

    cluster_status:檢視叢集狀態

    change_cluster_node_type disc | ram:更改節點儲存型別,disc表示磁碟,ram表示記憶體;一個叢集中必須有一個節點為disc型別;

    forget_cluster_node [--offline]:離開叢集;

    update_cluster_nodes clusternode:更新叢集節點;

    sync_queue queue:同步指定佇列;

    cancel_sync_queue queue:取消指定佇列同步

    set_cluster_name name:設定叢集名稱;

  設定引數相關子命令

    list_parameters [-p <vhostpath>]:檢視指定虛擬主機執行時引數配置,預設不指定虛擬主機,表示檢視預設虛擬主機的引數配置;

    set_parameter [-p <vhostpath>] <component_name> <name> <value>:設定指定引數的配置;不指定虛擬主機表示操作預設虛擬主機;

    clear_parameter [-p <vhostpath>] <component_name> <key>:刪除指定配置項;

  其他子命令

    eval <expr>:執行erlang表示式

    close_connection <connectionpid> <explanation>:關閉指定連線;

    trace_on [-p <vhost>]:開啟指定虛擬主機的追蹤功能;

    trace_off [-p <vhost>]:關閉指定虛擬主機的追蹤功能;

    set_vm_memory_high_watermark <fraction>:設定記憶體高水位標記;

  以上就是rabbitmq的簡單介紹和安裝配置相關引數的說明,以及rabbitmqctl這個工具的常用子命令的用法;

相關文章