对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

db.rotateCertificates()(mongosh方法)

版本 5.0 中的新增功能。

db.rotateCertificates(message)

Rotates the currently used TLS certificates for a mongod or mongos to use the updated values for these certificates defined in the configuration file.

db.rotateCertificates(message)

The db.rotateCertificates() method takes the following optional argument:

Parameter
类型
说明

message

字符串

可选服务器记录到日志文件和审核文件中的消息。

The db.rotateCertificates() method wraps the rotateCertificates command.

此方法可用于以下环境中托管的部署:

重要

MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令

注意

Atlas会自动轮换证书。使用Atlas时,无需运行rotateCertificates 命令。仅当您想手动轮换证书时才使用 rotateCertificates 命令。

The db.rotateCertificates() method returns a document with the following field:

字段
类型
说明

ok

bool

包含命令的执行状态。 成功则为true ,如果发生错误则为false 。 如果为false ,则另外向errmsg字段提供详细的错误消息。

轮换包括以下证书:

轮换一个或多个证书:

  1. 替换您要在文件系统中轮换的证书,并注意以下限制:

    • 每个新证书的文件名文件路径必须与被替换的证书相同。

    • 如果轮换加密的 TLS Certificate,其密码必须与旧证书的密码相同(如 certificateKeyFilePassword 配置文件设置所指定)。证书轮换不支持交互式密码提示。

  2. Connect mongosh to the mongod or mongos instance that you wish to perform certificate rotation on.

  3. Run db.rotateCertificates() to rotate the certificates used by the mongod or mongos instance.

当证书轮换发生时:

  • mongod}mongos 实例的现有连接不会终止,并将继续使用旧证书。

  • 所有新连接都将使用新证书。

If you have configured OCSP for your deployment, the db.rotateCertificates() method will also fetch stapled OCSP responses during rotation.

The db.rotateCertificates() method may be run on a running mongod or mongos regardless of replication status.

Only one instance of db.rotateCertificates() or rotateCertificates may run on each mongod or mongos process at a time. Attempting to initiate a second instance while one is already running will result in an error.

证书文件错误、过期、撤销或丢失会导致证书轮换失败,但不会导致现有 TLS 配置失效或终止正在运行的 mongodmongos 进程。

If the mongod or mongos is running with --tlsCertificateSelector set to thumbprint, db.rotateCertificates() will fail and write a warning message to the log file.

成功轮换后,主题名称、指纹以及服务器和集群证书指纹的有效期都会记录到配置的日志目标中。 如果已启用审核,此信息也会写入审核日志。

在 Linux 和 Windows 平台上,如果存在CRL file ,其指纹和有效期也会记录到这些位置。

You must have the rotateCertificates action in order to use the db.rotateCertificates() method. The rotateCertificates action is part of the hostManager role.

对配置文件进行适当更新以指定更新的证书信息后,以下操作将在运行中的mongod实例上轮换证书:

db.rotateCertificates()

以下操作的执行与上述操作相同,但还会在轮换时将自定义日志消息写入日志文件审核文件:

db.rotateCertificates("message": "Rotating certificates")