MongoDB-CN-Manual
  • MongoDB中文手册|官方文档中文版
  • MongoDB用户手册说明
  • MongoDB简介
    • 入门
    • 数据库和集合
      • 视图
      • 按需物化视图
      • 封顶集合
      • 时间序列集合
    • 文档
    • BSON类型
      • Comparison and Sort Order
      • MongoDB Extended JSON (v2)
      • MongoDB Extended JSON (v1)
  • 安装 MongoDB
    • 安装MongoDB社区版
      • 在Linux上安装MongoDB社区版
      • 在macOS上安装MongoDB社区版
      • 在Windows上安装MongoDB社区版
    • 安装MongoDB企业版
      • 在Linux上安装MongoDB企业版
      • 在Mac OS安装MongoDB企业版
      • 在Windows安装MongoDB企业版
      • 使用Docker安装MongoDB企业版
    • 将社区版MongoDB升级到企业版MongoDB
    • 验证MongoDB软件包的完整性
  • The mongo Shell
    • 配置mongo Shell
    • 使用 mongo Shell帮助
    • 为mongo Shell编写脚本
    • mongo Shell中的数据类型
    • mongo Shell 快速参考
  • MongoDB CRUD操作
    • 插入文档
      • 插入方法
    • 查询文档
      • 在mongo Shell中迭代游标
      • 从查询返回的项目字段
      • 查询嵌入式文档数组
      • 查询数组
      • 查询空字段或缺少字段
      • 查询嵌入/嵌套文档
    • 更新文档
      • 更新方法
      • 聚合管道更新
    • 删除文档
      • 删除方法
    • 地理空间查询
      • 用地理空间查询查找餐馆
      • GeoJSON对象
    • 批量写入操作
    • 可重试写入
    • 可重试读取
    • SQL到MongoDB的映射图表
    • 文本搜索
      • 文本索引
      • 文本索引操作
      • 集合管道中的文本索引
      • 文本索引语言
    • Read Concern读关注
      • 读关注 "local"
      • 读关注 "available"
      • 读关注 "majority"
      • 读关注 "linearizable"
      • 读关注 "snapshot"
    • Write Concern写关注
    • MongoDB CRUD概念
      • 原子性和事务
      • 读隔离性,一致性和近因性
        • 因果一致性和读写关注
      • 分布式查询
      • 通过findAndModify进行线性化读取
      • 查询计划
      • 查询优化
        • 评估当前操作性能
        • 优化查询性能
        • 写操作性能
        • 说明结果
      • 分析查询表现
      • Tailable 游标
  • MongoDB聚合
    • 聚合管道
      • 聚合管道优化
      • 聚合管道限制
      • 聚合管道和分片集合
      • 使用 Zip Code 数据集进行聚合
      • 使用用户首选项数据进行聚合
    • Map-Reduce
      • Map-Reduce 和分片集合
      • Map-Reduce 并发
      • Map-Reduce 示例
      • 执行增量 Map-Reduce
      • 对 Map Function 进行故障排除
      • 排除 Reduce Function 问题
      • Map-Reduce转换到聚合管道
    • 聚合参考
      • 聚合管道快速参考
      • 聚合命令
      • 聚合命令对比
      • 聚合表达式中的变量
      • SQL 到聚合映射图表
  • MongoDB数据模型
    • 数据建模介绍
    • 模式验证
    • 数据模型设计
      • 一对一嵌套关系模型
  • MongoDB事务
  • MongoDB事务
    • 驱动程序 API
    • 生产注意事项
    • 生产注意事项 (分片集群)
    • 事务操作
  • MongoDB索引
    • 单字段索引
    • 复合索引
    • 多键索引
      • 多键索引范围
    • 文本索引
      • 为文本索引指定语言
      • 指定文本索引的名称
      • 用权重控制搜索结果
      • 限制扫描条目的数量
    • 通配符索引
      • 通配符索引限制
    • 2dsphere 索引
      • 查询一个2dsphere索引
    • 2d 索引
      • 创建一个2d索引
      • 查询一个2d索引
      • 2d索引内部
      • 使用球面几何计算距离
    • geoHaystack 索引
      • 创建Haystack索引
      • 查询Haystack索引
    • 哈希索引
    • 索引特性
      • TTL 索引
        • 通过设置TTL使集合中的数据过期
      • 唯一索引
      • 部分索引
      • 不分大小写索引
      • Sparse 索引
    • 在填充的集合上建立索引
      • 在副本集上建立滚动索引
      • 在分片群集上建立滚动索引
    • 索引交集
    • 管理索引
    • 衡量索引使用
    • 索引策略
      • 创建索引来支持查询
      • 使用索引对查询结果进行排序
      • 确保索引适合RAM
      • 创建以确保选择性的查询
    • 索引参考
  • MongoDB安全
    • 安全检查列表
    • 启用访问控制
    • 身份验证
      • 用户
        • 添加用户
        • 权限认证机制
          • SCRAM
            • 用x.509证书来认证客户端
    • 审计
      • 配置审计过滤器
      • 配置审计
      • 系统事件审计消息
    • 网络和配置强化
    • 安全参考
      • system.roles集合
      • system.users集合
      • 资源文档
      • 权限操作
    • 附录
      • 附录-A-用于测试的 OpenSSl CA 证书
      • 附录-B-用于测试的OpenSSL服务器证书
      • 附录-C-用于测试的OpenSSL客户端证书
  • Change Streams变更流
    • 变更流生产建议
    • 变更事件
  • MongoDB复制
    • 副本集成员
    • 副本集日志
    • 副本集数据同步
    • 副本集部署架构
    • 副本集成员配置教程
    • 副本集维护教程
    • MongoDB复制参考
  • MongoDB分片
    • 分片集群组件
    • 分片键
    • 哈希分片
    • 范围分片
    • 区
      • 管理分片区
      • 按位置细分数据
      • 用于更改SLA或SLO的分层硬件
      • 按应用或客户细分数据
      • 仅插入工作负载的分布式本地写入
      • 管理分片区
    • 使用块进行数据分区
      • 在分片集群中拆分数据块
    • 分片管理
      • 查看集群设置
    • 重启一个分片集群
    • [把一个分片集群迁移到不同的硬件](fen-pian/migrate-a -sharded-cluster-to-different-hardware.md)
    • 分片参考
  • MongoDB管理
    • 产品说明
    • 操作检查列表
    • 开发检查列表
    • 配置和维护
    • 性能
    • 数据中心意识
      • MongoDB部署中的工作负载隔离
      • 区
        • 管理分片区
        • 按位置细分数据
        • 用于更改SLA或SLO的分层硬件
        • 按应用或客户细分数据
        • 仅插入工作负载的分布式本地写入
        • 管理分片区
    • MongoDB备份方法
    • MongoDB监控
  • MongoDB存储
    • 存储引擎
      • WiredTiger 存储引擎
      • 内存存储引擎
    • 日志记录
      • 管理日志记录
        • GridFS
        • FAQ:MongoDB 存储
  • MongoDB参考
    • 运算符
      • 查询与映射运算符
        • 比较查询运算符
          • $eq
          • $gt
          • $gte
          • $in
          • $lt
          • $lte
          • $ne
          • $nin
        • 逻辑查询运算符
          • $and
          • $not
          • $nor
          • $or
        • 元素查询运算符
        • 评估查询运算符
        • 地理空间查询运算符
        • 数组查询运算符
        • 按位查询运算符
        • $comment
        • 映射运算符
      • 更新运算符
        • 字段更新运算符
        • 数组更新运算符
        • 按位更新运算符
      • 聚合管道阶段
      • 聚合管道操作符
        • $abs (aggregation)
        • $acos (aggregation)
        • $acosh (aggregation)
        • $add (aggregation)
        • $addToSet (aggregation)
        • $allElementsTrue (aggregation)
        • $and (aggregation)
        • $anyElementTrue (aggregation)
        • $arrayElemAt (aggregation)
        • $arrayToObject (aggregation)
        • $asin (aggregation)
        • $asinh (aggregation)
        • $atan (aggregation)
        • $atan2 (aggregation)
        • $atanh (aggregation)
        • $avg (aggregation)
        • $ceil (aggregation)
        • $cmp (aggregation)
        • $concat (aggregation)
        • $concatArrays (aggregation)
        • $cond (aggregation)
        • $convert (aggregation)
        • $cos (aggregation)
        • $dateFromParts (aggregation)
        • $dateToParts (aggregation)
        • $dateFromString (aggregation)
        • $literal (aggregation)
      • 查询修饰符
    • 数据库命令
      • 聚合命令
      • 地理空间命令
      • 查询和写操作命令
      • 查询计划缓存命令
      • 认证命令
      • 用户管理命令
      • 角色管理命令
      • 复制命令
      • 分片命令
      • 会话命令
      • 管理命令
      • 诊断命令
      • 免费监控命令
      • 系统事件审计命令
    • mongo Shell 方法
      • 集合方法
        • db.collection.aggregate()
        • db.collection.bulkWrite()
        • db.collection.copyTo()
        • db.collection.count()
        • db.collection.countDocuments()
        • db.collection.estimatedDocumentCount()
        • db.collection.createIndex()
        • db.collection.createIndexes()
        • db.collection.dataSize()
        • db.collection.deleteOne()
        • db.collection.deleteMany()
        • db.collection.distinct()
        • db.collection.drop()
        • db.collection.dropIndex()
        • db.collection.dropIndexes()
        • db.collection.ensureIndex()
        • db.collection.explain()
        • db.collection.find()
        • db.collection.findAndModify()
        • db.collection.findOne()
        • db.collection.findOneAndDelete()
        • db.collection.findOneAndReplace()
        • db.collection.findOneAndUpdate()
        • db.collection.getIndexes()
        • db.collection.getShardDistribution()
        • db.collection.getShardVersion()
        • db.collection.insert()
        • db.collection.insertOne()
        • db.collection.insertMany()
        • db.collection.isCapped()
        • db.collection.latencyStats()
        • db.collection.mapReduce()
        • db.collection.reIndex()
        • db.collection.remove()
        • db.collection.renameCollection()
        • db.collection.replaceOne()
        • db.collection.save()
        • db.collection.stats()
        • db.collection.storageSize()
        • db.collection.totalIndexSize()
        • db.collection.totalSize()
        • db.collection.update()
        • db.collection.updateOne()
        • db.collection.updateMany()
        • db.collection.watch()
        • db.collection.validate()
    • MongoDB中的限制与阈值
    • MongoDB系统集合
    • 词汇表
    • 默认的MongoDB端口
    • 默认的MongoDB读/写关注
    • 服务器会话
  • MongoDB FAQ
    • FAQ: MongoDB基础知识
    • FAQ: MongoDB索引
    • FAQ: MongoDB并发
    • FAQ: MongoDB分片
    • FAQ: MongoDB复制和副本集
    • FAQ: MongoDB存储
    • FAQ: MongoDB诊断
  • MongoDB 版本管理
  • 联系我们
    • Tapdata Cloud
    • MongoDB中文社区
    • 社区合作伙伴—锦木信息
