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

升级集群以使用 TLS/SSL

MongoDB 服务器支持侦听同一 TCP 端口上的 TLS/SSL 加密连接和未加密连接。这支持 MongoDB 集群升级到使用 TLS/SSL 加密连接。

注意

MongoDB 在支持 TLS 1.1+ 的系统上禁用对 TLS 1.0 加密的支持。

重要

TLS/SSL、PKI(公钥基础设施)证书和证书颁发机构的完整描述已超出本文档的范围。本页假设您已了解 TLS/SSL 并可访问有效证书。

要从不使用 TLS/SSL 加密的 MongoDB 集群升级到仅使用 TLS/SSL 加密的 MongoDB 集群,请使用以下滚动升级进程。

注意

本部分中的过程将使用 tls 设置/选项。有关使用其 ssl 别名的过程,请参阅过程(使用 ssl 设置)。

由于 MongoDB 始终支持 TLS 1.0 及更高版本,因此 tls 设置/选项可提供与 ssl 选项相同的功能。

  1. For each node of a cluster, start the node with the command-line option --tlsMode or the configuration file option net.tls.mode set to allowTLS. The allowTLS setting allows the node to accept both TLS/SSL and non-TLS/non-SSL incoming connections. Its connections to other servers do not use TLS/SSL. Include other TLS/SSL options [1] as well as any other options that are required for your specific configuration.

    注意

    link_link__5o4ll link_linkInline__lmvkS 和 link_link__5o4ll link_linkInline__lmvkS,默认绑定到本地主机。如果部署的成员在不同的主机上运行,或者希望远程客户端连接到部署,则必须指定 --bind_ip 或 net.bindIp。

    例如:

    mongod --replSet <name> --tlsMode allowTLS --tlsCertificateKeyFile <TLS/SSL certificate and key file> --tlsCAFile <path to root CA PEM file> <additional options>

    将集群的所有节点升级到这些设置。

  2. 将所有客户端切换为使用 TLS/SSL。请参阅 连接到启用 TLS 的副本集。

  3. For each node of a cluster, use the setParameter command to update the tlsMode to preferTLS. [2] With preferTLS as its net.tls.mode, the node accepts both TLS/SSL and non-TLS/non-SSL incoming connections, and its connections to other servers use TLS/SSL. For example:

    db.adminCommand( { setParameter: 1, tlsMode: "preferTLS" } )

    将集群的所有节点升级到这些设置。

    此时,所有连接都应使用 TLS/SSL。

  4. For each node of the cluster, use the setParameter command to update the tlsMode to requireTLS. [2] With requireTLS as its net.tls.mode, the node will reject any non-TLS/non-SSL connections. For example:

    db.adminCommand( { setParameter: 1, tlsMode: "requireTLS" } )
  5. 升级所有节点后,使用适当的 TLS/SSL 设置编辑配置文件,以确保在后续重新启动时,集群使用 TLS/SSL。

重要

TLS/SSL、PKI(公钥基础设施)证书和证书颁发机构的完整描述已超出本文档的范围。本页假设您已了解 TLS/SSL 并可访问有效证书。

要从不使用 TLS/SSL 加密的 MongoDB 集群升级到仅使用 TLS/SSL 加密的 MongoDB 集群,请使用以下滚动升级进程。

注意

本部分中的过程将使用 ssl 设置/选项。有关使用 tls 别名的过程,请参阅 升级集群以使用 TLS/SSL。

由于 MongoDB 始终支持 TLS 1.0 及更高版本,因此 tls 设置/选项可提供与 ssl 选项相同的功能。

  1. For each node of a cluster, start the node with the command-line option --sslMode or the configuration file option net.ssl.mode set to allowSSL. The allowSSL setting allows the node to accept both TLS/SSL and non-TLS/non-SSL incoming connections. Its connections to other servers do not use TLS/SSL. Include other TLS/SSL options [1] as well as any other options that are required for your specific configuration.

    注意

    link_link__5o4ll link_linkInline__lmvkS 和 link_link__5o4ll link_linkInline__lmvkS,默认绑定到本地主机。如果部署的成员在不同的主机上运行,或者希望远程客户端连接到部署,则必须指定 --bind_ip 或 net.bindIp。

    例如:

    mongod --replSet <name> --sslMode allowSSL --sslPEMKeyFile <path to TLS/SSL Certificate and key PEM file> --sslCAFile <path to root CA PEM file> <additional options>

    将集群的所有节点升级到这些设置。

  2. 将所有客户端切换为使用 TLS/SSL。请参阅 连接到启用 TLS 的副本集。

  3. For each node of a cluster, use the setParameter command to update the sslMode to preferSSL. [2] With preferSSL as its net.ssl.mode, the node accepts both TLS/SSL and non-TLS/non-SSL incoming connections, and its connections to other servers use TLS/SSL. For example:

    db.adminCommand( { setParameter: 1, sslMode: "preferSSL" } )

    将集群的所有节点升级到这些设置。

    此时,所有连接都应使用 TLS/SSL。

  4. For each node of the cluster, use the setParameter command to update the sslMode to requireSSL. [2] With requireSSL as its net.ssl.mode, the node rejects any non-TLS/non-SSL connections. For example:

    db.adminCommand( { setParameter: 1, sslMode: "requireSSL" } )
  5. 升级所有节点后,使用适当的 TLS/SSL 设置编辑配置文件,以确保在后续重新启动时,集群使用 TLS/SSL。

[2](1, 2, 3, 4) As an alternative to using the setParameter command, you can also restart the nodes with the appropriate TLS/SSL options and values.
[1](1, 2)

您可以使用适用于Windows和 macOS 的系统 SSL 证书存储区。 要使用系统 SSL 证书存储,请使用:

  • net.tls.certificateSelector(或命令行选项 --tlsCertificateSelector)而不是 net.tls.certificateKeyFile(或命令行选项 ``--certificateKeyfile``)。

  • net.ssl.certificateSelector (或命令行选项--sslCertificateSelector )而不是net.ssl.PEMKeyFile (或命令行选项``-sslPEMKeyFile``)。

在使用系统 SSL 证书存储区时,会用 OCSP(在线证书状态协议)来验证证书的吊销状态。

给本页内容打分