Changed in version 5.0.在版本5.0中的更改。
shutdownTheshutdowncommand cleans up all database resources and then terminates the process. You must issue theshutdowncommand against the admin database.shutdown命令清理所有数据库资源,然后终止进程。您必须对admin数据库发出shutdown命令。
Compatibility兼容性
This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Important
This command is not supported in MongoDB Atlas clusters. MongoDB Atlas集群不支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
Syntax语法
The command has the following syntax:该命令具有以下语法:
db.adminCommand(
{
shutdown: 1,
force: <boolean>
timeoutSecs: <int>,
comment: <any>
}
)Command Fields命令字段
The command takes these fields:该命令包含以下字段:
shutdown |
|
force |
|
timeoutSecs |
|
comment |
|
Behavior行为
For a 对于以自我管理部署身份验证开始的mongod started with Authentication on Self-Managed Deployments, you must run shutdown over an authenticated connection. See Access Control for more information.mongod,您必须在经过身份验证的连接上运行关机。有关更多信息,请参阅访问控制。
For a 对于在自我管理部署上没有身份验证的mongod started without Authentication on Self-Managed Deployments, you must run shutdown from a client connected to the localhost interface. mongod,您必须从连接到localhost接口的客户端运行关机。For example, run 例如,在与mongosh with the --host "127.0.0.1" option on the same host machine as the mongod.mongod相同的主机上运行带有--host "127.0.0.1"选项的mongosh。
shutdown on Replica Set Members在副本集成员上shutdown
shutdown on Replica Set Membersshutdown fails if the replica set member is running certain operations such as index builds. 如果副本集成员正在运行某些操作(如索引构建),则失败。You can specify force: true to force the member to save index build progress to disk. 您可以指定force: true强制成员将索引构建进度保存到磁盘。The mongod recovers the index build when it restarts and continues from the saved checkpoint.mongod在重新启动时恢复索引构建,并从保存的检查点继续。
Shutting Down the Replica Set Primary, Secondary, or mongos关闭主副本集、次副本集或mongos副本集
mongosStarting in MongoDB 5.0, 从MongoDB 5.0开始,mongod and mongos enter a quiesce period to allow any ongoing database operations to complete before shutting down.mongod和mongos进入一个停顿期,以便在关闭之前完成任何正在进行的数据库操作。
If a 如果mongod primary receives a shut down request, the primary:mongod主服务器收到关闭请求,则主服务器:
Attempts to step down to a secondary.试图降级到secondary。If the step down fails and a:如果降级失败,并且a:shutdownordb.shutdownServer()command was run,mongodonly continues the shut down steps if the force field is true, or ashutdown或db.shutdownServer()命令已运行,mongod仅在force字段为真或SIGTERMsignal was sent tomongod,mongodalways continues the shut down steps.SIGTERM信号被发送给mongod,mongod总是继续关闭步骤。
Enters the quiesce period.进入停顿期。Ends any remaining database operations.结束所有剩余的数据库操作。Shuts down.关闭。
For a 对于mongod secondary or mongos shut down request, the quiesce period is entered after a shut down was requested.mongod二级或mongos关闭请求,在请求关闭后进入静默期。
The quiesce period is specified by the:停顿期由以下因素指定:
timeoutSecs field if ashutdownordb.shutdownServer()command was run, ortimeoutSecs字段(如果运行了shutdown或db.shutdownServer()命令),或shutdownTimeoutMillisForSignaledShutdownserver parameter if aSIGTERMsignal was sent tomongod, orshutdownTimeoutMillisForSignaledShutdown如果向mongod发送了SIGTERM信号,则关闭服务器参数,或mongosShutdownTimeoutMillisForSignaledShutdownserver parameter if aSIGTERMsignal was sent tomongos.mongosShutdownTimeoutMillisForSignaledShutdown服务器参数(如果向mongos发送了SIGTERM信号)。
Clients cannot open new connections to a 客户端无法打开与正在关闭的mongod or mongos that is shutting down.mongod或mongos的新连接。
timeoutSecs specifies a time period in seconds. The default is:指定以秒为单位的时间段。默认值为:
15 seconds starting in MongoDB 5.0.从MongoDB 5.0开始15秒。10 seconds in MongoDB versions earlier than 5.0.在5.0之前的MongoDB版本中为10秒。
mongod uses timeoutSecs as follows:使用timeoutSecs如下:
If the current node is the primary node of a replica set,如果当前节点是副本集的primary节点,mongodwaits for a period of up to the number of seconds specified by the timeoutSecs field for an electable node to catch up before stepping down the primary node.mongod将等待timeoutSecs字段指定的秒数,以便可选择的节点赶上,然后再关闭主节点。For details about the catch up time, see replication lag.有关追赶时间的详细信息,请参阅复制延迟。If the current node is in the如果当前节点在从主节点降级后处于SECONDARYstate after stepping down from being the primary, any remaining time specified in timeoutSecs is used for a quiesce period, which allows existing operations to complete.SECONDARY状态,则timeoutSecs中指定的任何剩余时间都将用于停顿期,这允许完成现有操作。New operations are sent to other replica set nodes.新操作被发送到其他副本集节点。
Starting in MongoDB 5.0, 从MongoDB 5.0开始,mongos uses timeoutSecs as a quiesce period, which allows existing operations to complete. mongos使用timeoutSecs作为停顿期,这允许完成现有的操作。New operations are sent to other 新的操作被发送到其他mongos nodes. mongos节点。In MongoDB versions earlier than 5.0, 在早于5.0的MongoDB版本中,mongos shuts down immediately and does not use timeoutSecs.mongos会立即关闭并且不使用timeoutSecs。
Access Control访问控制
To run 要在shutdown on a mongod enforcing Authentication on Self-Managed Deployments, the authenticated user must have the shutdown privilege. mongod上运行shutdown,并在自我管理部署上强制执行身份验证,经过身份验证的用户必须具有关机权限。For example, a user with the built-in role 例如,具有内置角色hostManager has the appropriate permissions.hostManager的用户具有适当的权限。
Examples示例
Shut down a mongod关掉一只mongod
mongoddb.adminCommand({ "shutdown" : 1 })Force Shut Down a mongod强制关闭一只mongod
mongoddb.adminCommand({ "shutdown" : 1, "force" : true })Shut Down a Primary mongod With Longer Timeout关闭一个主mongod,超时时间更长
mongod With Longer Timeoutdb.adminCommand({ "shutdown" : 1, timeoutSecs: 60 })