30.3.1 脚本中断

也可以从命令行或脚本管理停电。本节中列出的示例均使用 curl. 您可以从命令行运行命令或添加到文本文件并将其保存为 *.sh*.bat 取决于您的平台。

笔记

在 Unix 系统上,使用chmod +x blackout.sh命令使文件可执行。

描述了以下停电类型:

  • 服务器中断:描述如何在 MySQL 实例上应用或删除中断。

  • 组中断:描述如何在 MySQL Enterprise Monitor 组上应用或删除中断。

  • Agent Blackout:描述如何在 MySQL Enterprise Monitor Agent 上应用或删除中断,并递归地在代理监视的所有 MySQL 实例上应用或删除中断。

  • Blackout Status:描述如何检查代理、组或 MySQL 实例上的中断状态。

笔记

重新启动 MySQL Enterprise Service Manager 或 MySQL Enterprise Monitor Agent 不会删除应用的中断。

服务器停电

blackout命令使您能够中断单个 MySQL 实例。

要中断单个 MySQL 实例,您必须提供以下信息:

  • --user:运行命令的服务管理器用户的用户名和密码。确保此用户具有执行中断的正确权限。

  • Service Manager 的 rest API 的 URL。例如: "https://servicemanager:18443/rest"

  • command=blackout: 停电命令。

  • 以下之一:

    • server_name=ServerName:要中断的服务器的名称。

    • server_uuid=AlphanumericString:要中断的 MySQL 实例的 UUID。

要使用 中断服务器server_name,请使用以下命令:

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest" 
  --data-urlencode "command=blackout" --data-urlencode "server_name=servername:3306" 
  --data-urlencode "blackout_state=true"

要使用 中断服务器server_uuid,请使用以下命令:

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest" 
  --data-urlencode "command=blackout" 
  --data-urlencode "server_uuid=62e74f29-526a-11ba-77fb-0242xy112504" 
  --data-urlencode "blackout_state=true"

要删除停电,请运行相同的命令,使用 "blackout_state=false". 例如:

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest" 
  --data-urlencode "command=blackout" 
  --data-urlencode "server_uuid=62e74f29-526a-11ba-77fb-0242xy112504" 
  --data-urlencode "blackout_state=false"

It is also possible to blackout all the MySQL instances monitored by a specific Agent. for more information, see Agent Blackout.

Group Blackout

The blackout command enables you to blackout groups of MySQL instances. For more information on MySQL Enterprise Service Manager Groups, see Chapter 17, Managing Groups of Instances.

To blackout a group of MySQL instances you must provide the following:

  • --user: the username and password of the Service Manager user running the command. Ensure this user has the correct rights to perform blackouts.

  • The URL of the Service Manager's rest API. For example: "https://servicemanager:18443/rest"

  • command=blackout: the blackout command.

  • group_name=GroupName: the name of the group to blackout.

The following command blackouts all MySQL instances in the group named Group 1.

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest"
  --data-urlencode "command=blackout" --data-urlencode "group_name=Group 1" 
  --data-urlencode "blackout_state=true"

To remove the blackout, run the same command, with "blackout_state=false".

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest"
  --data-urlencode "command=blackout" --data-urlencode "group_name=Group 1" 
  --data-urlencode "blackout_state=false"

Agent Blackout

The command blackout enables you to blackout an Agent, or an Agent and all the MySQL instances it is currently monitoring.

To blackout an agent you must provide the following:

  • --user: the username and password of the Service Manager user running the command. Ensure this user has the correct rights to perform blackouts.

  • The URL of the Service Manager's rest API. For example: "https://servicemanager:18443/rest"

  • command=blackout: the blackout command.

  • id=alphanumericString: the id of the Agent to blackout.

To blackout an agent, run the following command:

   curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest"
  --data-urlencode "command=blackout" 
  --data-urlencode "agent_id=1e365f83-b703-4588-9472-877c90a2c49f" 
  --data-urlencode "blackout_state=true"

To blackout an Agent and all the MySQL instances it monitors, run the following command:

   curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest"
  --data-urlencode "command=blackout" 
  --data-urlencode "agent_id=1e365f83-b703-4588-9472-877c90a2c49f" 
  --data-urlencode "blackout_state=true" --data-urlencode "recursive=true"

Blackout Status

The command blackout_status enables you to check if an agent or MySQL instance is currently blacked out.

To check the blackout status you must provide the following:

  • --user: the username and password of the Service Manager user running the command. Ensure this user has the correct rights to perform blackouts.

  • The URL of the Service Manager's rest API. For example: "https://servicemanager:18443/rest"

  • command=blackout_status: the blackout status command.

  • id=alphanumericString:被检查的Agent或MySQL实例的id。

  • asset_type:以下之一:

    • agent.Agent:检查代理的停电状态。

    • mysql.MysqlServer:查看MySQL实例的中断状态。

以下命令检查代理的中断状态:

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest" 
  --data-urlencode "command=blackout_status" 
  --data-urlencode "id=1e365f83-b703-4588-9472-877c90a2c49f" 
  --data-urlencode "asset_type=agent.Agent"

以下命令检查 MySQL 实例的中断状态:

 curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest" 
  --data-urlencode "command=blackout_status" 
  --data-urlencode "id=750cead2-441d-11ea-b3e7-dfdaa5ad712e" 
  --data-urlencode "asset_type=mysql.MysqlServer"