Note
You must upgrade to WiredTiger. MongoDB removed the deprecated MMAPv1 storage engine in version 4.2.您必须升级到WiredTiger。MongoDB在4.2版本中删除了弃用的MMAPv1存储引擎。
Use this tutorial to update a sharded cluster to use WiredTiger.使用本教程更新分片集群以使用WiredTiger。
Considerations注意事项
Downtime停机时间
If you change the host or port of any shard, you must update the shard configuration as well.如果你更改了任何分片的主机或端口,你也必须更新分片配置。
PSA 3-member ArchitecturePSA三人架构
The 默认情况下,WiredTiger启用了"majority" read concern, available for WiredTiger, is enabled by default. "majority"读取关注。However, if you have a three-member shard replica set with a primary-secondary-arbiter (PSA) architecture, you can disable 但是,如果你有一个具有主从仲裁器(PSA)架构的三成员分片副本集,你可以禁用该分片副本集中的"majority" read concern for that shard replica set. "majority"读取关注。Disabling 禁用三成员PSA架构的"majority" for a three member PSA architecture avoids possible cache-pressure build up."majority"可以避免可能的缓存压力积聚。
Note
Disabling 禁用"majority" read concern has no effect on change streams availability."majority"读取关注不会影响更改流的可用性。
If you disable 如果禁用"majority" read concern, MongoDB prevents collMod commands which modify an index from rolling back. "majority"读取关注,MongoDB将阻止修改索引的collMod命令回滚。If you need to roll back 如果需要回滚collMod命令,则必须将受影响的节点与primary节点重新同步。collMod commands, you must resync the affected nodes with the primary node.
Disabling 禁用"majority" read concern affects support for transactions on sharded clusters. Specifically:"majority"读取关注会影响对分片集群上事务的支持。明确地:
A transaction cannot use read concern如果事务涉及已禁用读取关注"majority"的分片,则事务不能使用读取关注"snapshot"if the transaction involves a shard that has disabled read concern "majority"."snapshot"。A transaction that writes to multiple shards errors if any of the transaction's read or write operations involves a shard that has disabled read concern如果事务的任何读取或写入操作涉及已禁用读取的分片,则写入"majority"."majority"分片的事务会出错。
However, it does not affect transactions on replica sets. 但是,它不会影响副本集上的事务。For transactions on replica sets, you can specify read concern 对于副本集上的事务,即使禁用了读取关注"majority" (or "snapshot" or "local" ) for distributed transactions even if read concern "majority" is disabled."majority",您也可以为分布式事务指定读取关注"majority"(或"snapshot"或"local")。
For more information on PSA architecture and read concern 有关PSA架构的更多信息,请读取关注"majority", see Primary-Secondary-Arbiter Replica Sets."majority",请参阅主从仲裁器副本集。
Default Bind to Localhost默认绑定到本地主机
MongoDB binaries, MongoDB二进制文件mongod and mongos, bind to localhost by default.mongod和mongos默认绑定到localhost。
Config Servers配置服务器
Config servers must be deployed as replica sets (CSRS). As such, config servers already use the WiredTiger storage engine.配置服务器必须作为副本集(CSRS)部署。因此,配置服务器已经使用了WiredTiger存储引擎。
XFS and WiredTigerXFS和WiredTiger
With the WiredTiger storage engine, using XFS for data bearing nodes is recommended on Linux. For more information, see Kernel and File Systems.对于WiredTiger存储引擎,建议在Linux上使用XFS作为数据承载节点。有关更多信息,请参阅内核和文件系统。
MMAPv1 Only Restrictions仅限限制
Once upgraded to WiredTiger, your WiredTiger deployment is not subject to the following MMAPv1-only restrictions:升级到WiredTiger后,WiredTiger部署不受以下仅限MMAPv1的限制:
| MMAPv1 | |
|---|---|
mongod instance cannot manage a data set that exceeds maximum virtual memory address space provided by the underlying operating system.mongod实例无法管理超过底层操作系统提供的最大虚拟内存地址空间的数据集。 | |
Before You Begin开始之前
Starting in MongoDB 8.0, you can use the 从MongoDB 8.0开始,您可以使用directShardOperations role to perform maintenance operations that require you to execute commands directly against a shard.directShardOperations角色执行维护操作,这些操作要求您直接对分片执行命令。
Warning
Running commands using the 使用directShardOperations role can cause your cluster to stop working correctly and may cause data corruption. directShardOperations角色运行命令可能会导致集群停止正常工作,并可能导致数据损坏。Only use the 仅将directShardOperations role for maintenance purposes or under the guidance of MongoDB support. directShardOperations角色用于维护目的或在MongoDB支持的指导下使用。Once you are done performing maintenance operations, stop using the 完成维护操作后,停止使用directShardOperations role.directShardOperations角色。
Procedure过程
For each replica set shard, to change the storage engine to WiredTiger:对于每个副本集分片,要将存储引擎更改为WiredTiger:
A. Update the secondary members to WiredTiger.将次要成员更新为WiredTiger。
Update the secondary members one at a time:一次更新一个次要成员:
Shut down the secondary member.关闭次要成员。
In 在蒙古语中,关闭二级。mongosh, shut down the secondary.
use admin
db.shutdownServer()Prepare a data directory for the new mongod running with WiredTiger.为使用WiredTiger运行的新mongod准备一个数据目录。
mongod running with WiredTiger.Prepare a data directory for the new 为将与WiredTiger存储引擎一起运行的新mongod instance that will run with the WiredTiger storage engine. mongod实例准备一个数据目录。mongod must have read and write permissions for this directory. You can either delete the contents of the stopped secondary member's current data directory or create a new directory entirely.mongod必须具有此目录的读写权限。您可以删除已停止的辅助成员当前数据目录的内容,也可以完全创建一个新目录。
带有WiredTiger的mongod with WiredTiger will not start with data files created with a different storage engine.mongod不会从使用不同存储引擎创建的数据文件开始。
Update configuration for WiredTiger.更新WiredTiger的配置。
Remove any MMAPv1 configuration options from the 从mongod instance configuration.mongod实例配置中删除所有MMAPv1配置选项。
Start mongod with WiredTiger.用WiredTiger开始mongod。
mongod with WiredTiger.Start 启动mongod, specifying wiredTiger as the --storageEngine and the prepared data directory for WiredTiger as the --dbpath.mongod,将wiredTiger指定为--storageEngine,将为wiredTiger准备的数据目录指定为--dbpath。
Specify additional options as appropriate, such as 根据需要指定其他选项,例如--bind_ip.--bind_ip。
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. 在将实例绑定到可公开访问的IP地址之前,必须保护集群免受未经授权的访问。For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. 有关安全建议的完整列表,请参阅自我管理部署的安全检查表。At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证并加强网络基础设施。
General Use (For Most Architectures)一般用途(适用于大多数架构)
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)>PSA ArchitecturePSA架构
Important
If you are running a three-member PSA architecture, include 如果您正在运行一个由三个成员组成的PSA架构,请包含--enableMajorityReadConcern false to disable read concern majority. --enableMajorityReadConcern false以禁用读取关注majority。See PSA 3-member Architecture.请参阅PSA 3人架构。
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)> --enableMajorityReadConcern falseSince no data exists in the 由于--dbpath, the mongod will perform an initial sync. The length of the initial sync process depends on the size of the database and network connection between members of the replica set.--dbpath中没有数据,mongod将执行初始同步。初始同步过程的长度取决于数据库的大小和副本集成员之间的网络连接。
You can also specify the options in a configuration file. 您还可以在配置文件中指定选项。To specify the storage engine, use the 要指定存储引擎,请使用storage.engine setting.storage.engine设置。
Repeat the steps for the remaining secondary members, updating them one at a time.对剩余的次要成员重复这些步骤,一次更新一个。
B. Step down the primary.退出primary。
Once all the secondary members have been upgraded to WiredTiger, connect 一旦所有次要成员都升级到WiredTiger,将mongosh to the primary and use rs.stepDown() to step down the primary and force an election of a new primary.mongosh连接到主要成员,并使用rs.stepDown()退出主要成员并强制选举新的主要成员。
rs.stepDown()C. Update the old primary.更新旧的primary。
When the primary has stepped down and become a secondary, update the secondary to use WiredTiger as before:当主节点降级为次节点时,更新次节点以使用WiredTiger,如前所述:
Shut down the secondary member.关闭secondary成员。
In 在蒙古语中,关闭二级。mongosh, shut down the secondary.
use admin
db.shutdownServer()Prepare a data directory for the new mongod running with WiredTiger.为使用WiredTiger运行的新mongod准备一个数据目录。
mongod running with WiredTiger.Prepare a data directory for the new 为将与WiredTiger存储引擎一起运行的新mongod instance that will run with the WiredTiger storage engine. mongod实例准备一个数据目录。mongod must have read and write permissions for this directory. You can either delete the contents of the stopped secondary member's current data directory or create a new directory entirely.mongod必须具有此目录的读写权限。您可以删除已停止的辅助成员当前数据目录的内容,也可以完全创建一个新目录。
带有WiredTiger的mongod with WiredTiger will not start with data files created with a different storage engine.mongod不会从使用不同存储引擎创建的数据文件开始。
Update configuration for WiredTiger.更新WiredTiger的配置。
Remove any MMAPv1 configuration options from the 从mongod instance configuration.mongod实例配置中删除所有MMAPv1配置选项。
Start mongod with WiredTiger.用WiredTiger开始mongod。
mongod with WiredTiger.Start 启动mongod, specifying wiredTiger as the --storageEngine and the prepared data directory for WiredTiger as the --dbpath.mongod,将wiredTiger指定为--storageEngine,将为wiredTiger准备的数据目录指定为--dbpath。
Specify additional options as appropriate, such as 根据需要指定其他选项,例如--bind_ip.--bind_ip。
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. 在将实例绑定到可公开访问的IP地址之前,必须保护集群免受未经授权的访问。For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. 有关安全建议的完整列表,请参阅自我管理部署的安全检查表。At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证并加强网络基础设施。
General Use (For Most Architectures)一般用途(适用于大多数架构)
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)>PSA ArchitecturePSA架构
Important
If you are running a three-member PSA architecture, include 如果您正在运行一个由三个成员组成的PSA架构,请包含--enableMajorityReadConcern false to disable read concern majority. See PSA 3-member Architecture.--enableMajorityReadConcern false以禁用读取关注多数。请参阅PSA 3人架构。
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)> --enableMajorityReadConcern falseSince no data exists in the 由于--dbpath, the mongod will perform an initial sync. The length of the initial sync process depends on the size of the database and network connection between members of the replica set.--dbpath中没有数据,mongod将执行初始同步。初始同步过程的长度取决于数据库的大小和副本集成员之间的网络连接。
You can also specify the options in a configuration file. To specify the storage engine, use the 您还可以在配置文件中指定选项。要指定存储引擎,请使用storage.engine setting.storage.engine设置。
Repeat the procedure for the other shards.对其他分片重复该过程。