翻译或纠错本页面

将复制集模式下的 MongoDB 存储引擎切换到 WiredTiger

3.0 新版功能: WiredTiger 引擎目前是可用的. 而且, 同一个副本集中可以存在多种不同的存储引擎.

在 3.2 版更改: 在 MongoDB 最新版本中, WiredTiger 作为默认引擎出现.

这篇文档告诉你, 如何将 replica set 的存储引擎切换到 WiredTiger.

注意事项

复制集的不同成员可以使用不同的存储引擎. 因此, 你可以将复制集中的成员逐个升级为 WiredTiger 引擎, 在某些场景下, 你可能希望在一个复制集中同时运行多种存储引擎, 此时, 性能会随负载有所变动.

要使用 WiredTiger 引擎, MongoDB 版本必须为 3.0 或以上. 如果需要从更低版本的 MongoDB 升级, 在更改存储引擎之前, 需要参考 升级到 MongoDB 3.0 或者 升级到 MongoDB 3.2.

在使用新的 WiredTiger 存储引擎之前, 要确保分片/复制集中的成员的 MongoDB 版本至少为 2.6.8, 如果能到3.0或者最新是更好的选择.

步骤

这个步骤将复制集中 secondary 的数据完全移除, 然后使用 WiredTiger 存储引擎重启 mongod, 利用 :doc:`初始化同步 完成数据同步.

在升级复制集中的成员存储引擎时, 首先升级 secondary 成员. 然后将 primary 降级为从节点, 之后升级降级为从节点的成员.

1

Shut down the secondary member.

In the mongo shell, shut down the secondary mongod instance you wish to upgrade.

db.shutdownServer()
2

Prepare a data directory for the new mongod running with WiredTiger.

Prepare a data directory for the new mongod instance that will run with the WiredTiger storage engine. 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 with WiredTiger will not start with data files created with a different storage engine.

3

Start mongod with WiredTiger.

Start mongod, specifying wiredTiger as the --storageEngine and the prepared data directory for WiredTiger as the --dbpath. Specify additional options as appropriate for this replica set member.

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName>

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.

You can also specify the options in a configuration file. To specify the storage engine, use the storage.engine setting.

4

Repeat the procedure for other replica set secondaries you wish to upgrade.

Perform this procedure again for the rest of the secondary members of the replica set you wish to use the WiredTiger storage engine.