赞
踩
本文通过docker-compose构建一个单体的rabbtimq容器。
首先需要有docker和docker-compose环境,docker安装[1],docker-compose安装[2]。
通过下列命令确定docker、docker-compose是否安装成功。
[root@192 gengzhihao]# docker version Client: Docker Engine - Community Version: 25.0.3 API version: 1.44 Go version: go1.21.6 Git commit: 4debf41 Built: Tue Feb 6 21:17:10 2024 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 25.0.3 API version: 1.44 (minimum version 1.24) Go version: go1.21.6 Git commit: f417435 Built: Tue Feb 6 21:16:08 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.28 GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb runc: Version: 1.1.12 GitCommit: v1.1.12-0-g51d5e94 docker-init: Version: 0.19.0 GitCommit: de40ad0 [root@192 bin]# docker-compose version Docker Compose version v2.24.6
docker-compose在/usr/local/bin里,我们就在/usr/local下构建一个docker-compose目录,里面再构建各级不同容器的目录,用于构建dockerfile和挂载目录[3]。
[root@192 bin]# cd /usr/local
[root@192 local]# ls
bin docker-mount etc games include lib lib64 libexec mongodb mycat mysql sbin share src
[root@192 local]# mkdir docker-compose
[root@192 local]# ls
bin docker-mount games lib libexec mycat sbin src
docker-compose etc include lib64 mongodb mysql share
[root@192 local]# cd docker-compose/
[root@192 docker-compose]# mkdir rabbitmq
[root@192 docker-compose]# cd rabbitmq/
在其中构建dockerfile
[root@192 rabbitmq]# vim docker-compose.yml
内容如下:
version: '3.1'
services:
rabbitmq:
restart: always
image: daocloud.io/library/rabbitmq:3.8.8
volumes:
- ./data/:/var/lib/rabbitmq/
- ./log/:/var/log/rabbitmq/log/
ports:
- 15672:15672
- 5672:5672
启动rabbitmq的容器,curl其端口看一下是否正常返回AMQP,docker ps看一下容器名字是什么,后面进入容器内部用得上。
[root@192 rabbitmq]# docker-compose up -d [+] Running 11/11 ✔ rabbitmq 10 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿] 0B/0B Pulled 40.5s ✔ 5d9821c94847 Pull complete 25.6s ✔ a610eae58dfc Pull complete 0.4s ✔ a40e0eb9f140 Pull complete 0.4s ✔ d691f0af2920 Pull complete 1.3s ✔ 53d0225d76e3 Pull complete 31.4s ✔ 7c993fe17403 Pull complete 1.6s ✔ 0d9ec409b148 Pull complete 16.0s ✔ 59a47a965242 Pull complete 16.3s ✔ e0f8eb2a167a Pull complete 16.5s ✔ 75f84d813186 Pull complete 16.8s [+] Running 1/2 ⠴ Network rabbitmq_default Created 1.4s ✔ Container rabbitmq-rabbitmq-1 Started 1.3s #返回AMQP为正常返回 [root@192 rabbitmq]# curl localhost:5672 AMQP [root@192 rabbitmq]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 39dc5f01ded3 daocloud.io/library/rabbitmq:3.8.8 "docker-entrypoint.s…" About a minute ago Up About a minute 4369/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 5671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp rabbitmq-rabbitmq-1
启动的时候,有的时候会报错,
Error response from daemon: Head "https://daocloud.io/v2/library/rabbitmq/manifests/3.8.8": Get "https://daohub-auth.daocloud.io/auth?scope=repository%3Alibrary%2Frabbitmq%3Apull&service=daocloud.io": net/http: request canceled (Client.Timeout exceeded while awaiting headers)
解决方法就是多试几次命令就好[4]。
进入容器,进入其/opt/rabbitmq目录,其中plugins和sbin目录书我们需要注意的。进入容器时用到的容器名字,是docker ps时查看到的rabbitmq容器的名字。
[root@192 rabbitmq]# docker exec -it rabbitmq-rabbitmq-1 /bin/bash
root@39dc5f01ded3:/# cd /opt/rabbitmq/
root@39dc5f01ded3:/opt/rabbitmq# ls
INSTALL LICENSE-BSD-base64js LICENSE-MIT-Flot LICENSE-MPL etc
LICENSE LICENSE-BSD-recon LICENSE-MIT-Mochi LICENSE-MPL-RabbitMQ plugins
LICENSE-APACHE2 LICENSE-ISC-cowboy LICENSE-MIT-Sammy LICENSE-erlcloud sbin
LICENSE-APACHE2-ExplorerCanvas LICENSE-MIT-EJS LICENSE-MIT-Sammy060 LICENSE-httpc_aws share
LICENSE-APACHE2-excanvas LICENSE-MIT-EJS10 LICENSE-MIT-jQuery LICENSE-rabbitmq_aws
LICENSE-APL2-Stomp-Websocket LICENSE-MIT-Erlware-Commons LICENSE-MIT-jQuery164 escript
进入plugins目录,可以看到一个 rabbitmq_management-3.8.8.ez,是可视化界面需要用到的脚本,复制rabbitmq_management,版本号不用记。
root@39dc5f01ded3:/opt/rabbitmq/plugins# ls README rabbitmq_federation-3.8.8.ez accept-0.3.5.ez rabbitmq_federation_management-3.8.8.ez amqp10_client-3.8.8.ez rabbitmq_jms_topic_exchange-3.8.8.ez amqp10_common-3.8.8.ez rabbitmq_management-3.8.8.ez amqp_client-3.8.8.ez rabbitmq_management_agent-3.8.8.ez aten-0.5.5.ez rabbitmq_mqtt-3.8.8.ez base64url-0.0.1.ez rabbitmq_peer_discovery_aws-3.8.8.ez cowboy-2.6.1.ez rabbitmq_peer_discovery_common-3.8.8.ez cowlib-2.7.0.ez rabbitmq_peer_discovery_consul-3.8.8.ez credentials_obfuscation-2.2.0.ez rabbitmq_peer_discovery_etcd-3.8.8.ez cuttlefish-2.4.1.ez rabbitmq_peer_discovery_k8s-3.8.8.ez eetcd-0.3.3.ez rabbitmq_prelaunch-3.8.8.ez gen_batch_server-0.8.4.ez rabbitmq_prometheus-3.8.8.ez getopt-1.0.1.ez rabbitmq_random_exchange-3.8.8.ez goldrush-0.1.9.ez rabbitmq_recent_history_exchange-3.8.8.ez gun-1.3.3.ez rabbitmq_sharding-3.8.8.ez jose-1.10.1.ez rabbitmq_shovel-3.8.8.ez jsx-2.11.0.ez rabbitmq_shovel_management-3.8.8.ez lager-3.8.0.ez rabbitmq_stomp-3.8.8.ez observer_cli-1.5.4.ez rabbitmq_top-3.8.8.ez prometheus-4.6.0.ez rabbitmq_tracing-3.8.8.ez ra-1.1.6.ez rabbitmq_trust_store-3.8.8.ez rabbit-3.8.8.ez rabbitmq_web_dispatch-3.8.8.ez rabbit_common-3.8.8.ez rabbitmq_web_mqtt-3.8.8.ez rabbitmq_amqp1_0-3.8.8.ez rabbitmq_web_mqtt_examples-3.8.8.ez rabbitmq_auth_backend_cache-3.8.8.ez rabbitmq_web_stomp-3.8.8.ez rabbitmq_auth_backend_http-3.8.8.ez rabbitmq_web_stomp_examples-3.8.8.ez rabbitmq_auth_backend_ldap-3.8.8.ez ranch-1.7.1.ez rabbitmq_auth_backend_oauth2-3.8.8.ez recon-2.5.1.ez rabbitmq_auth_mechanism_ssl-3.8.8.ez stdout_formatter-0.2.4.ez rabbitmq_aws-3.8.8.ez syslog-3.4.5.ez rabbitmq_consistent_hash_exchange-3.8.8.ez sysmon_handler-1.3.0.ez rabbitmq_event_exchange-3.8.8.ez
去和plugins同级的sbin目录下,开启可视化界面
root@39dc5f01ded3:/opt/rabbitmq/plugins# cd ../sbin/ root@39dc5f01ded3:/opt/rabbitmq/sbin# ls rabbitmq-defaults rabbitmq-env rabbitmq-queues rabbitmq-upgrade rabbitmq-diagnostics rabbitmq-plugins rabbitmq-server rabbitmqctl root@39dc5f01ded3:/opt/rabbitmq/sbin# ./rabbitmq-plugins enable rabbitmq_management Enabling plugins on node rabbit@39dc5f01ded3: rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_prometheus rabbitmq_web_dispatch Applying plugin configuration to rabbit@39dc5f01ded3... The following plugins have been enabled: rabbitmq_management started 1 plugins.
这是在linux的浏览器中访问localhost:15672,即可看到可视化界面,账号密码都是guest。
参考资料:
[1],【Docker】基于yum安装docker
[2],【Docker】docker-compose安装
[3],RabbitMQ.md
[4],docker-compose 安装rabbitmq
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。