Restart a Sharded Cluster重新启动分片群集
On this page本页内容
The tutorial is specific to MongoDB 6.0. For earlier versions of MongoDB, refer to the corresponding version of the MongoDB Manual.本教程专门针对MongoDB 6.0。有关MongoDB的早期版本,请参阅相应版本的MongoDB手册。
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, shard servers may appear to hang if there are no config servers available.例如,如果没有可用的config
服务器,则分片服务器可能会挂起。
This procedure should only be performed during a planned maintenance period. 此程序只能在计划维护期间执行。During this period, applications should stop all reads and writes to the cluster in order to prevent potential data loss or reading stale data.在此期间,应用程序应停止对集群的所有读取和写入,以防止潜在的数据丢失或读取过时的数据。
Disable the Balancer禁用平衡器
Disable the balancer to stop chunk migration 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 要禁用平衡器,请连接到集群的一个mongos
instances and issue the following command: mongos
实例,然后发出以下命令:[1]
sh.stopBalancer()
To check the balancer state, issue the 要检查平衡器状态,请发出sh.getBalancerState()
command.sh.getBalancerState()
命令。
For more information, see Disable the Balancer.有关详细信息,请参阅禁用平衡器。
[1] | sh.stopBalancer() also disables auto-splitting for the sharded cluster.sh.stopBalancer() 还禁用了分片集群的自动拆分。 |
Stop Sharded Cluster停止分片群集
Stop mongos
routers.停止mongos
路由器。
mongos
routers.Run 在每个db.shutdownServer()
from the admin
database on each mongos
router:mongos
路由器上的管理数据库中运行db.shutdownServer()
:
use admin
db.shutdownServer()
Stop each shard replica set.停止每个分片复制集。
Run 在每个分片副本集成员的管理数据库中运行db.shutdownServer()
from the admin
database on each shard replica set member to shutdown its mongod
process. Shutdown all secondary members before shutting down the primary in each replica set.db.shutdownServer()
,以关闭其mongod
进程。在关闭每个复制集中的主成员之前,请先关闭所有辅助成员。
Stop config servers.停止配置服务器。
Run 从每个db.shutdownServer()
from the admin
database on each of the config servers to shutdown its mongod
process. Shutdown all secondary members before shutting down the primary.config
服务器上的管理数据库运行db.shutdownServer()
以关闭其mongod
进程。在关闭主成员之前关闭所有辅助成员。
Start Sharded Cluster启动分片群集
Start config servers.启动配置服务器。
When starting each 启动每个mongod
, specify the mongod
settings using either a configuration file or the command line. mongod
时,使用配置文件或命令行指定mongod
设置。For more information on startup parameters, see the 有关启动参数的更多信息,请参阅mongod
reference page.mongod
参考页面。
Configuration File配置文件
If using a configuration file, start the 如果使用配置文件,启动mongod
with the --config
option set to the configuration file path.mongod
时将--config
选项设置为配置文件路径。
mongod --config <path-to-config-file>
Command Line命令行
If using the command line options, start the 如果使用命令行选项,请使用mongod
with the --configsvr
, --replSet
, --bind_ip
, and other options as appropriate to your deployment. --configsvr
、--replSet
、--bind_ip
和其他适合您的部署的选项启动mongod
。For example:例如:
mongod --configsvr --replSet <replica set name> --dbpath <path> --bind_ip localhost,<hostname(s)|ip address(es)>
After starting all config servers, connect to the primary 启动所有配置服务器后,连接到主mongod
and run rs.status()
to confirm the health and availability of each CSRS member.mongod
并运行rs.status()
以确认每个CSRS成员的运行状况和可用性。
Start each shard replica set.启动每个分片复制集。
When starting each 启动每个mongod
, specify the mongod
settings using either a configuration file or the command line.mongod
时,使用配置文件或命令行指定mongod
设置。
Configuration File配置文件
If using a configuration file, start the 如果使用配置文件,启动mongod
with the --config
option set to the configuration file path.mongod
时将--config
选项设置为配置文件路径。
mongod --config <path-to-config-file>
Command Line命令行
If using the command line option, start the 如果使用命令行选项,请使用mongod
with the --replSet
, --shardsvr
, and --bind_ip
options, and other options as appropriate to your deployment. --replSet
、--shardsvr
和--bind_ip
选项以及其他适合您的部署的选项启动mongod
。For example:例如:
mongod --shardsvr --replSet <replSetname> --dbpath <path> --bind_ip localhost,<hostname(s)|ip address(es)>
After starting all members of each shard, connect to each primary 启动每个分片的所有成员后,连接到每个主mongod
and run rs.status()
to confirm the health and availability of each member.mongod
并运行rs.status()
来确认每个成员的健康状况和可用性。
Start mongos
routers.启动mongos
路由器。
mongos
routers.Start 使用配置文件或命令行参数启动mongos
routers using either a configuration file or a command line parameter to specify the config servers.mongos
路由器以指定配置服务器。
Configuration File配置文件
If using a configuration file, start the 如果使用配置文件,请启动mongos
specifying the --config
option and the path to the configuration file.mongos
,指定--config
选项和配置文件的路径。
mongos --config <path-to-config>
For more information on the configuration file, see configuration options.有关配置文件的更多信息,请参阅配置选项。
Command Line命令行
If using command line parameters, start the 如果使用命令行参数,请启动mongos
and specify the --configdb
, --bind_ip
, and other options as appropriate to your deployment. mongos
,并根据部署情况指定--configdb
、--bind_ip
和其他选项。For example:例如:
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. 在将实例绑定到可公开访问的IP地址之前,必须保护群集不受未经授权的访问。For a complete list of security recommendations, see Security Checklist. 有关安全建议的完整列表,请参阅安全检查表。At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证和强化网络基础设施。
mongos --configdb <configReplSetName>/cfg1.example.net:27019,cfg2.example.net:27019 --bind_ip localhost,<hostname(s)|ip address(es)>
Include any other options as appropriate for your deployment.包括适用于您的部署的任何其他选项。
Re-Enable the Balancer重新启用平衡器
Re-enable the balancer to resume chunk migrations.重新启用平衡器以恢复区块迁移。
Connect to one of the cluster's 连接到集群的一个mongos
instances and run the sh.startBalancer()
command: mongos
实例并运行sh.startBalancer()
命令:[2]
sh.startBalancer()
To check the balancer state, issue the 要检查平衡器状态,请发出sh.getBalancerState()
command.sh.getBalancerState()
命令。
For more information, see Enable the Balancer.有关详细信息,请参阅启用平衡器。
[2] | sh.startBalancer() also enables auto-splitting for the sharded cluster.sh.startBalancer() 还为分片集群启用了自动拆分。 |
Validate Cluster Accessibility验证群集可访问性
Connect a 将mongoshell连接到集群的一个mongo
shell to one of the cluster's mongos
processes. Use sh.status()
to check the overall cluster status.mongos
进程。使用sh.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 您可以将mongo
shell to each shard primary and use db.collection.find()
to validate that the data was sharded as expected.mongo
shell连接到每个分片primary
,并使用db.collection.find()
验证数据是否按预期进行了分片。
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.为了防止潜在的数据丢失或读取过时的数据,在确认集群正常且可访问之前,不要启动应用程序对集群的读写操作。