由 GitBook 提供支持
在本页
  • 重启一个分片集群 Restart a Sharded Cluster
  • Disable the Balancer
  • 禁用平衡器
  • Stop Sharded Cluster
  • 停止分片集群
  • 2.停止每个分片副本集
  • 3.停止配置服务器
  • Start Sharded Cluster
  • 启动分片集群
  • 1.启动配置服务器
  • Re-Enable the Balancer
  • 重新开启平衡器
  • Validate Cluster Accessibility
  • 验证集群可访问性
  1. MongoDB分片

重启一个分片集群

上一页查看集群设置下一页[把一个分片集群迁移到不同的硬件](fen-pian/migrate-a -sharded-cluster-to-different-hardware.md)

最后更新于3年前

重启一个分片集群 Restart a Sharded Cluster

The tutorial is specific to MongoDB 5.0. For earlier versions of MongoDB, refer to the corresponding version of the MongoDB Manual.

本教程对应的是MongoDB 5.0。对早期版本,可参考相关版本的手册。

This procedure demonstrates the shutdown and startup sequence for restarting a sharded cluster. Stopping or starting the components of a sharded cluster in a different order may cause communication errors between members. For example, servers may appear to hang if there are no available.

这一部分演示重启一个分片集群时关闭和启动的顺序。使用不同的顺序停止和开启一个分片集群,可能会导致成员间的通信错误。例如,如果没有配置有效的服务器会导致分片服务器挂起。

