https://docs.mongodb.com/manual/core/security-transport-encryption/
关于MongoDB 的SSL 配置, 官方文档挺齐全的
win10 64位 安装 OpenSSL-Win64 的安装版, 添加环境变量path
由于文档提供的基本是Linux 的, 网上搜索到的也是Linux 这样的, 自己改成了 windows 的
G:
cd G:\ca
openssl req -newkey rsa:2048 -new -x509 -days 365 -nodes -out mongodb-cert.crt -keyout mongodb-cert.key
copy /b /y mongodb-cert.key+mongodb-cert.crt mongodb.pem
这个是直接使用了CA根证书, 和由key+证书组成的CA服务器证书(mongodb 要求key+cert 合成的pem)
配置文件
net:
port: 27000
bindIp: 127.0.0.1
ssl:
mode: requireSSL
PEMKeyFile: G:\ca\mongodb.pem
CAFile: G:\ca\mongodb-cert.crt
allowInvalidHostnames: true
如果有集群, 加上
security:
authorization: enabled
clusterAuthMode: x509
启动MongoDB 后, 用mongo 客户端连接, 因为是自己建的证书, 所以--sslA