shutdown

On this page本页内容

Changed in version 5.0.在版本5.0中更改

shutdown

The shutdown command cleans up all database resources and then terminates the process. shutdown命令清除所有数据库资源,然后终止进程。 You must issue the shutdown command against the admin database.必须对admin数据库发出shutdown命令。

The command has this syntax:该命令具有以下语法:

db.adminCommand({
  shutdown: 1,
  force: <boolean>
  timeoutSecs: <int>,
  comment: <any>
})

The command takes these fields:该命令接受以下字段:

Field字段Description描述
shutdown

Specify 1.指定1

force

Optional. 可选。Specify true to force the mongod or mongos to shut down. 指定true以强制mongodmongos关闭。Force shutdown interrupts any ongoing operations on the mongod or mongos and may result in unexpected behavior.强制关闭会中断mongodmongos上正在进行的任何操作,并可能导致意外行为。

timeoutSecs

Optional.可选。

Starting in MongoDB 5.0, mongod and mongos enter a quiesce period to allow any ongoing database operations to complete before shutting down.从MongoDB 5.0开始,mongodmongos进入静止期,以便在关闭之前完成所有正在进行的数据库操作。

If a mongod primary receives a shut down request, the primary:如果mongodprimary收到关闭请求,则primary

  1. Attempts to step down to a secondary.试图退居secondary

    If the step down fails and a:如果步骤失败,并且:

  2. Enters the quiesce period.进入静止期。
  3. Ends any remaining database operations.结束所有剩余的数据库操作。
  4. 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:静止期由以下项指定:

The timeoutSecs field defaults to 15 seconds in MongoDB 5.0.在MongoDB 5.0中,timeoutSecs字段默认为15秒。

Clients cannot open new connections to a mongod or mongos that is shutting down.客户端无法打开与正在关闭的mongodmongos的新连接。

In MongoDB 4.4 and earlier, for a mongodprimary, timeoutSecs is the number of seconds the primary should wait for a secondary to catch up. 在MongoDB 4.4及更早版本中,对于mongodprimarytimeoutSecs是主服务器应等待辅助服务器追赶的秒数。If no secondaries catch up within the specified time, the command fails. 如果在指定时间内没有辅助设备赶上,则命令将失败。Defaults to 10 seconds.默认为10秒。

comment

Optional. 可选。A user-provided comment to attach to this command. 用户提供了附加到此命令的注释。Once set, this comment appears alongside records of this command in the following locations:设置后,此注释将与此命令的记录一起显示在以下位置:

A comment can be any valid BSON type(string, integer, object, array, etc).注释可以是任何有效的BSON类型(字符串、整数、对象、数组等)。

New in version 4.4.在版本4.4中新增

Tip提示
See also: 参阅:

db.shutdownServer()

Behavior行为

For a mongod started with Authentication, you must run shutdown over an authenticated connection. 对于以身份验证启动的mongod,必须在经过身份验证的连接上运行 shutdownSee Access Control for more information.有关详细信息,请参阅访问控制

For a mongod started without Authentication, you must run shutdown from a client connected to the localhost interface. 对于未经身份验证启动的mongod,必须从连接到localhost接口的客户端运行shutdownFor example, run mongosh with the --host "127.0.0.1" option on the same host machine as the mongod.例如,使用--host "127.0.0.1"选项在与mongod相同的主机上运行mongosh

shutdown on Replica Set Members在副本集成员上shutdown

shutdown fails if the replica set member is running certain operations such as index builds. 如果副本集成员正在运行某些操作(如索引生成),则shutdown失败。You can specify force: true to force the member to interrupt those operations and shut down.您可以指定force: true来强制成员中断这些操作并关闭。

Shutting Down the Replica Set Primary, Secondary, or mongos关闭副本集主要、次要或mongos

Starting in MongoDB 5.0, mongod and mongos enter a quiesce period to allow any ongoing database operations to complete before shutting down.从MongoDB 5.0开始,mongodmongos进入静止期,以便在关闭之前完成所有正在进行的数据库操作。

If a mongod primary receives a shut down request, the primary:如果mongodprimary收到关闭请求,则主服务器:

  1. Attempts to step down to a secondary.试图退居secondary

    If the step down fails and a:如果步骤失败,并且:

  2. Enters the quiesce period.进入静止期。
  3. Ends any remaining database operations.结束所有剩余的数据库操作。
  4. Shuts down.关闭。

For a mongod secondary or mongos shut down request, the quiesce period is entered after a shut down was requested.对于mongodsecondarymongos关闭请求,在请求关闭后进入静止期。

The quiesce period is specified by the:静止期由以下项指定:

The timeoutSecs field defaults to 15 seconds in MongoDB 5.0.在MongoDB 5.0中,timeoutSecs字段默认为15秒。

Clients cannot open new connections to a mongod or mongos that is shutting down.客户端无法打开与正在关闭的mongodmongos的新连接。

In MongoDB 4.4 and earlier, if running shutdown against the replica set primary, the operation implicitly uses replSetStepDown to step down the primary before shutting down the mongod. 在MongoDB 4.4及更早版本中,如果对副本集primary运行shutdown,则操作会隐式使用replSetStepDown来在关闭mongod之前关闭主服务器。If no secondary in the replica set can catch up to the primary within 10 seconds, the shutdown operation fails. 如果复制副本集中没有辅助副本能够在10秒内赶上主副本,则关闭操作将失败。You can issue shutdown with force: true to shut down the primary even if the step down fails.您可以使用force:true发出shutdown命令,以关闭主服务器,即使步骤失败。

Warning警告

Force shutdown of the primary can result in the rollback of any writes not yet replicated to a secondary.强制关闭主服务器可能会导致回滚任何尚未复制到辅助服务器的写入。

Access Control访问控制

To run shutdown on a mongod enforcing Authentication, 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

db.adminCommand({ "shutdown" : 1 })

Force Shut Down a mongod强制关闭mongod

db.adminCommand({ "shutdown" : 1, "force" : true })

Shut Down a Primary mongod With Longer Timeout关闭超时较长的主mongod

db.adminCommand({ "shutdown" : 1, timeoutSecs: 60 })
←  setDefaultRWConcernDiagnostic Commands →