面試官:如何用rabbitmqctl來管理和監控RabbitMQ?

概述

MQ全稱為Message Queue, 消息隊列(MQ)是一種應用程序對應用程序的通信方法。應用程序通過讀寫出入隊列的消息(針對應用程序的數據)來通信,而無需專用連接來鏈接它們。消息傳遞指的是程序之間通過在消息中發送數據進行通信,而不是通過直接調用彼此來通信,直接調用通常是用於諸如遠程過程調用的技術。排隊指的是應用程序通過 隊列來通信。隊列的使用除去了接收和發送應用程序同時執行的要求。

rabbitmq的管理功能最全的就是rabbitmqctl命令了,當然還有HTTP API和UI兩種管理手段。


一、rabbitmqctl語法

rabbitmqctl [-n <node>] [-q] <command> [<command>]/<command>/<command>/<node>

-n node 默認node名稱是"rabbit@server",如果你的主機明是'server.example.com',那麼node名稱是'rabbit@server'。

-q 安靜輸出模式,信息會被禁止輸出


二、命令用法

1、基本的管理功能

<code>join_cluster <clusternode> [--ram]      #clusternode表示node名稱,--ram表示node以ram node加入集群中。默認node以disc node加入集群,在一個node加入cluster之前,必須先停止該node的rabbitmq應用,即先執行stop_app。cluster_status      #顯示cluster中的所有nodechange_cluster_node_type disc | ram      #改變一個cluster中node的模式,該節點在轉換前必須先停止,不能把一個集群中唯一的disk node轉化為ram nodeforget_cluster_node [--offline]      #遠程移除cluster中的一個node,前提是該node必須處於offline狀態,如果是online狀態,則需要加--offline參數。update_cluster_nodes clusternode       #sync_queue queue      #同步鏡像隊列cancel_sync_queue queue/<clusternode>/<code>


2、cluster管理

<code>add_user <username> <password>      #在rabbitmq的內部數據庫添加用戶delete_user <username>      #刪除一個用戶change_password <username> <newpassword>      #改變用戶密碼  \\\\改變web管理登陸密碼clear_password <username>     #清除用戶密碼,禁止用戶登錄set_user_tags <username>  
... #設置用戶tagslist_users #列出用戶add_vhost <vhostpath> #創建一個vhostsdelete_vhost <vhostpath> #刪除一個vhostslist_vhosts [<vhostinfoitem> ...] #列出vhostsset_permissions [-p <vhostpath>] <user> <conf> <write> <read> #針對一個vhosts 給用戶賦予相關權限clear_permissions [-p <vhostpath>] <username> #清除一個用戶對vhosts的權限list_permissions [-p <vhostpath>] #列出哪些用戶可以訪問該vhostslist_user_permissions <username> #列出該用戶的訪問權限set_parameter [-p <vhostpath>] <component> <name> <value> #clear_parameter [-p <vhostpath>] <component> #list_parameters [-p <vhostpath>] #/<vhostpath>/<component>/<vhostpath>/<value>/<name>/<component>/<vhostpath>/<username>/<vhostpath>/<username>/<vhostpath>/<read>/<write>/<conf>/<user>/<vhostpath>/<vhostinfoitem>/<vhostpath>/<vhostpath>/<username>/<username>/<newpassword>/<username>/<username>/<password>/<username>/<code>


3、用戶管理

<code>set_policy [-p <vhostpath>] [--priority <priority>] [--apply-to <apply-to>]  <name> <pattern> <definition>        #name 策略名稱,pattern  正則表達式,用來匹配資源,符合的就會應用設置的策略,apply-to 表示策略應用到什麼類型的地方,一般有queues、exchange和all,默認是all。priority 是個整數優先級,definition 是json格式設置的策略。clear_policy [-p <vhostpath>] <name>      #清除一個策略list_policies [-p <vhostpath>]      #列出已有的策略/<vhostpath>/<name>/<vhostpath>/<definition>/<pattern>/<name>/<apply-to>/<priority>/<vhostpath>/<code>


4、policy管理,策略用來控制和修改queues和exchange在集群中的行為,策略可以應用到vhost

<code>set_policy [-p <vhostpath>] [--priority <priority>] [--apply-to <apply-to>]  <name> <pattern> <definition>        #name 策略名稱,pattern  正則表達式,用來匹配資源,符合的就會應用設置的策略,apply-to 表示策略應用到什麼類型的地方,一般有queues、exchange和all,默認是all。priority 是個整數優先級,definition 是json格式設置的策略。clear_policy [-p <vhostpath>] <name>      #清除一個策略list_policies [-p <vhostpath>]      #列出已有的策略/<vhostpath>/<name>/<vhostpath>/<definition>/<pattern>/<name>/<apply-to>/<priority>/<vhostpath>/<code>


5、queues && exchange狀態信息

<code>list_queues [-p <vhostpath>] [<queueinfoitem> ...]      #返回queue的信息,如果省略了-p參數,則默認顯示的是"/"vhosts的信息。list_exchanges [-p <vhostpath>] [<exchangeinfoitem> ...]      #返回exchange的信息。list_bindings [-p <vhostpath>] [<bindinginfoitem> ...]     #返回綁定信息。list_connections [<connectioninfoitem> ...]      #返回鏈接信息。list_channels [<channelinfoitem> ...]      #返回目前所有的channels。list_consumers [-p <vhostpath>]      #返回consumers,status      #顯示broker的狀態environment      #顯示環境參數的信息report      #返回一個服務狀態report,eval <expr>/<vhostpath>/<channelinfoitem>/<connectioninfoitem>/<bindinginfoitem>/<vhostpath>/<exchangeinfoitem>/<vhostpath>/<queueinfoitem>/<vhostpath>/<code>



三、常用監控命令

1、查看虛擬主機

rabbitmqctl list_vhosts

2、查看隊列

rabbitmqctl list_queues

面試官:如何用rabbitmqctl來管理和監控RabbitMQ?


3、查看exchanges

rabbitmqctl list_exchanges

4、查看用戶

rabbitmqctl list_users

面試官:如何用rabbitmqctl來管理和監控RabbitMQ?


5、查看連接

rabbitmqctl list_connections

面試官:如何用rabbitmqctl來管理和監控RabbitMQ?

6、查看消費者信息

rabbitmqctl list_consumers

面試官:如何用rabbitmqctl來管理和監控RabbitMQ?

7、查看環境變量

rabbitmqctl environment

面試官:如何用rabbitmqctl來管理和監控RabbitMQ?


8、查看未被確認的隊列

rabbitmqctl list_queues name messages_unacknowledged

面試官:如何用rabbitmqctl來管理和監控RabbitMQ?


9、查看單個隊列的內存使用

rabbitmqctl list_queues name memory

面試官:如何用rabbitmqctl來管理和監控RabbitMQ?


10、查看準備就緒的隊列

rabbitmqctl list_queues name messages_ready

面試官:如何用rabbitmqctl來管理和監控RabbitMQ?



覺得有用的朋友多幫忙轉發哦!後面會分享更多devops和DBA方面的內容,感興趣的朋友可以關注下~

面試官:如何用rabbitmqctl來管理和監控RabbitMQ?


分享到:


相關文章: