将 Linux 映像添加到 Azure Stack Hub 市场Add Linux images to the Azure Stack Hub Marketplace

可以通过将基于 Linux 的映像添加到 Azure Stack Hub 市场,在 Azure Stack Hub 上部署 Linux 虚拟机 (VM)。You can deploy Linux virtual machines (VMs) on Azure Stack Hub by adding a Linux-based image into Azure Stack Hub Marketplace. 将 Linux 映像添加到 Azure Stack Hub 的最简单方法是使用市场管理。The easiest way to add a Linux image to Azure Stack Hub is through marketplace management. 这些映像已准备好,并已针对与 Azure Stack Hub 的兼容性进行测试。These images have been prepared and tested for compatibility with Azure Stack Hub.

市场管理Marketplace management

若要从 Azure 市场下载 Linux 映像,请参阅将市场项从 Azure 下载到 Azure Stack HubTo download Linux images from Azure Marketplace, see Download marketplace items from Azure to Azure Stack Hub. 选择要在 Azure Stack Hub 上提供给用户的 Linux 映像。Select the Linux images that you want to offer users on your Azure Stack Hub.

这些映像频繁更新,因此请经常回来查看,确保使它们保持最新。There are frequent updates to these images, so check back often to keep up-to-date.

准备自己的映像Prepare your own image

请尽可能通过市场管理下载可用的映像。Wherever possible, download the images available through marketplace management. 这些映像已针对 Azure Stack Hub 进行了准备和测试。These images have been prepared and tested for Azure Stack Hub.

Azure Linux 代理Azure Linux Agent

Azure Linux 代理(通常称为 WALinuxAgentwalinuxagent)是必需的,并非所有代理版本都可以在 Azure Stack Hub 上正常工作。The Azure Linux Agent (typically called WALinuxAgent or walinuxagent) is required, and not all versions of the agent work on Azure Stack Hub. Azure Stack Hub 不支持 2.2.21 和 2.2.34(含)之间的版本。Versions between 2.2.21 and 2.2.34 (inclusive) are not supported on Azure Stack Hub. 若要使用 2.2.35 以上的最新代理版本,请应用 1901 修补程序/1902 修补程序,或者将 Azure Stack Hub 更新到 1903 版(或更高版本)。To use the latest agent versions above 2.2.35, apply the 1901 hotfix/1902 hotfix, or update your Azure Stack Hub to the 1903 release (or above). 请注意,超过 1910 的 Azure Stack Hub 版本支持 cloud-initNote that cloud-init is supported on Azure Stack Hub releases beyond 1910.

Azure Stack Hub 内部版本Azure Stack Hub build Azure Linux 代理内部版本Azure Linux Agent build
1.1901.0.99 或更低版本1.1901.0.99 or earlier 2.2.202.2.20
1.1902.0.691.1902.0.69 2.2.202.2.20
1.1901.3.1051.1901.3.105 2.2.35 或更高版本2.2.35 or newer
1.1902.2.731.1902.2.73 2.2.35 或更高版本2.2.35 or newer
1.1903.0.351.1903.0.35 2.2.35 或更高版本2.2.35 or newer
1903 之后的版本Builds after 1903 2.2.35 或更高版本2.2.35 or newer
不支持Not supported 2.2.21-2.2.342.2.21-2.2.34
1910 之后的版本Builds after 1910 所有 Azure WALA 代理版本All Azure WALA agent versions

可以按照以下说明准备自己的 Linux 映像:You can prepare your own Linux image using the following instructions:

Cloud-initCloud-init

超过 1910 的 Azure Stack Hub 版本支持 cloud-initCloud-init is supported on Azure Stack Hub releases beyond 1910. 若要使用 cloud init 自定义 Linux VM,可以使用以下 PowerShell 说明。To use cloud-init to customize your Linux VM, you can use the following PowerShell instructions.

步骤 1:使用你的 cloud-config 创建 cloud-init.txt 文件Step 1: Create a cloud-init.txt file with your cloud-config

创建名为“cloud-init.txt”的文件并粘贴以下云配置:Create a file named cloud-init.txt and paste the following cloud configuration:

#cloud-config
package_upgrade: true
packages:
  - nginx
  - nodejs
  - npm
write_files:
  - owner: www-data:www-data
    path: /etc/nginx/sites-available/default
    content: |
      server {
        listen 80;
        location / {
          proxy_pass http://localhost:3000;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection keep-alive;
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
        }
      }
  - owner: azureuser:azureuser
    path: /home/azureuser/myapp/index.js
    content: |
      var express = require('express')
      var app = express()
      var os = require('os');
      app.get('/', function (req, res) {
        res.send('Hello World from host ' + os.hostname() + '!')
      })
      app.listen(3000, function () {
        console.log('Hello world app listening on port 3000!')
      })
runcmd:
  - service nginx restart
  - cd "/home/azureuser/myapp"
  - npm init
  - npm install express -y
  - nodejs index.js

步骤 2:在 Linux VM 部署期间引用 cloud-init.txtStep 2: Reference cloud-init.txt during the Linux VM deployment

将该文件上传到 Azure 存储帐户、Azure Stack Hub 存储帐户,或者 Azure Stack Hub Linux VM 可访问的 GitHub 存储库。Upload the file to an Azure storage account, Azure Stack Hub storage account, or GitHub repository reachable by your Azure Stack Hub Linux VM. 目前,仅在 REST、Powershell 和 CLI 上支持使用 cloud-init 进行 VM 部署,在 Azure Stack Hub 上没有关联的门户 UI。Currently, using cloud-init for VM deployment is only supported on REST, Powershell, and CLI, and does not have an associated portal UI on Azure Stack Hub.

可以按照这些说明使用 PowerShell 创建 Linux VM,但请确保引用 cloud-init.txt 作为 -CustomData 标记的一部分:You can follow these instructions to create the Linux VM using powershell, but make sure to reference the cloud-init.txt as a part of the -CustomData flag:

$VirtualMachine =Set-AzureRmVMOperatingSystem -VM $VirtualMachine `
  -Linux `
  -ComputerName "MainComputer" `
  -Credential $cred -CustomData "#include https://cloudinitstrg.blob.core.windows.net/strg/cloud-init.txt"

将映像添加到市场Add your image to Marketplace

按照将映像添加到市场进行操作。Follow Add the image to the Marketplace. 请确保 OSType 参数已设置为 LinuxMake sure that the OSType parameter is set to Linux.

将映像添加到市场后,便会创建市场项,用户就可以部署 Linux VM 了。After you've added the image to the Marketplace, a Marketplace item is created and users can deploy a Linux VM.

后续步骤Next steps