Disable the Balancer

禁用平衡器

Disable the balancer to stop and do not perform any metadata write operations until the process finishes. If a migration is in progress, the balancer will complete the in-progress migration before stopping.

禁用平衡器以停止块迁移,在操作完成之前不要进行任何大数据写操作。如果迁移正在进行,平衡器会在停止前完成正在进行的迁移。

To disable the balancer, connect to one of the cluster's instances and issue the following command: [

如果要关闭平衡器,连接一个mongos的实例,使用如下命令:

sh.stopBalancer()

To check the balancer state, issue the command.

检查平衡器状态,使用 命令。

For more information, see .

[1]

自MongoDB 4.2开始,sh.stopBalancer()也可以禁用分片集群的自动分割功能。

Stop Sharded Cluster

停止分片集群

use admin db.shutdownServer()

2.Stop each shard replica set

2.停止每个分片副本集

3.Stop config servers

3.停止配置服务器

Start Sharded Cluster

启动分片集群

1.Start config servers

1.启动配置服务器

Configuration File

配置文件

mongod --config <path-to-config-file>

Command Line

** 命令行**

mongod --configsvr --replSet <replica set name> --dbpath <path> --bind_ip localhost,<hostname(s)|ip address(es)>

2.Start each shard replica set

2.启动每个分片复本集

