RabbitMQ-常用命令_rabbitmq 启动(2),高级面试题+解析

时间:2024-10-12 18:59:22

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新大数据全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip204888 (备注大数据)
img

正文

Starting broker… completed with 3 plugins.


后台启动命令-rabbitmq-server -detached



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 soft]# rabbitmq-server -detached
[root@mes01 soft]#


停止命令-rabbitmq-server stop



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 soft]# rabbitmq-server stop
BOOT FAILED

ERROR: distribution port 25672 in use by rabbit@mes01

14:12:35.938 [error]
14:12:35.943 [error] BOOT FAILED
14:12:35.943 [error] ===========
14:12:35.943 [error] ERROR: distribution port 25672 in use by rabbit@mes01
14:12:35.943 [error]
14:12:36.946 [error] Supervisor rabbit_prelaunch_sup had child prelaunch started with rabbit_prelaunch:run_prelaunch_first_phase() at undefined exit with reason {dist_port_already_used,25672,“rabbit”,“mes01”} in context start_error
14:12:36.947 [error] CRASH REPORT Process <0.154.0> with 0 neighbours exited with reason: {{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,“rabbit”,“mes01”}}},{rabbit_prelaunch_app,start,[normal,[]]}} in application_master:init/4 line 138
{“Kernel pid terminated”,application_controller,“{application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,“rabbit”,“mes01”}}},{rabbit_prelaunch_app,start,[normal,[]]}}}”}
Kernel pid terminated (application_controller) ({application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,“rabbit”,“mes01”}}},{rabbit_prel

Crash dump is being written to: erl_crash.dump…done


停止命令-rabbitmq-server stop



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 soft]# rabbitmqctl stop
Stopping and halting node rabbit@mes01 …


启动后的进程信息



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 ~]# ps -ef | grep rabbitmq
root 1413 1333 0 14:19 pts/0 00:00:00 /sbin/runuser -u rabbitmq – /usr/lib/rabbitmq/bin/rabbitmq-server
rabbitmq 1421 1413 0 14:19 pts/0 00:00:00 /bin/sh /usr/lib/rabbitmq/bin/rabbitmq-server
rabbitmq 1428 1421 43 14:19 pts/0 00:00:12 /usr/lib64/erlang/erts-11.0.2/bin/ -W w -K true -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -B i – -root /usr/lib64/erlang -progname erl – -home /var/lib/rabbitmq – -pa -noshell -noinput -s rabbit boot -boot start_sasl -lager crash_log false -lager handlers []
rabbitmq 1539 1428 0 14:19 ? 00:00:00 erl_child_setup 1024
rabbitmq 1568 1 0 14:19 ? 00:00:00 /usr/lib64/erlang/erts-11.0.2/bin/epmd -daemon
rabbitmq 1595 1539 0 14:19 ? 00:00:00 inet_gethost 4
rabbitmq 1596 1595 0 14:19 ? 00:00:00 inet_gethost 4
root 1679 1621 0 14:19 pts/1 00:00:00 grep --color=auto rabbitmq


#### 3.2 一般操作命令



  • 1
  • 2
  • 3
  • 4
  • 5

查看所有队列

rabbitmqctl list_queues

查看所有虚拟主机

rabbitmqctl list_vhosts

在Erlang VM运行的情况下启动或者停止RabbitMQ应用

rabbitmqctl start_app
rabbitmqctl stop_app

查看节点状态

rabbitmqctl status

查看可用插件

rabbitmq-plugins list

启用插件

rabbitmq-plugins enable

停用插件

rabbitmq-plugins disable

移除所有数据 要在rabbitmqctl stop_app之后使用

rabbitmqctl reset

查看所有交换器信息-列表式

rabbitmqctl list_exchanges

格式化查看

rabbitmqctl list_exchanges --formatter pretty_table

查看绑定的列表 - 查看交换机队列绑定信息

rabbitmqctl list_bindings

格式化查看

rabbitmqctl list_bindings --formatter pretty_table


样例:


**查看所有队列-rabbitmqctl list\_queues**



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

[root@mes01 ~]# rabbitmqctl list_queues
Timeout: 60.0 seconds …
Listing queues for vhost / …


**查看所有虚拟主机-rabbitmqctl list\_vhosts**



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 ~]# rabbitmqctl list_vhosts
Listing vhosts …
name
/


**停止RabbitMQ应用-rabbitmqctl stop\_app**



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 ~]# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@mes01 …


