安装 RabbitMQ @Docker

1、docker pull rabbitmq

[root@vultr ~]# docker pull rabbitmq
Using default tag: latest
latest: Pulling from library/rabbitmq
423ae2b273f4: Pull complete 
de83a2304fa1: Pull complete 
f9a83bce3af0: Pull complete 
b6b53be908de: Pull complete 
834aeb8bfce6: Pull complete 
3407dc115970: Pull complete 
a003ac596878: Pull complete 
5664c847e128: Pull complete 
d392687f8224: Pull complete 
8b6336946e55: Pull complete 
Digest: sha256:fb0023bda1d2237418417557b212ca027180dcdf6da883891c08b78591cc8c15
Status: Downloaded newer image for rabbitmq:latest
docker.io/library/rabbitmq:latest

2、运行RabbitMQ(默认端口:TCP 5672)

[root@vultr ~]# docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3
Unable to find image 'rabbitmq:3' locally
3: Pulling from library/rabbitmq
Digest: sha256:fb0023bda1d2237418417557b212ca027180dcdf6da883891c08b78591cc8c15
Status: Downloaded newer image for rabbitmq:3
45d50c2dd09f1edc72325aecf1f9640652522de7a216ae006c16c273fda9f505

[root@vultr ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                      NAMES
45d50c2dd09f        rabbitmq:3          "docker-entrypoint.s…"   16 seconds ago      Up 16 seconds       4369/tcp, 5671-5672/tcp, 25672/tcp         some-rabbit

3、查看日志

[root@vultr ~]# docker logs some-rabbit
2020-02-23 14:25:48.606 
<0.8.0> Feature flags: list of feature flags found: 2020-02-23 14:25:48.606
<0.8.0> Feature flags: [ ] implicit_default_bindings 2020-02-23 14:25:48.606
<0.8.0> Feature flags: [ ] quorum_queue 2020-02-23 14:25:48.606
<0.8.0> Feature flags: [ ] virtual_host_metadata 2020-02-23 14:25:48.607
<0.8.0> Feature flags: feature flag states written to disk: yes 2020-02-23 14:25:48.635
<0.258.0> ra: meta data store initialised. 0 record(s) recovered 2020-02-23 14:25:48.635
<0.263.0> WAL: recovering [] 2020-02-23 14:25:48.636
<0.267.0> Starting RabbitMQ 3.8.2 on Erlang 22.2.7 Copyright (c) 2007-2019 Pivotal Software, Inc. Licensed under the MPL 1.1. Website: https://rabbitmq.com ## ## RabbitMQ 3.8.2 ## ## ########## Copyright (c) 2007-2019 Pivotal Software, Inc. ###### ## ########## Licensed under the MPL 1.1. Website: https://rabbitmq.com Doc guides: https://rabbitmq.com/documentation.html Support: https://rabbitmq.com/contact.html Tutorials: https://rabbitmq.com/getstarted.html Monitoring: https://rabbitmq.com/monitoring.html Logs: <stdout> Config file(s): /etc/rabbitmq/rabbitmq.conf Starting broker...2020-02-23 14:25:48.638
<0.267.0> node : rabbit@my-rabbit home dir : /var/lib/rabbitmq config file(s) : /etc/rabbitmq/rabbitmq.conf cookie hash : zyUyupuIc8quGN1cGHijxA== log(s) : <stdout> database dir : /var/lib/rabbitmq/mnesia/rabbit@my-rabbit 2020-02-23 14:25:48.646
<0.267.0> Running boot step pre_boot defined by app rabbit 2020-02-23 14:25:48.646
<0.267.0> Running boot step rabbit_core_metrics defined by app rabbit 2020-02-23 14:25:48.647
<0.267.0> Running boot step rabbit_alarm defined by app rabbit 2020-02-23 14:25:48.653
<0.273.0> Memory high watermark set to 396 MiB (415632588 bytes) of 990 MiB (1039081472 bytes) total 2020-02-23 14:25:48.658
<0.275.0> Enabling free disk space monitoring 2020-02-23 14:25:48.658
<0.275.0> Disk free limit set to 50MB 2020-02-23 14:25:48.662
<0.267.0> Running boot step code_server_cache defined by app rabbit 2020-02-23 14:25:48.662
<0.267.0> Running boot step file_handle_cache defined by app rabbit 2020-02-23 14:25:48.663
<0.278.0> Limiting to approx 1048479 file handles (943629 sockets) 2020-02-23 14:25:48.663
<0.279.0> FHC read buffering: OFF 2020-02-23 14:25:48.663
<0.279.0> FHC write buffering: ON 2020-02-23 14:25:48.664
<0.267.0> Running boot step worker_pool defined by app rabbit 2020-02-23 14:25:48.664
<0.268.0> Will use 1 processes for default worker pool 2020-02-23 14:25:48.664
<0.268.0> Starting worker pool 'worker_pool' with 1 processes in it 2020-02-23 14:25:48.664
<0.267.0> Running boot step database defined by app rabbit 2020-02-23 14:25:48.664
<0.267.0> Node database directory at /var/lib/rabbitmq/mnesia/rabbit@my-rabbit is empty. Assuming we need to join an existing cluster or initialise from scratch... 2020-02-23 14:25:48.664
<0.267.0> Configured peer discovery backend: rabbit_peer_discovery_classic_config 2020-02-23 14:25:48.664
<0.267.0> Will try to lock with peer discovery backend rabbit_peer_discovery_classic_config 2020-02-23 14:25:48.664
<0.267.0> Peer discovery backend does not support locking, falling back to randomized delay 2020-02-23 14:25:48.664
<0.267.0> Peer discovery backend rabbit_peer_discovery_classic_config does not support registration, skipping randomized startup delay. 2020-02-23 14:25:48.665
<0.267.0> All discovered existing cluster peers: 2020-02-23 14:25:48.665
<0.267.0> Discovered no peer nodes to cluster with. Some discovery backends can filter nodes out based on a readiness criteria. Enabling debug logging might help troubleshoot. 2020-02-23 14:25:48.667
<0.43.0> Application mnesia exited with reason: stopped 2020-02-23 14:25:48.717
<0.267.0> Waiting for Mnesia tables for 30000 ms, 9 retries left 2020-02-23 14:25:48.728
<0.267.0> Waiting for Mnesia tables for 30000 ms, 9 retries left 2020-02-23 14:25:48.728
<0.267.0> Feature flag `implicit_default_bindings`: supported, attempt to enable... 2020-02-23 14:25:48.728
<0.267.0> Feature flag `implicit_default_bindings`: mark as enabled=state_changing 2020-02-23 14:25:48.732
<0.267.0> Feature flags: list of feature flags found: 2020-02-23 14:25:48.732
<0.267.0> Feature flags: [~] implicit_default_bindings 2020-02-23 14:25:48.732
<0.267.0> Feature flags: [ ] quorum_queue 2020-02-23 14:25:48.732
<0.267.0> Feature flags: [ ] virtual_host_metadata 2020-02-23 14:25:48.732
<0.267.0> Feature flags: feature flag states written to disk: yes 2020-02-23 14:25:48.741
<0.267.0> Waiting for Mnesia tables for 30000 ms, 0 retries left 2020-02-23 14:25:48.742
<0.267.0> Feature flag `implicit_default_bindings`: mark as enabled=true 2020-02-23 14:25:48.747
<0.267.0> Feature flags: list of feature flags found: 2020-02-23 14:25:48.747
<0.267.0> Feature flags: [x] implicit_default_bindings 2020-02-23 14:25:48.747
<0.267.0> Feature flags: [ ] quorum_queue 2020-02-23 14:25:48.747
<0.267.0> Feature flags: [ ] virtual_host_metadata 2020-02-23 14:25:48.747
<0.267.0> Feature flags: feature flag states written to disk: yes 2020-02-23 14:25:48.758
<0.267.0> Feature flag `quorum_queue`: supported, attempt to enable... 2020-02-23 14:25:48.758
<0.267.0> Feature flag `quorum_queue`: mark as enabled=state_changing 2020-02-23 14:25:48.762
<0.267.0> Feature flags: list of feature flags found: 2020-02-23 14:25:48.762
<0.267.0> Feature flags: [x] implicit_default_bindings 2020-02-23 14:25:48.762
<0.267.0> Feature flags: [~] quorum_queue 2020-02-23 14:25:48.762
<0.267.0> Feature flags: [ ] virtual_host_metadata 2020-02-23 14:25:48.762
<0.267.0> Feature flags: feature flag states written to disk: yes 2020-02-23 14:25:48.771
<0.267.0> Waiting for Mnesia tables for 30000 ms, 9 retries left 2020-02-23 14:25:48.773
<0.267.0> Feature flag `quorum_queue`: migrating Mnesia table rabbit_queue... 2020-02-23 14:25:48.779
<0.267.0> Feature flag `quorum_queue`: migrating Mnesia table rabbit_durable_queue... 2020-02-23 14:25:48.786
<0.267.0> Feature flag `quorum_queue`: Mnesia tables migration done 2020-02-23 14:25:48.786
<0.267.0> Feature flag `quorum_queue`: mark as enabled=true 2020-02-23 14:25:48.792
<0.267.0> Feature flags: list of feature flags found: 2020-02-23 14:25:48.792
<0.267.0> Feature flags: [x] implicit_default_bindings 2020-02-23 14:25:48.792
<0.267.0> Feature flags: [x] quorum_queue 2020-02-23 14:25:48.792
<0.267.0> Feature flags: [ ] virtual_host_metadata 2020-02-23 14:25:48.792
<0.267.0> Feature flags: feature flag states written to disk: yes 2020-02-23 14:25:48.802
<0.267.0> Feature flag `virtual_host_metadata`: supported, attempt to enable... 2020-02-23 14:25:48.803
<0.267.0> Feature flag `virtual_host_metadata`: mark as enabled=state_changing 2020-02-23 14:25:48.807
<0.267.0> Feature flags: list of feature flags found: 2020-02-23 14:25:48.807
<0.267.0> Feature flags: [x] implicit_default_bindings 2020-02-23 14:25:48.807
<0.267.0> Feature flags: [x] quorum_queue 2020-02-23 14:25:48.807
<0.267.0> Feature flags: [~] virtual_host_metadata 2020-02-23 14:25:48.807
<0.267.0> Feature flags: feature flag states written to disk: yes 2020-02-23 14:25:48.816
<0.267.0> Waiting for Mnesia tables for 30000 ms, 9 retries left 2020-02-23 14:25:48.824
<0.267.0> Feature flag `virtual_host_metadata`: mark as enabled=true 2020-02-23 14:25:48.830
<0.267.0> Feature flags: list of feature flags found: 2020-02-23 14:25:48.830
<0.267.0> Feature flags: [x] implicit_default_bindings 2020-02-23 14:25:48.830
<0.267.0> Feature flags: [x] quorum_queue 2020-02-23 14:25:48.830
<0.267.0> Feature flags: [x] virtual_host_metadata 2020-02-23 14:25:48.831
<0.267.0> Feature flags: feature flag states written to disk: yes 2020-02-23 14:25:48.840
<0.267.0> Waiting for Mnesia tables for 30000 ms, 9 retries left 2020-02-23 14:25:48.852
<0.267.0> Waiting for Mnesia tables for 30000 ms, 9 retries left 2020-02-23 14:25:48.852
<0.267.0> Peer discovery backend rabbit_peer_discovery_classic_config does not support registration, skipping registration. 2020-02-23 14:25:48.852
<0.267.0> Running boot step database_sync defined by app rabbit 2020-02-23 14:25:48.852
<0.267.0> Running boot step feature_flags defined by app rabbit 2020-02-23 14:25:48.852
<0.267.0> Running boot step codec_correctness_check defined by app rabbit 2020-02-23 14:25:48.852
<0.267.0> Running boot step external_infrastructure defined by app rabbit 2020-02-23 14:25:48.852
<0.267.0> Running boot step rabbit_registry defined by app rabbit 2020-02-23 14:25:48.852
<0.267.0> Running boot step rabbit_auth_mechanism_cr_demo defined by app rabbit 2020-02-23 14:25:48.852
<0.267.0> Running boot step rabbit_queue_location_random defined by app rabbit 2020-02-23 14:25:48.852
<0.267.0> Running boot step rabbit_event defined by app rabbit 2020-02-23 14:25:48.852
<0.267.0> Running boot step rabbit_auth_mechanism_amqplain defined by app rabbit 2020-02-23 14:25:48.852
<0.267.0> Running boot step rabbit_auth_mechanism_plain defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_exchange_type_direct defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_exchange_type_fanout defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_exchange_type_headers defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_exchange_type_topic defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_mirror_queue_mode_all defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_mirror_queue_mode_exactly defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_mirror_queue_mode_nodes defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_priority_queue defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Priority queues enabled, real BQ is rabbit_variable_queue 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_queue_location_client_local defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_queue_location_min_masters defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step kernel_ready defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_sysmon_minder defined by app rabbit 2020-02-23 14:25:48.853
<0.267.0> Running boot step rabbit_epmd_monitor defined by app rabbit 2020-02-23 14:25:48.856
<0.500.0> epmd monitor knows us, inter-node communication (distribution) port: 25672 2020-02-23 14:25:48.856
<0.267.0> Running boot step guid_generator defined by app rabbit 2020-02-23 14:25:48.857
<0.267.0> Running boot step rabbit_node_monitor defined by app rabbit 2020-02-23 14:25:48.858
<0.506.0> Starting rabbit_node_monitor 2020-02-23 14:25:48.858
<0.267.0> Running boot step delegate_sup defined by app rabbit 2020-02-23 14:25:48.859
<0.267.0> Running boot step rabbit_memory_monitor defined by app rabbit 2020-02-23 14:25:48.859
<0.267.0> Running boot step core_initialized defined by app rabbit 2020-02-23 14:25:48.859
<0.267.0> Running boot step upgrade_queues defined by app rabbit 2020-02-23 14:25:48.868
<0.267.0> message_store upgrades: 1 to apply 2020-02-23 14:25:48.868
<0.267.0> message_store upgrades: Applying rabbit_variable_queue:move_messages_to_vhost_store 2020-02-23 14:25:48.868
<0.267.0> message_store upgrades: No durable queues found. Skipping message store migration 2020-02-23 14:25:48.868
<0.267.0> message_store upgrades: Removing the old message store data 2020-02-23 14:25:48.869
<0.267.0> message_store upgrades: All upgrades applied successfully 2020-02-23 14:25:48.879
<0.267.0> Running boot step rabbit_connection_tracking defined by app rabbit 2020-02-23 14:25:48.880
<0.267.0> Running boot step rabbit_connection_tracking_handler defined by app rabbit 2020-02-23 14:25:48.880
<0.267.0> Running boot step rabbit_exchange_parameters defined by app rabbit 2020-02-23 14:25:48.880
<0.267.0> Running boot step rabbit_mirror_queue_misc defined by app rabbit 2020-02-23 14:25:48.880
<0.267.0> Running boot step rabbit_policies defined by app rabbit 2020-02-23 14:25:48.880
<0.267.0> Running boot step rabbit_policy defined by app rabbit 2020-02-23 14:25:48.881
<0.267.0> Running boot step rabbit_queue_location_validator defined by app rabbit 2020-02-23 14:25:48.881
<0.267.0> Running boot step rabbit_quorum_memory_manager defined by app rabbit 2020-02-23 14:25:48.881
<0.267.0> Running boot step rabbit_vhost_limit defined by app rabbit 2020-02-23 14:25:48.881
<0.267.0> Running boot step recovery defined by app rabbit 2020-02-23 14:25:48.881
<0.267.0> Running boot step load_core_definitions defined by app rabbit 2020-02-23 14:25:48.882
<0.267.0> Running boot step empty_db_check defined by app rabbit 2020-02-23 14:25:48.882
<0.267.0> Adding vhost '/' (description: 'Default virtual host') 2020-02-23 14:25:48.887
<0.543.0> Making sure data directory '/var/lib/rabbitmq/mnesia/rabbit@my-rabbit/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L' for vhost '/' exists 2020-02-23 14:25:48.889
<0.543.0> Starting message stores for vhost '/' 2020-02-23 14:25:48.890
<0.547.0> Message store "628WB79CIFDYO9LJI6DKMI09L/msg_store_transient": using rabbit_msg_store_ets_index to provide index 2020-02-23 14:25:48.891
<0.543.0> Started message store of type transient for vhost '/' 2020-02-23 14:25:48.891
<0.550.0> Message store "628WB79CIFDYO9LJI6DKMI09L/msg_store_persistent": using rabbit_msg_store_ets_index to provide index 2020-02-23 14:25:48.892
<0.550.0> Message store "628WB79CIFDYO9LJI6DKMI09L/msg_store_persistent": rebuilding indices from scratch 2020-02-23 14:25:48.893
<0.543.0> Started message store of type persistent for vhost '/' 2020-02-23 14:25:48.894
<0.267.0> Creating user 'guest' 2020-02-23 14:25:48.895
<0.267.0> Setting user tags for user 'guest' to [administrator] 2020-02-23 14:25:48.896
<0.267.0> Setting permissions for 'guest' in '/' to '.*', '.*', '.*' 2020-02-23 14:25:48.897
<0.267.0> Running boot step rabbit_looking_glass defined by app rabbit 2020-02-23 14:25:48.897
<0.267.0> Running boot step rabbit_core_metrics_gc defined by app rabbit 2020-02-23 14:25:48.897
<0.267.0> Running boot step background_gc defined by app rabbit 2020-02-23 14:25:48.897
<0.267.0> Running boot step connection_tracking defined by app rabbit 2020-02-23 14:25:48.899
<0.267.0> Setting up a table for connection tracking on this node: 'tracked_connection_on_node_rabbit@my-rabbit' 2020-02-23 14:25:48.901
<0.267.0> Setting up a table for per-vhost connection counting on this node: 'tracked_connection_per_vhost_on_node_rabbit@my-rabbit' 2020-02-23 14:25:48.901
<0.267.0> Running boot step routing_ready defined by app rabbit 2020-02-23 14:25:48.901
<0.267.0> Running boot step pre_flight defined by app rabbit 2020-02-23 14:25:48.901
<0.267.0> Running boot step notify_cluster defined by app rabbit 2020-02-23 14:25:48.901
<0.267.0> Running boot step networking defined by app rabbit 2020-02-23 14:25:48.903
<0.596.0> started TCP listener on [::]:5672 2020-02-23 14:25:48.903
<0.267.0> Running boot step cluster_name defined by app rabbit 2020-02-23 14:25:48.903
<0.267.0> Running boot step direct_client defined by app rabbit 2020-02-23 14:25:49.330
<0.8.0> Server startup complete; 0 plugins started. completed with 0 plugins.

4、进入 RabbitMQ B Shell

[root@vultr ~]# docker exec -it 45d50c2dd09f bash

root@my-rabbit:/bin# rabbitmqctl list_users
Listing users ...
user    tags
guest   [administrator]

5、运行 RabbitMQ Management

[root@vultr ~]# docker run -d --hostname my-rabbit --name some-rabbit -p 8080:15672 rabbitmq:3-management
Unable to find image 'rabbitmq:3-management' locally
3-management: Pulling from library/rabbitmq
423ae2b273f4: Already exists 
de83a2304fa1: Already exists 
f9a83bce3af0: Already exists 
b6b53be908de: Already exists 
834aeb8bfce6: Already exists 
3407dc115970: Already exists 
a003ac596878: Already exists 
5664c847e128: Already exists 
d392687f8224: Already exists 
8b6336946e55: Already exists 
dd7577d662e2: Pull complete 
928bd21b5ae7: Pull complete 
Digest: sha256:03a8032b17995aabc7ba81d2e2ac50652b1b929d1474e2b05244b1334032a420
Status: Downloaded newer image for rabbitmq:3-management
docker: Error response from daemon: Conflict. The container name "/some-rabbit" is already in use by container "45d50c2dd09f1edc72325aecf1f9640652522de7a216ae006c16c273fda9f505". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.

[root@vultr ~]# docker run -d --hostname my-rabbit --name some-rabbit-man -p 8080:15672 rabbitmq:3-management
c8229552360435f4866d277c98e8cfe9c39a22042a285fcd92db682b8c221e4d

[root@vultr ~]# docker ps -a
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                                                                    NAMES
c82295523604        rabbitmq:3-management   "docker-entrypoint.s…"   18 seconds ago      Up 18 seconds       4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:8080->15672/tcp   some-rabbit-man
45d50c2dd09f        rabbitmq:3              "docker-entrypoint.s…"   14 minutes ago      Up 14 minutes       4369/tcp, 5671-5672/tcp, 25672/tcp                                       some-rabbit

6、进入管理界面

http://localhost:8080

7、参考文档

https://hub.docker.com/_/rabbitmq

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注