Technology Sharing

RABBITMQ local test certificate generation script

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Since the applet requires access to the wss interface, the test environment needs to be switched to https. I read the official documentation.

RabbitMQ Web STOMP Plugin | RabbitMQThere is this information in it

Then I typed GPT for a while, inputting the requirements several times, and got a script like this:

generate_cert.sh

  1. #!/bin/bash
  2. # 检查是否提供了IP地址
  3. if [ "$#" -ne 1 ]; then
  4. echo "Usage: $0 <IP_ADDRESS>"
  5. exit 1
  6. fi
  7. IP_ADDRESS=$1
  8. PASSWORD="changeme"
  9. # 创建必要的目录
  10. mkdir -p certs
  11. # 生成 CA 密钥
  12. openssl genrsa -des3 -passout pass:$PASSWORD -out certs/ca.key 2048
  13. # 生成 CA 证书
  14. openssl req -x509 -new -nodes -key certs/ca.key -sha256 -days 1024 -passin pass:$PASSWORD -out certs/ca_certificate.pem -subj "/CN=${IP_ADDRESS}"
  15. # 生成服务器密钥
  16. openssl genrsa -des3 -passout pass:$PASSWORD -out certs/server.key 2048
  17. # 生成服务器证书签名请求(CSR)
  18. openssl req -new -key certs/server.key -passin pass:$PASSWORD -out certs/server.csr -subj "/CN=${IP_ADDRESS}"
  19. # 创建一个配置文件用于扩展
  20. cat <<EOF > certs/openssl.cnf
  21. [ v3_ca ]
  22. basicConstraints = CA:TRUE
  23. [ v3_req ]
  24. basicConstraints = CA:FALSE
  25. subjectAltName = @alt_names
  26. [ alt_names ]
  27. IP.1 = ${IP_ADDRESS}
  28. EOF
  29. # 使用 CA 证书签署服务器证书
  30. openssl x509 -req -in certs/server.csr -CA certs/ca_certificate.pem -CAkey certs/ca.key -CAcreateserial -out certs/server_certificate.pem -days 500 -sha256 -passin pass:$PASSWORD -extfile certs/openssl.cnf -extensions v3_req
  31. # 转换服务器密钥为 PEM 格式
  32. openssl rsa -in certs/server.key -out certs/server_key.pem -passin pass:$PASSWORD -passout pass:$PASSWORD
  33. # 打印完成信息
  34. echo "Certificates and keys generated successfully in the 'certs' directory."
  35. echo "CA Certificate: certs/ca_certificate.pem"
  36. echo "Server Certificate: certs/server_certificate.pem"
  37. echo "Server Key: certs/server_key.pem"

Use in Ubuntu of WSL
generate_cert.sh &lt;test IP&gt; to generate

Then create rabbitmq.conf in the log/db directory of the RabbitMQ server

Paste the content of the first picture, then restart the rabbitMQ service, and then look at the management interface. The https port 15673 is successfully started.