- 存储 >
- Storage Engines >
- WiredTiger Storage Engine >
- Change Sharded Cluster to WiredTiger >
- Change Config Servers to WiredTiger
Change Config Servers to WiredTiger¶
3.0 新版功能: The WiredTiger storage engine is available.
在 3.2 版更改: WiredTiger is the new default storage engine for MongoDB.
This tutorial gives an overview of changing the storage engine of the config servers in a sharded cluster to WiredTiger.
Considerations¶
You may safely continue to use MMAPv1 for the config servers even if one or more shards in the sharded cluster are using the WiredTiger storage engine. If you do choose to update the config servers to use WiredTiger, you must update all three.
You must be using MongoDB version 3.0 or greater in order to use the WiredTiger storage engine. If upgrading from an earlier version of MongoDB, see the guides on Upgrading to MongoDB 3.0 or Upgrading to MongoDB 3.2 before proceeding with changing your storage engine.
Procedure¶
This tutorial assumes that you have three config servers for this sharded cluster. The three servers are named first, second, and third, based on their position in the mongos configDB setting.
重要
During this process, at most only two config servers will be running at any given time to ensure that the sharded cluster’s metadata is read-only.
Disable the balancer.¶
sh.disableBalancer()
Turn off the balancer in the sharded cluster, as described in Disable the Balancer.
Shut down the third config server to ensure read-only metadata.¶
Connect a mongo shell to the third config server and use db.shutdownServer() to shut down the third config server.
The third config server is the last one listed in the mongos configDB setting.
db.shutdownServer()
Export the data of the second config server with mongodump.¶
While the third config server is down to ensure the config servers are read-only, prepare to upgrade the second config server to use WiredTiger. The second config server is the second server listed in the mongos setting configDB.
Export the data of the second config server with mongodump.
mongodump --out <exportDataDestination>
Specify additional options as appropriate, such as username and password if running with authorization enabled. See mongodump for available options.
For the second config server, create a new data directory for use with WiredTiger.¶
Create a data directory in preparation for having the second config server run with WiredTiger. mongod will not start if the --dbpath directory contains data files created with a different storage engine.
mongod must have read and write permissions for the new directory.
Stop the second config server.¶
Connect a mongo shell to the second config server and use db.shutdownServer() to shut down the second config server.
db.shutdownServer()
Start the second config server mongod with the WiredTiger storage engine option.¶
Start mongod as a config server, specifying wiredTiger as the --storageEngine and the newly created data directory for WiredTiger as the --dbpath. Specify additional options as appropriate.
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --configsvr
You can also specify the options in a configuration file. To specify the storage engine, use the storage.engine setting.
Upload the exported data using mongorestore to the second config server.¶
Use mongorestore to upload the exported data. Specify additional options as appropriate. See mongorestore for available options.
mongorestore <exportDataDestination>
When the mongorestore finishes, the second config server upgrade to use WiredTiger is complete.
Shut down the second config server to ensure read-only metadata.¶
When the second config server upgrade is complete, shut down the second config server in preparation to upgrade the other config servers. This is necessary to maintain at most only two active config servers and keep the sharded cluster’s metadata read-only.
Connect a mongo shell to the second config server and use db.shutdownServer() to shut down the second config server.
db.shutdownServer()
Restart the third config server to prepare for its upgrade.¶
Restart the third config server with its original startup options. Do not change its options to use the WiredTiger storage engine at this point.
mongod --configsvr --dbpath <existingDBPath>
Include any other options in use for the third config server.
For the third config server, create a new data directory for use with WiredTiger.¶
Create a data directory in preparation for having the third config server run with WiredTiger. mongod will not start if the --dbpath directory contains data files created with a different storage engine.
mongod must have read and write permissions for the new directory.
Stop the third config server.¶
Connect a mongo shell to the third config server and use db.shutdownServer() to shut down the third config server.
db.shutdownServer()
Start the third config server with the WiredTiger storage engine option.¶
Start mongod as a config server, specifying wiredTiger as the --storageEngine and the newly created data directory for WiredTiger as the --dbpath. Specify additional options as appropriate.
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --configsvr
You can also specify the options in a configuration file. To specify the storage engine, use the storage.engine setting.
Upload the exported data using mongorestore to the third config server.¶
Use mongorestore to upload the exported data. Specify additional options as appropriate. See mongorestore for available options.
mongorestore <exportDataDestination>
When the mongorestore finishes, the third config server upgrade to use WiredTiger is complete.
Export data of the first config server with mongodump.¶
To prepare for the upgrade of the first config server to use WiredTiger, export the data of the first config server with mongodump.
mongodump --out <exportDataDestination>
Specify additional options as appropriate, such as username and password if running with authorization enabled. See mongodump for available options.
For the first config server, create a new data directory for use with WiredTiger.¶
Create a data directory in preparation for having the first config server run with WiredTiger. mongod will not start if the --dbpath directory contains data files created with a different storage engine.
mongod must have read and write permissions for the new directory.
Stop the first config server.¶
Connect a mongo shell to the first config server and use db.shutdownServer() to shut down the first config server.
db.shutdownServer()
Start the first config server with the WiredTiger storage engine option.¶
Start mongod as a config server, specifying wiredTiger as the --storageEngine and the newly created data directory for WiredTiger as the --dbpath. Specify additional options as appropriate.
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --configsvr
You can also specify the options in a configuration file. To specify the storage engine, use the storage.engine setting.
Upload the exported data using mongorestore to the first config server.¶
Use mongorestore to upload the exported data. Specify additional options as appropriate. See mongorestore for available options.
mongorestore <exportDataDestination>
When the mongorestore finishes, the first config server upgrade to use WiredTiger is complete.
Restart the second config server to enable writes to the sharded cluster’s metadata.¶
Restart the second config server, specifying WiredTiger as the --storageEngine and the newly created WiredTiger data directory as the --dbpath. Specify additional options as appropriate.
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --configsvr
You can also specify the options in a configuration file. To specify the storage engine, use the storage.engine setting.
Once all three config servers are up, the sharded cluster’s metadata is available for writes.
Re-enable the balancer.¶
Once all three config servers are up and running with WiredTiger, re-enable the balancer.
sh.startBalancer()