当停止应用后,可以观察到mq的进程都还是存在的。但页面已经无法访问



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 ~]# ps -ef | grep rabbitmq
rabbitmq 1568 1 0 14:19 ? 00:00:00 /usr/lib64/erlang/erts-11.0.2/bin/epmd -daemon
rabbitmq 1971 1 5 14:22 ? 00:00:41 /usr/lib64/erlang/erts-11.0.2/bin/ -W w -K true -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 – -root /usr/lib64/erlang -progname erl – -home /var/lib/rabbitmq – -pa -noshell -noinput -s rabbit boot -boot start_sasl -lager crash_log false -lager handlers []
rabbitmq 2080 1971 0 14:22 ? 00:00:00 erl_child_setup 32768
rabbitmq 2146 2080 0 14:22 ? 00:00:00 inet_gethost 4
rabbitmq 2396 2146 0 14:24 ? 00:00:00 inet_gethost 4
root 3584 1621 0 14:35 pts/1 00:00:00 grep --color=auto rabbitmq


观察页面,已经不能访问了。


**启动RabbitMQ应用-rabbitmqctl start\_app**



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

[root@mes01 ~]# rabbitmqctl start_app
Starting node rabbit@mes01 …


此时查看进程



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 ~]# ps -ef | grep rabbitmq
rabbitmq 1568 1 0 14:19 ? 00:00:00 /usr/lib64/erlang/erts-11.0.2/bin/epmd -daemon
rabbitmq 1971 1 5 14:22 ? 00:00:50 /usr/lib64/erlang/erts-11.0.2/bin/ -W w -K true -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 – -root /usr/lib64/erlang -progname erl – -home /var/lib/rabbitmq – -pa -noshell -noinput -s rabbit boot -boot start_sasl -lager crash_log false -lager handlers []
rabbitmq 2080 1971 0 14:22 ? 00:00:00 erl_child_setup 32768
rabbitmq 2146 2080 0 14:22 ? 00:00:00 inet_gethost 4
rabbitmq 2396 2146 0 14:24 ? 00:00:00 inet_gethost 4
root 3841 1621 0 14:38 pts/1 00:00:00 grep --color=auto rabbitmq


查看rabbitMQ管理页面


