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:该命令接受以下字段:
shutdown |
|
force |
|
timeoutSecs |
|
comment |
|
For a 对于以身份验证启动的mongod
started with Authentication, you must run shutdown
over an authenticated connection. mongod
,必须在经过身份验证的连接上运行 shutdown
。See 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接口的客户端运行shutdown
。For 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 Membersshutdown
如果副本集成员正在运行某些操作(如索引生成),则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
来强制成员中断这些操作并关闭。
mongos
mongos
Starting 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
primary收到关闭请求,则主服务器:
Attempts to step down to a secondary.试图退居secondary。
If the step down fails and a:如果步骤失败,并且:
shutdown
or db.shutdownServer()
command was run, mongod
only continues the shut down steps if the force field is true, or ashutdown
或db.shutdownServer()
命令已运行,mongod
仅在force
字段为true
或SIGTERM
signal was sent to mongod
, mongod
always continues the shut down steps.SIGTERM
信号被发送到mongod
,mongod
总是继续关闭步骤。For a 对于mongod
secondary or mongos
shut down request, the quiesce period is entered after a shut down was requested.mongod
secondary或mongos
关闭请求,在请求关闭后进入静止期。
The quiesce period is specified by the:静止期由以下项指定:
shutdown
or db.shutdownServer()
command was run, ortimeoutSecs
字段(如果运行了shutdown
或db.shutdownServer()
命令),或shutdownTimeoutMillisForSignaledShutdown
server parameter if a SIGTERM
signal was sent to mongod
, orshutdownTimeoutMillisForSignaledShutdown
服务器参数(如果向mongod
发送了SIGTERM
信号),或mongosShutdownTimeoutMillisForSignaledShutdown
server parameter if a SIGTERM
signal was sent to mongos
.mongosShutdownTimeoutMillisForSignaledShutdown
服务器参数(如果向mongos
发送了SIGTERM
信号)。The 在MongoDB 5.0中,timeoutSecs
field defaults to 15
seconds in MongoDB 5.0.timeoutSecs
字段默认为15
秒。
Clients cannot open new connections to a 客户端无法打开与正在关闭的mongod
or mongos
that is shutting down.mongod
或mongos
的新连接。
In MongoDB 4.4 and earlier, if running 在MongoDB 4.4及更早版本中,如果对副本集primary运行shutdown
against the replica set primary, the operation implicitly uses replSetStepDown
to step down the primary before shutting down the mongod
. 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
命令,以关闭主服务器,即使步骤失败。
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
的用户具有适当的权限。
mongod
mongod
db.adminCommand({ "shutdown" : 1 })
mongod
mongod
db.adminCommand({ "shutdown" : 1, "force" : true })
mongod
With Longer Timeoutmongod
db.adminCommand({ "shutdown" : 1, timeoutSecs: 60 })