Configuration File

** 配置文件**

mongod --config <path-to-config-file>

Command Line

命令行

如果使用命令行,使用--replSet, --shardsvr和--bind_ip选项和其他相应选项启动mongod,例如:

mongod --shardsvr --replSet <replSetname> --dbpath <path> --bind_ip localhost,<hostname(s)|ip address(es)>

使用一个配置文件或者命令行参数指定配置服务器,启动 [mongos]路由。

Configuration File

** 配置文件**

mongos --config <path-to-config>

Command Line

** 命令行**

WARNING

警告

mongos --configdb <configReplSetName>/cfg1.example.net:27019,cfg2.example.net:27019 --bind_ip localhost,<hostname(s)|ip address(es)>

Re-Enable the Balancer

重新开启平衡器

重新开启平衡器以恢复块迁移。

sh.startBalancer()

[2]

Validate Cluster Accessibility

验证集群可访问性

IMPORTANT

重要

To prevent potential data loss or reading stale data, do not start application reads and writes to the cluster until after confirming the cluster is healthy and accessible.

为了避免潜在的数据丢失或读取垃圾数据,在确认集群是健康的和可访问之前,不要开始对集群的应用程序读写。

译者:张冲

时间:2021年8月20日

原文链接:https://docs.mongodb.com/manual/tutorial/restart-sharded-cluster/#stop-each-shard-replica-set

要了解更多信息,查看。

[]

Starting in MongoDB 4.2, also disables auto-splitting for the sharded cluster.

1.Stop routers

1.停止 路由

Run from the admin database on each router:

在每个 路由上,从admin数据库中运行 :

Run from the admin database on each replica set member to shutdown its process. Shutdown all secondary members before shutting down the primary in each replica set.

在每个分片复制集合成员的admin数据库中运行 ,以关闭其 进程。在每个复制集合关闭主模块之前,关闭所有的二级成员。

Run from the admin database on each of the to shutdown its process. Shutdown all secondary members before shutting down the primary.

在每个分片复制集合的admin数据库中运行 ,以关闭其 进程。在关闭主模块之前,关闭所有的二级成员。

When starting each , specify the settings using either a configuration file or the command line. For more information on startup parameters, see the reference page.

启动每个 时,使用一个配置文件或者命令行指定 的设置。要了解更多的启动参数,查看 参考页。

If using a configuration file, start the with the --config option set to the configuration file path.

如果使用配置文件,使用 --config 选项启动 以配置文件路径。

