代码之家  ›  专栏  ›  技术社区  ›  MindingData

从github为azure虚拟机加载自定义脚本扩展

  •  0
  • MindingData  · 技术社区  · 8 年前

    我正在设置一个azure windows虚拟机,并希望使用自定义脚本扩展来进行一些启动脚本。

    许多关于自定义脚本扩展的文章都谈到了能够从blob和/或github加载脚本。但是,当我通过门户添加CSE时,我看到的是:

    enter image description here

    所以我可以从本地机器上给出脚本文件,就这样?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Charles Xu    8 年前

    在azure门户中,你使用你看到的扩展名,脚本文件将从你的本地机器上传。上载脚本文件后,可以看到它存储在azure存储blob中,url将如下所示: https://iaasv2tempstoreeastus.blob.core.windows.net/vmextensionstemporary-10030000aa9b4851-20180717014522123/Untitled1.ps1 是的。

    如果要使用blob和/或github中的自定义脚本文件,则需要使用powershell cmdlet Set-AzureRmVMExtension ,并将如下所示:

    $SettingsString = '{"fileUris":[],"commandToExecute":""}';
    $ProtectedSettingsString = '{"storageAccountName":"' + $stoname + '","storageAccountKey":"' + $stokey + '"}';
    Set-AzureRmVMExtension -ResourceGroupName "ResourceGroup11" -Location "West US" -VMName "VirtualMachine22" -Name "CustomScriptExtension" -Publisher "Contoso.Compute" -Type "CustomScriptExtension" -TypeHandlerVersion "1.1" -SettingString $SettingsString -ProtectedSettingString $ProtectedSettingsString ;
    

    您可以设置 fileUrls 使用blob和/或github中的脚本文件链接,以便可以将其用作自定义脚本。