Database Manual / Self-Managed Deployments / Storage / Storage Engines / WiredTiger

Change a Self-Managed Sharded Cluster to WiredTiger将自管理分片集群更改为WiredTiger

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 "majority" read concern, available for WiredTiger, is enabled by default. 默认情况下,WiredTiger启用了"majority"读取关注。However, if you have a three-member shard replica set with a primary-secondary-arbiter (PSA) architecture, you can disable "majority" read concern for that shard replica set. 但是,如果你有一个具有主从仲裁器(PSA)架构的三成员分片副本集,你可以禁用该分片副本集中的"majority"读取关注。Disabling "majority" for a three member PSA architecture avoids possible cache-pressure build up.禁用三成员PSA架构的"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 commands, you must resync the affected nodes with the primary node.如果需要回滚collMod命令,则必须将受影响的节点与primary节点重新同步。

Disabling "majority" read concern affects support for transactions on sharded clusters. Specifically:禁用"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 "majority", see Primary-Secondary-Arbiter Replica Sets.有关PSA架构的更多信息,请读取关注"majority",请参阅主从仲裁器副本集。

Default Bind to Localhost默认绑定到本地主机

MongoDB binaries, mongod and mongos, bind to localhost by default.MongoDB二进制文件mongodmongos默认绑定到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 Restrictions限制Short Description简短描述
Number of Namespaces命名空间数量For MMAPv1, the number of namespaces is limited to the size of the namespace file divided by 628.对于MMAPv1,命名空间的数量限制为命名空间文件的大小除以628。
Size of Namespace File命名空间文件的大小For MMAPv1, namespace files can be no larger than 2047 megabytes.对于MMAPv1,命名空间文件不能大于2047 MB。
Database Size数据库大小The MMAPv1 storage engine limits each database to no more than 16000 data files.MMAPv1存储引擎将每个数据库限制为不超过16000个数据文件。
Data Size数据大小For MMAPv1, a single mongod instance cannot manage a data set that exceeds maximum virtual memory address space provided by the underlying operating system.对于MMAPv1,单个mongod实例无法管理超过底层操作系统提供的最大虚拟内存地址空间的数据集。
Number of Collections in a Database数据库中的集合数For the MMAPv1 storage engine, the maximum number of collections in a database is a function of the size of the namespace file and the number of indexes of collections in the database.对于MMAPv1存储引擎,数据库中集合的最大数量是命名空间文件大小和数据库中集合索引数量的函数。

Before You Begin开始之前

Starting in MongoDB 8.0, you can use the directShardOperations role to perform maintenance operations that require you to execute commands directly against a shard.从MongoDB 8.0开始,您可以使用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:一次更新一个次要成员:

1

Shut down the secondary member.关闭次要成员。

In mongosh, shut down the secondary.在蒙古语中,关闭二级。

use admin
db.shutdownServer()
2

Prepare a data directory for the new mongod running with WiredTiger.为使用WiredTiger运行的新mongod准备一个数据目录。

Prepare a data directory for the new mongod instance that will run with the WiredTiger storage engine. 为将与WiredTiger存储引擎一起运行的新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必须具有此目录的读写权限。您可以删除已停止的辅助成员当前数据目录的内容,也可以完全创建一个新目录。

mongod with WiredTiger will not start with data files created with a different storage engine.带有WiredTiger的mongod不会从使用不同存储引擎创建的数据文件开始。

3

Update configuration for WiredTiger.更新WiredTiger的配置。

Remove any MMAPv1 configuration options from the mongod instance configuration.mongod实例配置中删除所有MMAPv1配置选项。

4

Start mongod with WiredTiger.用WiredTiger开始mongod

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 --enableMajorityReadConcern false to disable read concern majority. 如果您正在运行一个由三个成员组成的PSA架构,请包含--enableMajorityReadConcern false以禁用读取关注majoritySee PSA 3-member Architecture.请参阅PSA 3人架构

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)> --enableMajorityReadConcern false

Since 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 mongosh to the primary and use rs.stepDown() to step down the primary and force an election of a new primary.一旦所有次要成员都升级到WiredTiger,将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,如前所述:

1

Shut down the secondary member.关闭secondary成员。

In mongosh, shut down the secondary.在蒙古语中,关闭二级。

use admin
db.shutdownServer()
2

Prepare a data directory for the new mongod running with WiredTiger.为使用WiredTiger运行的新mongod准备一个数据目录。

Prepare a data directory for the new mongod instance that will run with the WiredTiger storage engine. 为将与WiredTiger存储引擎一起运行的新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必须具有此目录的读写权限。您可以删除已停止的辅助成员当前数据目录的内容,也可以完全创建一个新目录。

mongod with WiredTiger will not start with data files created with a different storage engine.带有WiredTiger的mongod不会从使用不同存储引擎创建的数据文件开始。

3

Update configuration for WiredTiger.更新WiredTiger的配置。

Remove any MMAPv1 configuration options from the mongod instance configuration.mongod实例配置中删除所有MMAPv1配置选项。

4

Start mongod with WiredTiger.用WiredTiger开始mongod

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 --enableMajorityReadConcern false to disable read concern majority. See PSA 3-member Architecture.如果您正在运行一个由三个成员组成的PSA架构,请包含--enableMajorityReadConcern false以禁用读取关注多数。请参阅PSA 3人架构

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)> --enableMajorityReadConcern false

Since 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.对其他分片重复该过程。