Linux VM 扩展配置示例


Note

必须修改从 GitHub 存储库“azure-quickstart-templates”下载的模板,以适应 Azure 中国云环境。 例如,替换某些终结点(将“blob.core.windows.net”替换为“blob.core.chinacloudapi.cn”,将“cloudapp.azure.com”替换为“chinacloudapp.cn”);更改某些不受支持的 VM 映像;更改某些不受支持的 VM 大小。

本文提供为 Linux VM 配置 Azure VM 扩展的示例配置。

若要了解有关这些扩展的详细信息,请单击此处:Azure VM 扩展概述

若要了解有关创作扩展模板的详细信息,请单击此处:创作扩展模板

本文列出了一些 Linux 扩展的预期配置值。

VM 扩展的示例模板代码段。

用于部署扩展的模板代码段如下所示:

  {
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "name": "MyExtension",
  "apiVersion": "2015-05-01-preview",
  "location": "[parameters('location')]",
  "dependsOn": ["[concat('Microsoft.Compute/virtualMachines/',parameters('vmName'))]"],
  "properties":
  {
  "publisher": "Publisher Namespace",
  "type": "extension Name",
  "typeHandlerVersion": "extension version",
  "autoUpgradeMinorVersion":true,
  "settings": {
  // Extension specific configuration goes in here.
  }
  }
  }

适用于 VM 规模集的 VM 扩展的示例模板代码段。

      {
       "type":"Microsoft.Compute/virtualMachineScaleSets",
      ....
             "extensionProfile":{
             "extensions":[
               {
                 "name":"extension Name",
                 "properties":{
                   "publisher":"Publisher Namespace",
                   "type":"extension Name",
                   "typeHandlerVersion":"extension version",
                   "autoUpgradeMinorVersion":true,
                   "settings":{
                   // Extension specific configuration goes in here.
                   }
                 }
                }
              }
            }

在部署扩展之前,请检查最新的扩展版本,并将“typeHandlerVersion”替换为当前最新版本。

本文剩余部分提供 Linux VM 扩展的示例配置。

      {
        "publisher": "CloudLinkEMC.SecureVM",
        "type": "CloudLinkSecureVMLinuxAgent",
        "typeHandlerVersion": "4.0",
        "settings": {
          "CloudLinkCenter" : "specify valid IP/FQDN to CloudLinkCenter"
        }
      }

适用于 Linux 的 CustomScript 扩展。

{
    "publisher": " Microsoft.Azure.Extensions",
    "type": "CustomScript",
    "typeHandlerVersion": "2.0",
    "autoUpgradeMinorVersion": true,
    "settings": {
        "fileUris": [
            "http: //Yourstorageaccount.blob.core.chinacloudapi.cn/customscriptfiles/start.ps1"
        ],
        "commandToExecute": "powershell.exe-ExecutionPolicyUnrestricted-Filestart.ps1"
    }
}

Datadog 代理

    {
      "publisher": "Datadog.Agent",
      "type": "DatadogLinuxAgent",
      "typeHandlerVersion": "0.4",
      "settings": {
        "api_key" : "API Key from https://app.datadoghq.com/account/settings#api"
      }
    }

Chef 代理

    {
      "publisher": "Chef.Bootstrap.WindowsAzure",
      "type": "CentosChefClient|LinuxChefClient",
      "typeHandlerVersion": "1210.12",
      "settings": {
        "validation_key" : " Validation key",
        "client_rb" : "client_rb file",
        "runlist" : "Optional runlist"
      }
    }

VM 访问扩展(密码重置)

有关更新的架构,请参阅 VMAccessForLinux 文档

    {
      "publisher": "Microsoft.OSTCExtensions",
      "type": "VMAccessForLinux",
      "typeHandlerVersion": "1.2",
      "protectedSettings": {
        "username": "(required, string) the name of the user",
        "password": "(optional, string) the password of the user",
        "reset_ssh": "(optional, boolean) whether or not reset the ssh",
        "ssh_key": "(optional, string) the public key of the user, base64 encoded pem",
        "remove_user": "(optional, string) the user name to remove"
      }
    }

OS 修补

有关更新的架构,请参阅 OSPatching 文档

    {
    "publisher": "Microsoft.OSTCExtensions",
    "type": "OSPatchingForLinux",
    "typeHandlerVersion": "2.9",
    "Settings": {
      "disabled": false,
      "stop": false,
      "rebootAfterPatch": "RebootIfNeed|Required|NotRequired|Auto",
      "category": "Important|ImportantAndRecommended",
      "installDuration": "<hr:min>",
      "oneoff": false,
      "intervalOfWeeks": "<number>",
      "dayOfWeek": "Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Everyday",
      "startTime": "<hr:min>",
      "vmStatusTest": {
          "local": false,
          "idleTestScript": "<path_to_idletestscript>",
          "healthyTestScript": "<path_to_healthytestscript>"
      }
    }
    }

Docker 扩展

有关更新的架构,请参阅 Docker 扩展文档

    {
      "publisher": "Microsoft.Azure.Extensions ",
      "type": "DockerExtension ",
      "typeHandlerVersion": "1.0",
      "Settings": {
        "docker":{
            "port": "2376",
            "options": ["-D", "--dns=8.8.8.8"]
        },
        "compose": {
            "cache" : {
                "image" : "memcached",
                "ports" : ["11211:11211"]
            },
            "blog": {
                "image": "ghost",
                "ports": ["80:2368"]
            }
        }
        }
    }

Linux 诊断扩展

    {
    "storageAccountName": "storage account to receive data",
    "storageAccountKey": "key of the account",
    "perfCfg": [
    {
        "query": "SELECT PercentAvailableMemory, AvailableMemory, UsedMemory ,PercentUsedSwap FROM SCX_MemoryStatisticalInformation",
        "table": "LinuxMemory"
    }
    ],
    "fileCfg": [
    {
        "file": "/var/log/mysql.err",
        "table": "mysqlerr"
    }
    ]
    }

在上述示例中,请将版本号替换为最新版本号。

以下是使用扩展创建 Linux VM 的完整 VM 模板:

Linux VM 上的自定义脚本扩展