您可以使用 Ops Manager API来关闭、启动、重启和重新同步 MongoDB 进程。这些操作在弹性测试中非常有用,可以模拟停机时间,也可用于计划内维护重启。您还可以重新同步在长时间停机后数据同步严重滞后的成员。
当您发送请求时,Ops Manager 会立即指示运行在该主机上的自动化代理关闭、启动、重启或重新同步 MongoDB 进程。代理会在下次与 Ops Manager 通信时应用更改。如果该进程是当前主进程,代理会先将其降级,以便其他成员可以接管,然后再停止或重启该进程。
关于此任务
Each operation is asynchronous. A
200 OKresponse means Ops Manager published the change, not that the process has stopped, started, restarted, or resynced. The response includes no job ID. To follow the change to completion, poll the automation status resource. If the agent can't apply the change, the plan shows as failed there and the agent keeps retrying.Every endpoint accepts an optional
dryRun=truequery parameter. Use it to preview a change before you apply it. Ops Manager runs all the same checks and returns the process document as it would look after the change, but sends nothing to the agent and changes nothing in your deployment. For example, after a shutdown the returned document contains"disabled": true. Review it, then send the same request withoutdryRun=trueto apply the change.
开始之前
Your deployment must run Ops Manager 8.0.28 or 9.0.2 or later.
项目必须启用自动化功能,并且目标主机的自动化代理必须正在运行。
如果项目中存在未发布的自动化配置草稿,Ops Manager 将拒绝所有请求,包括试运行。请先发布或删除该草稿,然后再继续操作。
You must have the
Project Automation Adminrole.这些端点不支持外部管理的项目或 Kubernetes Operator (MCK) 部署。
警告
这些端点不提供仲裁保护。关闭副本集中过多的成员会导致副本集缺少主节点。请一次关闭一个成员,并等待每个成员停止运行后再继续。
关闭进程
此过程可优雅地停止正在运行的进程。
找到该进程的主机名和端口。
Find the hostname:port of the process in the Ops Manager UI or with the v2.0 Get All Hosts endpoint.
轮询自动化状态端点。
Poll the automation status resource until the process's lastGoalVersionAchieved equals the plan's goalVersion.
下表描述了运维经理在特定场景下如何处理关机请求。
Scenario | 行为 |
|---|---|
目标是当前的主要目标 | 特工在停止之前先逐步降低操作难度。 |
Target已经关门了 | 流程没有变化。代理程序不执行任何操作,但运维管理器仍然会发布配置并记录事件。 |
目标处于手动模式 | Ops Manager rejects the request with |
启动流程
此程序启动了一个之前已关闭的进程。
找到该进程的主机名和端口。
Find the hostname:port of the process in the Ops Manager UI or with the v2.0 Get All Hosts endpoint.
确认该成员恢复健康状态。
Poll the automation status resource until the plan completes. Then confirm that the member's replicaStateName on the v2.0 Get One Host by ID endpoint returns to SECONDARY or PRIMARY.
下表描述了运维管理器在特定场景下如何处理启动请求。
Scenario | 行为 |
|---|---|
Target 已经在运行 | 流程没有变化。代理程序不执行任何操作,但运维管理器仍然会发布配置并记录事件。 |
进程停机期间,操作日志滚动了。 | The member starts and stays in |
重启进程
此过程可优雅地重启正在运行的进程。如果目标是当前主进程,代理程序会在重启前先将其降级。
找到该进程的主机名和端口。
Find the hostname:port of the process in the Ops Manager UI or with the v2.0 Get All Hosts endpoint.
轮询自动化状态端点。
轮询自动化状态资源,直到计划完成。
下表描述了运维管理器在特定场景下如何处理重启请求。
Scenario | 行为 |
|---|---|
Target 已关闭 | Ops Manager rejects the request with |
目标主机的代理从未向运维经理报告过。 | Ops Manager rejects the request with |
重新同步进程
This procedure triggers an initial sync on a replica set member. Use it to recover a member stuck in RECOVERING because it fell behind the oplog window.
找到该进程的主机名和端口。
Find the hostname:port of the process in the Ops Manager UI or with the v2.0 Get All Hosts endpoint.
确认成员已完成初始同步。
Poll the automation status resource until the plan completes. Then poll v2.0 Get One Host by ID until replicaStateName is SECONDARY. The initial sync can take a long time on large data sets.
下表描述了 Ops Manager 在特定场景下如何处理重新同步请求。
Scenario | 行为 |
|---|---|
The target is a | Ops Manager rejects the request with |
副本集中另一个成员已经有未完成的重新同步任务。 | Ops Manager rejects the request with |
目标是当前的主要目标 | Ops Manager returns |
目标主机的代理从未向运维经理报告过。 | Ops Manager rejects the request with |
审核记录
每次成功的非试运行请求都会在项目活动流中添加一个事件,与常规的自动化配置发布事件并列显示。活动流会将通过API发出的请求归类到公共 API。
操作 | 事件类型 | 它告诉您什么 |
|---|---|---|
关闭 |
| 已对此进程发出关闭请求。如果某个成员意外离线,请检查此事件。 |
开始 |
| 已提出启动已停止进程的请求。 |
重新启动 |
| 已为此进程发出重启请求。请检查此事件,确认是否有成员短暂退出或发生了选举。 |
重新同步 |
| A resync request was made for this process. Check this event if a member went into |
故障排除
下表描述了使用流程生命周期端点时常见的错误和症状。
症状 | 可能的原因 | 解决方案 |
|---|---|---|
| 项目中有一个尚未发布的自动化配置草稿。 | 发布或删除草稿,然后重试。 |
| 有人在运维管理器读取和发布配置之间发布了更改。 | 请重试请求。 |
| 项目在恢复后正在进行协调。 | 等待对账完成后再重试。 |
| 目标主机的代理从未向运维经理报告过。 | 确认代理已安装、正在运行且可以连接到运维管理器,然后重试。 |
| 该项目的流程由外部系统管理。 | 这些端点不适用于外部管理的项目。 |
|
| Confirm the value with v2.0 Get All Hosts, then retry. |
| 该进程已停止。 | 改用启动端点。 |
| 已为此副本集请求重新同步,但部署尚未达到目标状态。例如,在主副本上请求的重新同步操作如果卡住,就会持续阻塞新的请求。 | 轮询自动化状态资源,直到计划完成,然后重试。 |
| The target is a | 改为重新同步包含数据的副本集成员。 |
|
| 修改该值或省略该参数。 |
重新同步后,自动化状态显示需要人工干预。 | 主节点已请求重新同步。 | 降低主设备的优先级以解除重新同步的阻塞。 |
计划在自动化状态下持续失败 | 例如,由于主机无法访问,代理无法应用更改。 | 查看自动化状态响应中的流程错误并修复原因。然后代理将重试。 |
Member stays in | 进程中断期间,操作日志滚动更新,因此该成员无法跟上进度。 | Resync the process, then check |