If using the command line options, start the with the --configsvr, --replSet, --bind_ip, and other options as appropriate to your deployment. For example:

如果使用命令行设置,用 --configsvr, --replSet, --bind_ip选项和其他适合配置的选项启动 ,例如:

After starting all config servers, connect to the primary and run to confirm the health and availability of each CSRS member.

启动所有的配置服务器之后,连接主mongod,并运行 以确认每个CSRS成员的健康和有效。

When starting each , specify the settings using either a configuration file or the command line.

启动每个时,使用配置文件或命令行指定设置。

If using a configuration file, start the with the --config option set to the configuration file path.

如果使用配置文件,使用--config选项配置文件路径并启动 。

If using the command line option, start the with the --replSet, --shardsvr, and --bind_ip options, and other options as appropriate to your deployment. For example:

After starting all members of each shard, connect to each primary and run to confirm the health and availability of each member.

在启动每个分片的所有成员之后,连接到每个主 并运行 以确认每个成员的健康和有效。

3.Start routers

3.启动 路由

Start routers using either a configuration file or a command line parameter to specify the config servers.

If using a configuration file, start the specifying the --config option and the path to the configuration file.

如果使用配置文件,指定--config选项配置文件路径并启动 。

For more information on the configuration file, see .

要了解更多配置文件信息,查看 。

If using command line parameters, start the and specify the --configdb, --bind_ip, and other options as appropriate to your deployment. For example:

如果使用命令行参数,指定--configdb, --bind_ip和其他相应选项启动 。例如:

Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. For a complete list of security recommendations, see . At minimum, consider and .

绑定到一个非本地IP地址之前,要确保你的集群如果遇到未授权访问的安全性。如果想查看安全建议的完整列表,查看Security Checklist。最少,考虑 和 。

Re-enable the balancer to resume .

Connect to one of the cluster's instances and run the command: [

连接一个集群的 实例并运行 命令:

To check the balancer state, issue the command.

使用 命令检查平衡器状态。

For more information, see .

要了解更多信息,查看。

[]

Starting in MongoDB 4.2, also enables auto-splitting for the sharded cluster.

自MongoDB 4.2开始, 也可以开启分片集群的自动分割功能。

Connect a shell to one of the cluster's processes. Use to check the overall cluster status.

连接一个 命令行到一个集群的 进程。使用 检查整体的集群状态。

To confirm that all shards are accessible and communicating, insert test data into a temporary sharded collection. Confirm that data is being split and migrated between each shard in your cluster. You can connect a shell to each shard primary and use to validate that the data was sharded as expected.

要确认所有的分片是可访问的和可通信的,把测试数据插入到一个临时的分片集合当中。在你的集合的每个分片间确认数据正在被分割和迁移。你可以把一个 命令行连接到每个分片的主块区,使用db.collection.find()验证数据是否按预期进行了分片。

shard
config servers
chunk migration
mongos
1]
sh.getBalancerState()
sh.getBalancerState()
Disable the Balancer
Disable the Balancer
mongos
mongos
db.shutdownServer()
mongos
mongos
db.shutdownServer()
db.shutdownServer()
shard
mongod
db.shutdownServer()
mongod
db.shutdownServer()
config servers
mongod
db.shutdownServer()
mongod
mongod
mongod
mongod
mongod
mongod
mongod
mongod
mongod
mongod
mongod
mongod
rs.status()
rs.status()
mongod
mongod
mongod
mongod
mongod
mongod
mongod
mongod
rs.status()
mongod
rs.status()
mongos
mongos
mongos
mongos
mongod
configuration options
configuration options
mongos
mongod
Security Checklist
enabling authentication
hardening network infrastructure
enabling authentication
hardening network infrastructure
chunk migrations
mongos
sh.startBalancer()
2]
mongos
sh.startBalancer()
sh.getBalancerState()
sh.getBalancerState()
Enable the Balancer
Enable the Balancer
mongo
mongos
sh.status()
mongo
mongos
sh.status()
mongo
db.collection.find()
mongo
1
sh.stopBalancer()
2
sh.startBalancer()
sh.startBalancer()