![在这里插入图片描述](/#pic_center)


**查看节点状态-rabbitmqctl status**



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

[root@mes01 ~]# rabbitmqctl status
Status of node rabbit@mes01 …
Runtime

OS PID: 1971
OS: Linux
Uptime (seconds): 1137
RabbitMQ version: 3.8.5
Node name: rabbit@mes01
Erlang configuration: Erlang/OTP 23 [erts-11.0.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:64] [hipe]
Erlang processes: 448 used, 1048576 limit
Scheduler run queue: 1
Cluster heartbeat timeout (net_ticktime): 60

Plugins

Enabled plugin file: /etc/rabbitmq/enabled_plugins
Enabled plugins:

  • rabbitmq_management
  • amqp_client
  • rabbitmq_web_dispatch
  • cowboy
  • cowlib
  • rabbitmq_management_agent

Data directory

Node data directory: /var/lib/rabbitmq/mnesia/rabbit@mes01
Raft data directory: /var/lib/rabbitmq/mnesia/rabbit@mes01/quorum/rabbit@mes01

Config files

Log file(s)

  • /var/log/rabbitmq/rabbit@
  • /var/log/rabbitmq/rabbit@mes01_upgrade.log

Alarms

(none)

Memory

Calculation strategy: rss
Memory high watermark setting: 0.4 of available memory, computed to: 3.295 gb
other_proc: 0.0333 gb (31.58 %)
code: 0.0277 gb (26.21 %)
allocated_unused: 0.0171 gb (16.17 %)
other_system: 0.0143 gb (13.52 %)
reserved_unallocated: 0.0062 gb (5.9 %)
other_ets: 0.0032 gb (3.05 %)
atom: 0.0014 gb (1.34 %)
plugins: 0.0014 gb (1.32 %)
binary: 0.0002 gb (0.21 %)
mgmt_db: 0.0002 gb (0.21 %)
metrics: 0.0002 gb (0.2 %)
connection_other: 0.0002 gb (0.15 %)
mnesia: 0.0001 gb (0.07 %)
quorum_ets: 0.0 gb (0.05 %)
msg_index: 0.0 gb (0.03 %)
connection_channels: 0.0 gb (0.0 %)
connection_readers: 0.0 gb (0.0 %)
connection_writers: 0.0 gb (0.0 %)
queue_procs: 0.0 gb (0.0 %)
queue_slave_procs: 0.0 gb (0.0 %)
quorum_queue_procs: 0.0 gb (0.0 %)

File Descriptors

Total: 2, limit: 32671
Sockets: 0, limit: 29401

Free Disk Space

Low free disk space watermark: 0.05 gb
Free disk space: 23.2459 gb

Totals

Connection count: 0
Queue count: 0
Virtual host count: 1

Listeners

Interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
Interface: [::], port: 15672, protocol: http, purpose: HTTP API


**查看可用插件-rabbitmq-plugins list**



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 ~]# rabbitmq-plugins list
Listing plugins with pattern “.*” …
Configured: E = explicitly enabled; e = implicitly enabled
| Status: * = running on rabbit@mes01
|/
[ ] rabbitmq_amqp1_0 3.8.5
[ ] rabbitmq_auth_backend_cache 3.8.5
[ ] rabbitmq_auth_backend_http 3.8.5
[ ] rabbitmq_auth_backend_ldap 3.8.5
[ ] rabbitmq_auth_backend_oauth2 3.8.5
[ ] rabbitmq_auth_mechanism_ssl 3.8.5
[ ] rabbitmq_consistent_hash_exchange 3.8.5
[ ] rabbitmq_event_exchange 3.8.5
[ ] rabbitmq_federation 3.8.5
[ ] rabbitmq_federation_management 3.8.5
[ ] rabbitmq_jms_topic_exchange 3.8.5
[E*] rabbitmq_management 3.8.5
[e*] rabbitmq_management_agent 3.8.5
[ ] rabbitmq_mqtt 3.8.5
[ ] rabbitmq_peer_discovery_aws 3.8.5
[ ] rabbitmq_peer_discovery_common 3.8.5
[ ] rabbitmq_peer_discovery_consul 3.8.5
[ ] rabbitmq_peer_discovery_etcd 3.8.5
[ ] rabbitmq_peer_discovery_k8s 3.8.5
[ ] rabbitmq_prometheus 3.8.5
[ ] rabbitmq_random_exchange 3.8.5
[ ] rabbitmq_recent_history_exchange 3.8.5
[ ] rabbitmq_sharding 3.8.5
[ ] rabbitmq_shovel 3.8.5
[ ] rabbitmq_shovel_management 3.8.5
[ ] rabbitmq_stomp 3.8.5
[ ] rabbitmq_top 3.8.5
[ ] rabbitmq_tracing 3.8.5
[ ] rabbitmq_trust_store 3.8.5
[e*] rabbitmq_web_dispatch 3.8.5
[ ] rabbitmq_web_mqtt 3.8.5
[ ] rabbitmq_web_mqtt_examples 3.8.5
[ ] rabbitmq_web_stomp 3.8.5
[ ] rabbitmq_web_stomp_examples 3.8.5


E\* 表示启动的插件 e\* 表示依赖启动的插件


rabbitmq\_management 依赖于rabbitmq\_management\_agent和rabbitmq\_web\_dispatch


**启用插件-rabbitmq-plugins enable rabbitmq\_management**



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

[root@mes01 soft]# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@mes01:
rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@mes01…
The following plugins have been enabled:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch

started 3 plugins.


**信用插件-rabbitmq-plugins disable rabbitmq\_management**



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 ~]# rabbitmq-plugins disable rabbitmq_management
Disabling plugins on node rabbit@mes01:
rabbitmq_management
All plugins have been disabled.
Applying plugin configuration to rabbit@mes01…
The following plugins have been disabled:
rabbitmq_management_agent
rabbitmq_web_dispatch
rabbitmq_management

stopped 3 plugins.


