MongoDB 服务器支持侦听同一 TCP 端口上的 TLS/SSL 加密连接和未加密连接。这支持 MongoDB 集群升级到使用 TLS/SSL 加密连接。
注意
MongoDB 在支持 TLS 1.1+ 的系统上禁用对 TLS 1.0 加密的支持。
过程(使用 tls 设置)
重要
TLS/SSL、PKI(公钥基础设施)证书和证书颁发机构的完整描述已超出本文档的范围。本页假设您已了解 TLS/SSL 并可访问有效证书。
要从不使用 TLS/SSL 加密的 MongoDB 集群升级到仅使用 TLS/SSL 加密的 MongoDB 集群,请使用以下滚动升级进程。
注意
本部分中的过程将使用 tls 设置/选项。有关使用其 ssl 别名的过程,请参阅过程(使用 ssl 设置)。
由于 MongoDB 始终支持 TLS 1.0 及更高版本,因此 tls 设置/选项可提供与 ssl 选项相同的功能。
For each node of a cluster, start the node with the command-line option
--tlsModeor the configuration file optionnet.tls.modeset toallowTLS. TheallowTLSsetting 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>要在配置文件中指定这些选项,请在文件中包含以下设置:
net: tls: mode: allowTLS certificateKeyFile: <path to TLS/SSL certificate and key PEM file> CAFile: <path to root CA PEM file>将集群的所有节点升级到这些设置。
将所有客户端切换为使用 TLS/SSL。请参阅 连接到启用 TLS 的副本集。
For each node of a cluster, use the
setParametercommand to update thetlsModetopreferTLS. [2] WithpreferTLSas itsnet.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。
For each node of the cluster, use the
setParametercommand to update thetlsModetorequireTLS. [2] WithrequireTLSas itsnet.tls.mode, the node will reject any non-TLS/non-SSL connections. For example:db.adminCommand( { setParameter: 1, tlsMode: "requireTLS" } )升级所有节点后,使用适当的 TLS/SSL 设置编辑配置文件,以确保在后续重新启动时,集群使用 TLS/SSL。
过程(使用 ssl 设置)
重要
TLS/SSL、PKI(公钥基础设施)证书和证书颁发机构的完整描述已超出本文档的范围。本页假设您已了解 TLS/SSL 并可访问有效证书。
要从不使用 TLS/SSL 加密的 MongoDB 集群升级到仅使用 TLS/SSL 加密的 MongoDB 集群,请使用以下滚动升级进程。
注意
本部分中的过程将使用 ssl 设置/选项。有关使用 tls 别名的过程,请参阅 升级集群以使用 TLS/SSL。
由于 MongoDB 始终支持 TLS 1.0 及更高版本,因此 tls 设置/选项可提供与 ssl 选项相同的功能。
For each node of a cluster, start the node with the command-line option
--sslModeor the configuration file optionnet.ssl.modeset toallowSSL. TheallowSSLsetting 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>要在配置文件中指定这些选项,请在文件中包含以下设置:
net: ssl: mode: <allowSSL> PEMKeyFile: <path to TLS/SSL certificate and key PEM file> CAFile: <path to root CA PEM file>将集群的所有节点升级到这些设置。
将所有客户端切换为使用 TLS/SSL。请参阅 连接到启用 TLS 的副本集。
For each node of a cluster, use the
setParametercommand to update thesslModetopreferSSL. [2] WithpreferSSLas itsnet.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。
For each node of the cluster, use the
setParametercommand to update thesslModetorequireSSL. [2] WithrequireSSLas itsnet.ssl.mode, the node rejects any non-TLS/non-SSL connections. For example:db.adminCommand( { setParameter: 1, sslMode: "requireSSL" } )升级所有节点后,使用适当的 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 证书存储,请使用:
在使用系统 SSL 证书存储区时,会用 OCSP(在线证书状态协议)来验证证书的吊销状态。 |