最近购入一台新服务器,以前都是通过rpm离线安装,现在尝试使用docker安装,下面是docker安装rabbitmq的具体步骤:
一、RabbitMQ安装
1.使用docker搜索rabbitmq的镜像,可以选择所需要安装版本。
[root@nightmare-01 ~]# docker search rabbitmq
2.安装镜像
这里直接安装最新版本rabbitmq,如果需要安装其他版本,可以在rabbitmq后面跟上所需版本号即可。
[root@nightmare-01 ~]# docker pull rabbitmq
Using default tag: latest
latest: Pulling from library/rabbitmq
fb0b3276a519: Pull complete
4b7e2bc6e42d: Pull complete
498446f27344: Pull complete
b2df5a4d5834: Pull complete
2dfb57eb3a37: Pull complete
e62da47353ea: Pull complete
cb81e266b02f: Pull complete
a71f8bd3b746: Pull complete
6126e39c0e78: Pull complete
Digest: sha256:588974c4b11c390a702839cd065f746870c91c4a4d951b05a2a33f485e4bab4a
Status: Downloaded newer image for rabbitmq:latest
[docker.io/library/rabbitmq:latest](http://docker.io/library/rabbitmq:latest)
3.启动rabbitmq。
-p 5673:5672 说明: -p 外网端口:docker内部端口
可以任意修改外网端口,如果映射外网端口为5673,那么程序中连接端口使用5673
[root@nightmare-01 ~]# docker run -d --hostname my-rabbit --name rabbit -p 15672:15672 -p 5673:5672 rabbitmq
5fdcd2e3d91adbf7b0e0ec8dbda261e28e76d203340ad880b4c43a659b422268
4.查看容器运行应用:.
[root@nightmare-01 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5fdcd2e3d91a rabbitmq "docker-entrypoint.s…" 29 seconds ago Up 28 seconds 4369/tcp, 5671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp, 0.0.0.0:5673->5672/tcp, :::5673->5672/tcp rabbit
5.添加rabbitmq插件,用于界面展示。
[root@nightmare-01 ~]# docker exec -it 5fdcd2e3d91a /bin/bash
root@my-rabbit:/# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@my-rabbit:
rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_prometheus
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@my-rabbit...
The following plugins have been enabled:
rabbitmq_management
started 1 plugins.
二、RabbitMQ的密码修改
1.进入 Docker 容器
docker exec -it 容器ID bash
2.查看当前用户列表。
root@my-rabbit:/bin# rabbitmqctl list_users
Listing users ...
user tags
guest [administrator]
3.添加用户,授予管理员权限。
root@my-rabbit:/# rabbitmqctl add_user admin wu1234
root@my-rabbit:/# rabbitmqctl set_user_tags admin administrator
root@my-rabbit:/# rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
4.修改密码。
rabbitmqctl change_password Username 'Newpassword'
Username:对应不同用户,NewPassword:需设置的新密码
例如:
rabbitmqctl change_password guest 'wu1234'
三、解决Docker部署rabbitmq遇到的以下问题:
问题描述:
3.1 访问交换机时报错,Management API returned status code 500
3.2 访问channel时报错,Stats in management UI are disabled on this node
3.3 /api/queues 队列接口返回数据不全.
解决办法:
[root@VM-12-16-centos ~]# docker exec -it 4fea64002906 bash
root@my-rabbit:/# cd /etc/rabbitmq/conf.d/
root@my-rabbit:/etc/rabbitmq/conf.d# cat management_agent.disable_metrics_collector.conf
management_agent.disable_metrics_collector=true
root@my-rabbit:/etc/rabbitmq/conf.d# echo management_agent.disable_metrics_collector=false > management_agent.disable_metrics_collector.conf
root@my-rabbit:/etc/rabbitmq/conf.d# exit
exit
[root@VM-12-16-centos ~]# docker restart 4fea64002906
4fea64002906