On this page本页内容
Changed in version 5.0.在版本5.0中更改。
db.shutdownServer()
Shuts down the current 清洁安全地关闭当前mongod
or mongos
process cleanly and safely. mongod
或mongos
进程。You must issue the 必须对db.shutdownServer()
operation against the admin database.admin
数据库执行db.shutdownServer()
操作。
db.shutdownServer()
has this syntax:具有以下语法:
db.shutdownServer({
force: <boolean>,
timeoutSecs: <int>
})
The method takes these fields:该方法采用以下字段:
force |
|
timeoutSecs |
|
This operation provides a wrapper around the 此操作提供shutdown
command.shutdown
命令的包装。
For a 对于以mongod
started with Authentication, you must run db.shutdownServer()
over an authenticated connection. Authentication
启动的mongod
,必须在经过身份验证的连接上运行db.shutdownServer()
。See Access Control for more information.有关详细信息,请参阅访问控制。
For a 对于在没有身份验证的情况下启动的mongod
started without Authentication, you must run db.shutdownServer()
from a client connected to the localhost interface. mongod
,必须从连接到localhost接口的客户端运行db.shutdownServer()
。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
。
db.shutdownServer()
如果db.shutdownServer()
fails if the mongod
replica set member is running certain operations such as index builds. mongod
副本集成员正在运行某些操作(如索引构建),db.shutdownServer()
将失败。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收到关闭请求,则primary:
Attempts to step down to a 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
服务器参数(如果SIGTERM
信号发送到mongod
),或mongosShutdownTimeoutMillisForSignaledShutdown
server parameter if a SIGTERM
signal was sent to mongos
.mongosShutdownTimeoutMillisForSignaledShutdown
服务器参数,如果SIGTERM
信号被发送到mongos
。The timeoutSecs field defaults to 在MongoDB 5.0中,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及更早版本中,如果对副本集主服务器运行db.shutdownServer()
against the replica set primary, the operation implicitly uses replSetStepDown
to step down the primary before shutting down the mongod
. db.shutdownServer()
,则操作会在关闭mongod
之前隐式使用replSetStepDown逐步关闭主服务器。If no secondary in the replica set can catch up to the primary within 如果复制集中没有辅助设备可以在10
seconds, the shutdown operation fails. 10
秒内赶上主设备,则关闭操作将失败。You can issue 您可以使用db.shutdownServer()
with force: true to shut down the primary even ifthe step down fails.force:true
命令db.shutdownServer()
来关闭主服务器,即使步降失败。
To run 要在强制身份验证的db.shutdownServer()
on a mongod
enforcing Authentication, the authenticated user must have the db.shutdownServer()
privilege. mongod
上运行db.shutdownServer()
,经过身份验证的用户必须具有db.shutdownServer()
权限。For example, a user with the built-in role 例如,具有内置角色hostManager
has the appropriate permissions.hostManager
的用户具有相应的权限。
mongod
db.getSiblingDB("admin").shutdownServer()
mongod
db.getSiblingDB("admin").shutdownServer({ "force" : true })
mongod
With Longer Timeoutmongod
db.getSiblingDB("admin").shutdownServer({ "timeoutSecs": 60 })