将副本集更改为 WiredTiger

从 3.2 版开始,WiredTiger 是 MongoDB 的默认存储引擎。

本教程概述了将replica set成员的存储引擎更改为WiredTiger的过程。

Considerations

副本集可以具有具有不同存储引擎的成员。这样,您可以更新成员以滚动方式使用 WiredTiger 存储引擎。

MongoDB 3.6 和 PSA 3 成员架构

从 MongoDB 3.6 开始,默认启用"majority"读取关注(可用于 WiredTiger)。但是,对于 MongoDB 3.6.1-3.6.x ,如果您具有具有主要-次要仲裁器(PSA)体系结构的三成员副本集,则可以禁用"majority"读取关注。为三成员 PSA 架构禁用"majority"可以避免可能的缓存压力增加。

以下过程通过包含--enableMajorityReadConcern false来禁用 MongoDB 3.6.1-3.6.x PSA 体系结构的"majority"读取关注。如果您正在运行 MongoDB 3.6.0 PSA 体系结构,请首先升级到最新的 3.6 版本,以禁用此已读问题。

Note

禁用"majority"读取关注会禁用对Change Streams的支持。

有关 PSA 架构的更多信息并阅读关注"majority",请参阅禁用多数阅读关注

MongoDB 3.0 或更高版本

Note

您必须使用 MongoDB 3.0 或更高版本才能使用 WiredTiger 存储引擎。如果使用的是 MongoDB 的早期版本,则必须先升级 MongoDB 的版本,然后才能更改存储引擎。要升级您的 MongoDB 版本,请参考手册的相应版本。

默认绑定到 localhost

Note

从 MongoDB 3.6 开始,MongoDB 二进制文件mongodmongos默认绑定到localhost。从 MongoDB 版本 2.6 到 3.4,默认情况下,只有来自正式 MongoDB RPM(Red Hat,CentOS,Fedora Linux 和衍生产品)和 DEB(Debian,Ubuntu 和衍生产品)软件包的二进制文件会绑定到localhost。要了解有关此更改的更多信息,请参见Localhost 绑定兼容性更改

XFS 和 WiredTiger

对于 WiredTiger 存储引擎,建议在 Linux 上将 XFS 用于数据承载节点。有关更多信息,请参见内核和文件系统

Procedure

要将成员更新为 WiredTiger,该过程将删除成员的数据,以 WiredTiger 开头mongod,然后执行initial sync

Tip

  • 要更新副本集的所有成员以使用 WiredTiger,请以滚动方式更新成员。也就是说,首先更新所有secondary成员。然后,一旦所有辅助成员都已更新,则step down primary并更新该降级成员。

  • 如果您正在运行 MongoDB 3.6.0 三成员 PSA 体系结构,并且希望禁用"majority"读取关注,请首先升级到最新的 3.6 版本。

A.更新次要成员。

关闭次要成员。

mongo shell 中,关闭辅助mongod实例。

use admin
db.shutdownServer()

为使用 WiredTiger 运行的新 mongod 准备一个数据目录。

为将与 WiredTiger 存储引擎一起运行的新mongod实例准备一个数据目录。 mongod必须对此目录具有读写权限。您可以删除已停止的辅助成员当前数据目录的内容,也可以完全创建一个新目录。

带有 WiredTiger 的mongod不会以使用其他存储引擎创建的数据文件开头。

使用 WiredTiger 启动 mongod。

开始mongod,将wiredTiger指定为--storageEngine,并将 WiredTiger 的准备数据目录指定为--dbpath。指定适合此副本集成员的其他选项,例如--bind_ip

Warning

绑定到非 localhost(例如可公开访问)的 IP 地址之前,请确保已保护群集免受未经授权的访问。有关安全建议的完整列表,请参见Security Checklist。至少考虑enabling authentication加强网络基础设施

General Use (For Most Architectures)
PSA Architecture
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<ipaddresses>

Important

If you are running a three-member PSA architecture and MongoDB version 3.6.1-3.6.x, include --enableMajorityReadConcern false to disable read concern majority . See MongoDB 3.6 and PSA 3-member Architecture.

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<ipaddresses> --enableMajorityReadConcern false

由于--dbpath中没有数据,因此mongod将执行initial sync。初始同步过程的长度取决于数据库的大小以及副本集成员之间的网络连接。

您也可以在configuration file中指定选项。要指定存储引擎,请使用storage.engine设置。

要更新另一个辅助服务器,请重复前面的步骤。

B.降级。

Important

如果将副本集的所有成员更新为使用 WiredTiger,请确保在更新主副本之前先更新了所有辅助副本。

要更新主要数据库,请step down primary

Note

rs.stepDown()

C.更新已降级的主数据库。

当主节点降级并成为辅助节点后,请像以前一样更新辅助节点以使用 WiredTiger:

Warning

关闭次要成员。

mongo shell 中,关闭辅助mongod实例。

use admin
db.shutdownServer()

为使用 WiredTiger 运行的新 mongod 准备一个数据目录。

为将与 WiredTiger 存储引擎一起运行的新mongod实例准备一个数据目录。 mongod必须对此目录具有读写权限。您可以删除已停止的辅助成员当前数据目录的内容,也可以完全创建一个新目录。

带有 WiredTiger 的mongod不会以使用其他存储引擎创建的数据文件开头。

使用 WiredTiger 启动 mongod。

开始mongod,将wiredTiger指定为--storageEngine,并将 WiredTiger 的准备数据目录指定为--dbpath。指定适合此副本集成员的其他选项,例如--bind_ip

Warning

绑定到非 localhost(例如可公开访问)的 IP 地址之前,请确保已保护群集免受未经授权的访问。有关安全建议的完整列表,请参见Security Checklist。至少考虑enabling authentication加强网络基础设施

General Use (For Most Architectures)
PSA Architecture
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<ipaddresses>

Important

If you are running a three-member PSA architecture and MongoDB version 3.6.1-3.6.x, include --enableMajorityReadConcern false to disable read concern majority . See MongoDB 3.6 and PSA 3-member Architecture.

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<ipaddresses> --enableMajorityReadConcern false

由于--dbpath中没有数据,因此mongod将执行initial sync。初始同步过程的长度取决于数据库的大小以及副本集成员之间的网络连接。

您也可以在configuration file中指定选项。要指定存储引擎,请使用storage.engine设置。