再次检查插件列表



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 ~]# rabbitmq-plugins list
Listing plugins with pattern “.*” …
Configured: E = explicitly enabled; e = implicitly enabled
| Status: * = running on rabbit@mes01
|/
[ ] rabbitmq_amqp1_0 3.8.5
[ ] rabbitmq_auth_backend_cache 3.8.5
[ ] rabbitmq_auth_backend_http 3.8.5
[ ] rabbitmq_auth_backend_ldap 3.8.5
[ ] rabbitmq_auth_backend_oauth2 3.8.5
[ ] rabbitmq_auth_mechanism_ssl 3.8.5
[ ] rabbitmq_consistent_hash_exchange 3.8.5
[ ] rabbitmq_event_exchange 3.8.5
[ ] rabbitmq_federation 3.8.5
[ ] rabbitmq_federation_management 3.8.5
[ ] rabbitmq_jms_topic_exchange 3.8.5
[ ] rabbitmq_management 3.8.5
[ ] rabbitmq_management_agent 3.8.5
[ ] rabbitmq_mqtt 3.8.5
[ ] rabbitmq_peer_discovery_aws 3.8.5
[ ] rabbitmq_peer_discovery_common 3.8.5
[ ] rabbitmq_peer_discovery_consul 3.8.5
[ ] rabbitmq_peer_discovery_etcd 3.8.5
[ ] rabbitmq_peer_discovery_k8s 3.8.5
[ ] rabbitmq_prometheus 3.8.5
[ ] rabbitmq_random_exchange 3.8.5
[ ] rabbitmq_recent_history_exchange 3.8.5
[ ] rabbitmq_sharding 3.8.5
[ ] rabbitmq_shovel 3.8.5
[ ] rabbitmq_shovel_management 3.8.5
[ ] rabbitmq_stomp 3.8.5
[ ] rabbitmq_top 3.8.5
[ ] rabbitmq_tracing 3.8.5
[ ] rabbitmq_trust_store 3.8.5
[ ] rabbitmq_web_dispatch 3.8.5
[ ] rabbitmq_web_mqtt 3.8.5
[ ] rabbitmq_web_mqtt_examples 3.8.5
[ ] rabbitmq_web_stomp 3.8.5
[ ] rabbitmq_web_stomp_examples 3.8.5


**重置所有数据**



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 ~]# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@mes01 …
[root@mes01 ~]# rabbitmqctl reset
Resetting node rabbit@mes01 …
[root@mes01 ~]#


#### 3.3 用户权限管理命令



  • 1
  • 2
  • 3
  • 4
  • 5

查看所有用户

rabbitmqctl list_users

添加用户

rabbitmqctl add_user username password

修改用户密码

rabbitmqctl change_password username password

删除用户

rabbitmqctl delete_user username

设置用户权限

rabbitmqctl set_permissions -p vhostpath username “.*” “.*” “.*”

列表用户权限

rabbitmqctl list_user_permissions username

清除用户权限

rabbitmqctl clear_permissions -p vhostspath username

给用户设置标签

rabbitmqctl set_user_tags username tag

创建虚拟主机

rabbitmqctl add_vhost vhostpath

列表所有虚拟主机

rabbitmqctl list_vhosts

列表所有虚拟主机的权限

rabbitmqctl list_permissions -p vhostpath

删除虚拟主机

rabbitmqctl delete_vhosts vhostspath


样例


**列出所有用户-rabbitmqctl list\_users**



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

[root@mes01 ~]# rabbitmqctl list_users
Listing users …
user tags
guest [administrator]
root [administrator]


**添加用户**



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 ~]# rabbitmqctl add_user test 123456
Adding user “test” …
[root@mes01 ~]# rabbitmqctl list_users
Listing users …
user tags
guest [administrator]
test []
root [administrator]
[root@mes01 ~]#


**修改用户密码**



  • 1
  • 2
  • 3
  • 4
  • 5

root@mes01 ~]# rabbitmqctl change_password test 654321
Changing password for user “test” …


**设置并查看权限**



  • 1
  • 2
  • 3
  • 4
  • 5

[root@mes01 ~]# rabbitmqctl set_permissions -p / test “.*” “.*” “.*”
Setting permissions for user “test” in vhost “/” …
[root@mes01 ~]# rabbitmqctl list_user_permissions test
Listing permissions for user “test” …
vhost configure write read
/ .* .* .*


**设置用户标签并查看**





**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注大数据)**
![img](/img_convert/)

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

oot@mes01 ~]# rabbitmqctl set\_permissions -p / test ".\*" ".\*" ".\*"
Setting permissions for user "test" in vhost "/" ...
[root@mes01 ~]# rabbitmqctl list\_user\_permissions test
Listing permissions for user "test" ...
vhost   configure       write   read
/       .*      .*      .*

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

设置用户标签并查看

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注大数据)
[外链图片转存中…(img-41sa8ZZi-1713320129194)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!