将分片群集更改为 WiredTiger

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

使用本教程将 MongoDB 3.6 分片群集更新为使用WiredTiger

对于早期版本的 MongoDB:

Considerations

Downtime

如果您更改任何shard的主机或端口,则还必须更新分片配置。

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 绑定兼容性更改

Config Servers

从 3.4 版开始,配置服务器必须为部署为副本集(CSRS)。因此,版本 3.4 配置服务器已经使用 WiredTiger 存储引擎。

XFS 和 WiredTiger

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

Procedure

Note

分片群集**可以为其单独的shards使用混合存储引擎。

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

要更改副本的存储引擎,请将shard设置为 WiredTiger:

A.将辅助成员更新为 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设置。

对其余的次要成员重复这些步骤,一次更新一个。

B.降级。

一旦所有辅助成员都升级到 WiredTiger,将mongo shell 连接到主要节点,并使用rs.stepDown()降级主要节点并强制选择新的主要节点。

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设置。

首页