一、万能帮助指令
<command> help
[root@localhost ~]# rabbitmqctl help
Usage
rabbitmqctl [--node <node>] [--timeout <timeout>] [--longnames] [--quiet] <command> [<command options>]
Available commands:
Help:
autocomplete Provides command name autocomplete variants
help Displays usage information for a command
version Displays CLI tools version
Nodes:
await_startup Waits for the RabbitMQ application to start on the target node
reset Instructs a RabbitMQ node to leave the cluster and return to its virgin state
rotate_logs Does nothing [deprecated]
shutdown Stops RabbitMQ and its runtime (Erlang VM). Monitors progress for local nodes. Does not require a PID file path.
start_app Starts the RabbitMQ application but leaves the runtime (Erlang VM) running
stop Stops RabbitMQ and its runtime (Erlang VM). Requires a local node pid file path to monitor progress.
stop_app Stops the RabbitMQ application, leaving the runtime (Erlang VM) running
wait Waits for RabbitMQ node startup by monitoring a local PID file. See also 'rabbitmqctl await_online_nodes'
Cluster:
await_online_nodes Waits for <count> nodes to join the cluster
change_cluster_node_type Changes the type of the cluster node
cluster_status Displays all the nodes in the cluster grouped by node type, together with the currently running nodes
force_boot Forces node to start even if it cannot contact or rejoin any of its previously known peers
force_reset Forcefully returns a RabbitMQ node to its virgin state
forget_cluster_node Removes a node from the cluster
join_cluster Instructs the node to become a member of the cluster that the specified node is in
rename_cluster_node Renames cluster nodes in the local database
update_cluster_nodes Instructs a cluster member node to sync the list of known cluster members from <seed_node>
Replication:
cancel_sync_queue Instructs a synchronising mirrored queue to stop synchronising itself
sync_queue Instructs a mirrored queue with unsynchronised mirrors (follower replicas) to synchronise them
Users:
add_user Creates a new user in the internal database. This user will have no permissions for any virtual hosts by default.
authenticate_user Attempts to authenticate a user. Exits with a non-zero code if authentication fails.
change_password Changes the user password
clear_password Clears (resets) password and disables password login for a user
clear_user_limits Clears user connection/channel limits
delete_user Removes a user from the internal database. Has no effect on users provided by external backends such as LDAP
list_user_limits Displays configured user limits
list_users List user names and tags
set_user_limits Sets user limits
set_user_tags Sets user tags
Access Control:
clear_permissions Revokes user permissions for a vhost
clear_topic_permissions Clears user topic permissions for a vhost or exchange
list_permissions Lists user permissions in a virtual host
list_topic_permissions Lists topic permissions in a virtual host
list_user_permissions Lists permissions of a user across all virtual hosts
list_user_topic_permissions Lists user topic permissions
list_vhosts Lists virtual hosts
set_permissions Sets user permissions for a vhost
set_topic_permissions Sets user topic permissions for an exchange
Monitoring, observability and health checks:
list_bindings Lists all bindings on a vhost
list_channels Lists all channels in the node
list_ciphers Lists cipher suites supported by encoding commands
list_connections Lists AMQP 0.9.1 connections for the node
list_consumers Lists all consumers for a vhost
list_exchanges Lists exchanges
list_hashes Lists hash functions supported by encoding commands
list_node_auth_attempt_stats Lists authentication attempts on the target node
list_queues Lists queues and their properties
list_unresponsive_queues Tests queues to respond within timeout. Lists those which did not respond
ping Checks that the node OS process is up, registered with EPMD and CLI tools can authenticate with it
report Generate a server status report containing a concatenation of all server status information for support purposes
schema_info Lists schema database tables and their properties
status Displays status of a node
Parameters:
clear_global_parameter Clears a global runtime parameter
clear_parameter Clears a runtime parameter.
list_global_parameters Lists global runtime parameters
list_parameters Lists runtime parameters for a virtual host
set_global_parameter Sets a runtime parameter.
set_parameter Sets a runtime parameter.
Policies:
clear_operator_policy Clears an operator policy
clear_policy Clears (removes) a policy
list_operator_policies Lists operator policy overrides for a virtual host
list_policies Lists all policies in a virtual host
set_operator_policy Sets an operator policy that overrides a subset of arguments in user policies
set_policy Sets or updates a policy
Virtual hosts:
add_vhost Creates a virtual host
clear_vhost_limits Clears virtual host limits
delete_vhost Deletes a virtual host
list_vhost_limits Displays configured virtual host limits
restart_vhost Restarts a failed vhost data stores and queues
set_vhost_limits Sets virtual host limits
set_vhost_tags Sets virtual host tags
trace_off
trace_on
Configuration and Environment:
decode Decrypts an encrypted configuration value
encode Encrypts a sensitive configuration value
environment Displays the name and value of each variable in the application environment for each running application
set_cluster_name Sets the cluster name
set_disk_free_limit Sets the disk_free_limit setting
set_log_level Sets log level in the running node
set_vm_memory_high_watermark Sets the vm_memory_high_watermark setting
Definitions:
export_definitions Exports definitions in JSON or compressed Erlang Term Format.
import_definitions Imports definitions in JSON or compressed Erlang Term Format.
Feature flags:
enable_feature_flag Enables a feature flag or all supported feature flags on the target node
list_feature_flags Lists feature flags
Operations:
close_all_connections Instructs the broker to close all connections for the specified vhost or entire RabbitMQ node
close_all_user_connections Instructs the broker to close all connections of the specified user
close_connection Instructs the broker to close the connection associated with the Erlang process id
eval Evaluates a snippet of Erlang code on the target node
eval_file Evaluates a file that contains a snippet of Erlang code on the target node
exec Evaluates a snippet of Elixir code on the CLI node
force_gc Makes all Erlang processes on the target node perform/schedule a full sweep garbage collection
resume_listeners Resumes client connection listeners making them accept client connections again
suspend_listeners Suspends client connection listeners so that no new client connections are accepted
Queues:
delete_queue Deletes a queue
purge_queue Purges a queue (removes all messages in it)
Deprecated:
hipe_compile DEPRECATED. This command is a no-op. HiPE is no longer supported by modern Erlang versions
node_health_check DEPRECATED. Performs intrusive, opinionated health checks on a fully booted node. See https://www.rabbitmq.com/monitoring.html#health-checks instead
Use 'rabbitmqctl help <command>' to learn more about a specific command
二、rabbitmqctl
查看具体某一指令详情 rabbitmqctl help
[root@localhost ~]# rabbitmqctl help add_user
Usage
rabbitmqctl [--node <node>] [--longnames] [--quiet] add_user <username> <password>
Creates a new user in the internal database. This user will have no permissions for any virtual hosts by default..
Arguments and Options
<username>
Self-explanatory
<password>
Password this user will authenticate with. Use a blank string to disable password-based authentication.
Relevant Doc Guides
* https://rabbitmq.com/access-control.html
General Options
The following options are accepted by most or all commands.
short | long | description
-----------------|---------------|--------------------------------
-? | --help | displays command help
-n <node> | --node <node> | connect to node <node>
-l | --longnames | use long host names
-t | --timeout <n> | for commands that support it, operation timeout in seconds
-q | --quiet | suppress informational messages
-s | --silent | suppress informational messages
| and table header row
-p | --vhost | for commands that are scoped to a virtual host,
| | virtual host to use
| --formatter | alternative result formatter to use
| if supported: json, pretty_table, table, csv, erlang
not all commands support all (or any) alternative formatters.
1.用户相关
Users:
add_user Creates a new user in the internal database. This user will have no permissions for any virtual hosts by default.
authenticate_user Attempts to authenticate a user. Exits with a non-zero code if authentication fails.
change_password Changes the user password
clear_password Clears (resets) password and disables password login for a user
clear_user_limits Clears user connection/channel limits
delete_user Removes a user from the internal database. Has no effect on users provided by external backends such as LDAP
list_user_limits Displays configured user limits
list_users List user names and tags
set_user_limits Sets user limits
set_user_tags Sets user tags
添加用户
rabbitmqctl [--node <node>] [--longnames] [--quiet] add_user <username> <password>
[root@localhost ~]# rabbitmqctl add_user test test
Adding user "test" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
[root@localhost ~]#
校验用户密码
rabbitmqctl [--node <node>] [--longnames] [--quiet] authenticate_user <username> <password>
[root@localhost ~]# rabbitmqctl authenticate_user test test1
Authenticating user "test" ...
Success
修改用户密码
rabbitmqctl [--node <node>] [--longnames] [--quiet] authenticate_user <username> <password>
rabbitmqctl [--node <node>] [--longnames] [--quiet] change_password <username> <password>
[root@localhost ~]# rabbitmqctl change_password test test1
Changing password for user "test" ...
[root@localhost ~]#
清除用户密码
rabbitmqctl [--node <node>] [--longnames] [--quiet] clear_password <username>
[root@localhost ~]# rabbitmqctl clear_password test
Clearing password for user "test" ...
[root@localhost ~]#
显示所有用户
rabbitmqctl [--node <node>] [--longnames] [--quiet] list_users [--no-table-headers] [--timeout <timeout>]
[root@localhost ~]# rabbitmqctl list_users
Listing users ...
user tags
test []
guest [administrator]
[root@localhost ~]#
删除用户
rabbitmqctl [--node <node>] [--longnames] [--quiet] delete_user <username>
[root@localhost ~]# rabbitmqctl delete_user test
Deleting user "test" ...
[root@localhost ~]#
设置用户tag角色
- administrator 可登录管理控制台(启用management plugin的情况下),查看所有的信息,并且可以对用户、策略(policy)进行操作;
- monitoring 可登录管理控制台(启用management plugin的情况下),同时可以查看rabbitmq节点的相关信息(进程数、内存使用情况,磁盘使用情况等);
- policymaker 可以登录管理控制台(启用management plugin的情况下),同时可以对策略(policy)进行操作;
- management 仅可登录管理控制台(启用management plugin的情况下),无法看到节点信息,也无法对策略进行管理;
- 其他 无法登录管理控制台,通常就是普通的生产者和消费者。
rabbitmqctl [--node <node>] [--longnames] [--quiet] set_user_tags <username> <tag> [...]
[root@localhost ~]# rabbitmqctl set_user_tags test administrator management policymaker
Setting tags for user "test" to [administrator, management, policymaker] ...
[root@localhost ~]#
设置用户最大连接数和最大通道数
rabbitmqctl [--node <node>] [--longnames] [--quiet] set_user_limits <username> <definition>
<definition> JSON文档
[root@localhost ~]# rabbitmqctl set_user_limits test '{"max-channels": 100,"max-connections":1000}'
Setting user limits to "{"max-channels": 100,"max-connections":1000}" for user "test" ...
[root@localhost ~]#
查看用户最大连接数和最大通道数限制条件
rabbitmqctl [--node <node>] [--longnames] [--quiet] list_user_limits [--user <username>] [--global]
[root@localhost ~]# rabbitmqctl list_user_limits --user test
Listing limits for user "test" ...
{"max-channels":100,"max-connections":1000}
[root@localhost ~]#
清除用户最大连接数和最大通道数限制条件
rabbitmqctl [--node <node>] [--longnames] [--quiet] clear_user_limits <username> <limit_type> | all
Arguments and Options
<username>
Self-explanatory
<limit_type>
Limit type, must be max-connections or max-channels
[root@localhost ~]# rabbitmqctl clear_user_limits test all
Clearing all limits for user "test" ...
[root@localhost ~]#
2、虚拟主机相关
Virtual hosts:
add_vhost Creates a virtual host
clear_vhost_limits Clears virtual host limits
delete_vhost Deletes a virtual host
list_vhost_limits Displays configured virtual host limits
restart_vhost Restarts a failed vhost data stores and queues
set_vhost_limits Sets virtual host limits
set_vhost_tags Sets virtual host tags
trace_off
trace_on
添加虚拟机
rabbitmqctl [--node <node>] [--longnames] [--quiet] add_vhost <vhost> [--description <description> --tags "<tag1>,<tag2>,<...>"]
[root@localhost ~]# rabbitmqctl add_vhost /my_vhost
Adding vhost "/my_vhost" ...
[root@localhost ~]#
设置虚拟机最大连接数和最大队列
[root@localhost ~]# rabbitmqctl set_vhost_limits -p /my_vhost '{"max-connections": 10,"max-queues":100}'
Setting vhost limits to "{"max-connections": 10,"max-queues":100}" for vhost "/my_vhost" ...
[root@localhost ~]#
设置虚拟机tag
[root@localhost ~]# rabbitmqctl set_vhost_tags /my_vhost administrator
Setting tags for virtual host "/my_vhost" to [administrator] ...
[root@localhost ~]#
列举所有虚拟主机
[root@localhost ~]# rabbitmqctl list_vhosts
Listing vhosts ...
name
/
/my_vhost
[root@localhost ~]#
查看虚拟机最大连接数和最大队列
[root@localhost ~]# rabbitmqctl list_vhost_limits -p /my_vhost
Listing limits for vhost "/my_vhost" ...
{"max-connections":10,"max-queues":100}
[root@localhost ~]#
删除虚拟机
[root@localhost ~]# rabbitmqctl delete_vhost /my_vhost
Deleting vhost "/my_vhost" ...
[root@localhost ~]#
3、权限相关
Access Control:
clear_permissions Revokes user permissions for a vhost
clear_topic_permissions Clears user topic permissions for a vhost or exchange
list_permissions Lists user permissions in a virtual host
list_topic_permissions Lists topic permissions in a virtual host
list_user_permissions Lists permissions of a user across all virtual hosts
list_user_topic_permissions Lists user topic permissions
list_vhosts Lists virtual hosts
set_permissions Sets user permissions for a vhost
set_topic_permissions Sets user topic permissions for an exchange
设置权限
rabbitmqctl [--node <node>] [--longnames] [--quiet] set_permissions [--vhost <vhost>] <username> <conf> <write> <read>
[root@localhost ~]# rabbitmqctl set_permissions -p add test ".*" ".*" ".*"
Setting permissions for user "test" in vhost "add" ...
[root@localhost ~]#
查询一个用户的所有虚拟机权限
[root@localhost ~]# rabbitmqctl list_user_permissions test
Listing permissions for user "test" ...
vhost configure write read
add .* .* .*
[root@localhost ~]#
查询一个虚拟机的所有用户权限
[root@localhost ~]# rabbitmqctl list_permissions -p add
Listing permissions for vhost "add" ...
user configure write read
test .* .* .*
[root@localhost ~]#
设置交换机的权限
rabbitmqctl [--node <node>] [--longnames] [--quiet] set_topic_permissions [--vhost <vhost>] <username> <exchange> <write> <read>
[root@localhost ~]# rabbitmqctl set_topic_permissions -p add test my_exchange ".*" ".*"
Setting topic permissions on "my_exchange" for user "test" in vhost "add" ...
[root@localhost ~]#
查看用户的交换机权限
[root@localhost ~]# rabbitmqctl list_user_topic_permissions test
Listing topic permissions for user "test" ...
add my_exchange .* .*
add exchange .* .*
[root@localhost ~]#
查看虚拟机的交换机与用户权限
rabbitmqctl [--node <node>] [--longnames] [--quiet] list_topic_permissions [--vhost <vhost>] [--no-table-headers] [--timeout <timeout>]
[root@localhost ~]# rabbitmqctl list_topic_permissions -p add
Listing topic permissions for vhost "add" ...
user exchange write read
test my_exchange .* .*
test exchange .* .*
[root@localhost ~]#