RabbitMQ基础操作命令
1:启动服务(两种方式)
rabbitmq-server start
service rabbitmq-server start
2:查看Connection,Queue,Channel,User
rabbitmqctl list_connections
rabbitmqctl list_queues
rabbitmqctl list_channels
rabbitmqctl list_users
3:查看集群状态
rabbitmqctl cluster_status
4:加入集群 (注意各节点上erlang版本不同也会导致集群的失败)
rabbitmqctl stop
rabbitmqctl -detached(各节点均以单磁盘节点的集群方式各自运行)
查看下状态rabbitmqctl cluster_status
接下来加入集群
rabbitmqctl stop_app
rabbitmqctl join_cluster --ram(以磁盘节点还是内存节点加入) rabbit@hostname
rabbitmqctl start_app
5:退出集群
磁盘节点通过下述命令来退出集群
[root@node-34 ~]# rabbitmqctl forget_cluster_node rabbit@node-35
Removing node 'rabbit@node-35' from cluster ...
...done.
[root@node-34 ~]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@node-34' ...
[{nodes,[{disc,['rabbit@node-34']}]},
{running_nodes,['rabbit@node-34']},
{partitions,[]}]
...done.
注:内存节点可以通过下述命令变成独立节点
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
6: rabbitmqctl list_queues命令
查看rabbitmqctl说明文档可以发现
list_queues [-p <vhostpath>] [<queueinfoitem> ...]
<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, active_consumers, memory, slave_pids, synchronised_slave_pids,
status].
看其含义就是如果带有<queueinfoitem>参数,则其只能是[name, durable, auto_delete,...这个列表中的一个,比如说
[root@node-34 ~]# rabbitmqctl list_queues name durable messages
Listing queues ...
Hello Muyi false 1
...done.
7:设置用户名,密码,权限
[root@node-34 ~]# rabbitmqctl list_users
Listing users ...
guest [administrator]
...done.
[root@node-34 ~]# rabbitmqctl add_user muyi y132132
Creating user "muyi" ...
...done.
[root@node-34 ~]# rabbitmqctl set_user_tags muyi administrator
Setting tags for user "muyi" to [administrator] ...
...done.
[root@node-34 ~]# rabbitmqctl list_users
Listing users ...
guest [administrator]
muyi [administrator]
...done.
[root@node-34 ~]# rabbitmqctl list_user_permissions guest
Listing permissions for user "guest" ...
/ .* .* .*
...done.
[root@node-34 ~]# rabbitmqctl list_user_permissions muyi
Listing permissions for user "muyi" ...
...done.
此处设置权限时注意'.*'之间需要有空格 三个'.*'分别代表了conf权限,read权限与write权限
例如:当没有给muyi设置这三个权限前是没有权限查询队列,在ui界面也看不见
[root@node-34 ~]# rabbitmqctl set_permissions -p / muyi '.*' '.*' '.*'
Setting permissions for user "muyi" in vhost "/" ...
...done.
[root@node-34 ~]# rabbitmqctl list_users
Listing users ...
guest [administrator]
muyi [administrator]
...done.
End