Docker部署RabbitMQ开启SSL与SpringBoot连接测试
准备工作
在配置 RabbitMQ 的 SSL 之前,需要准备 CA 证书、服务器证书和密钥,以及客户端证书和密钥。
生成证书和密钥
使用 OpenSSL 来生成自签名证书和私钥。以下是一个完整的步骤示例:
ca.crt
:CA 证书server.key
和server.crt
:RabbitMQ 服务器的私钥和证书client.key
和client.crt
:客户端的私钥和证书client.p12
和server.keystore
: java客户端连接使用
配置 RabbitMQ 启用 SSL
RabbitMQ 使用配置文件(rabbitmq.conf
)来启用 SSL
enabled_plugins
文件
[rabbitmq_auth_mechanism_ssl,rabbitmq_management].
Docker compose部署Rabbitmq
创建目录与复制证书
docker-compose.yml
启动容器
docker-compose up -d
# 查看容器正常启动
[root@host146 logs]# docker logs -f b2c8c7215d65
2024-11-26 14:29:56.940431+08:00 [notice] <0.45.0> Application syslog exited with reason: stopped
2024-11-26 14:29:56.949526+08:00 [notice] <0.216.0> Logging: switching to configured handler(s); following messages may not be visible in this log output
## ## RabbitMQ 4.0.4
## ##
########## Copyright (c) 2007-2024 Broadcom Inc and/or its subsidiaries
###### ##
########## Licensed under the MPL 2.0. Website: https://rabbitmq.com
Erlang: 27.1.2 [jit]
TLS Library: OpenSSL - OpenSSL 3.3.2 3 Sep 2024
Release series support status: see https://www.rabbitmq.com/release-information
Doc guides: https://www.rabbitmq.com/docs
Support: https://www.rabbitmq.com/docs/contact
Tutorials: https://www.rabbitmq.com/tutorials
Monitoring: https://www.rabbitmq.com/docs/monitoring
Upgrading: https://www.rabbitmq.com/docs/upgrade
Logs: /var/log/rabbitmq/rabbit@rabbitmq.log
<stdout>
Config file(s): /etc/rabbitmq/rabbitmq.conf
Starting broker... completed with 3 plugins.
#查看监听
rabbitmq-diagnostics listeners
#查看支持的TLS版本
rabbitmq-diagnostics --silent tls_versions
测试 SSL 配置
在 RabbitMQ 配置 SSL 后,你可以使用 OpenSSL 或客户端工具测试连接。
使用 openssl s_client
测试
从客户端机器运行以下命令,测试与 RabbitMQ 的 SSL 连接:
成功连接时,应该能看到包含 Verify return code: 0 (ok) 的输出。
使用 RabbitMQ 客户端测试
Spring Boot 示例配置(application.yml
):