gpt4 book ai didi

javascript - 从订阅内的其他 VM 在 Azure 虚拟机上定期运行 power-shell 脚本的最佳方法

转载 作者:行者123 更新时间:2023-12-03 05:42:31 25 4
gpt4 key购买 nike

尝试使用 Azure Nodejs SDK 并测试虚拟机运行命令,如 Get StdOut from RunCommand using Azure VM Javascript SDK 中提到的。此调用的性能很差。用户是否有权更改虚拟机运行命令的超时值?

发送脚本的任何其他替代方法。

最佳答案

是的,“运行命令”方式的性能不太好,如果使用 SDK 出现超时错误,也许直接调用 REST API 是一种解决方法。

底层方面,当你使用SDK调用run命令函数时,它会调用这个API:

POST https://management.azure.com/subscriptions/<your subscription ID>/resourceGroups/<resource group name>/providers/Microsoft.Compute/virtualMachines/<VM Name>/runCommand?api-version=2018-04-01

Request Headers:
Content-Type: application/json
Authorization: Bearer <access token>

Request Body:
{"commandId":"RunPowerShellScript","script":["<script content>"]}

一旦调用成功,您将获得 202 响应代码,并且在响应 header 中,将有一个参数“location”,其值为链接,您可以使用它获取命令运行状态: enter image description here

enter image description here

通过这种方式,您可以通过调用该url来监控运行状态,而不用长时间等待响应。

除了在 Azure VM 上运行 ps 脚本的“运行命令”方式之外,还有其他 3 种方法:

  1. Azure VM 自定义脚本扩展
  2. 远程 PowerShell
  3. Azure 自动化 DSC

This blog描述得很好,您可以根据您的要求选择其中之一。

希望有帮助。

关于javascript - 从订阅内的其他 VM 在 Azure 虚拟机上定期运行 power-shell 脚本的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57614913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com