將 Linux 映像新增至 Azure Stack Hub MarketplaceAdd Linux images to the Azure Stack Hub Marketplace

您可以將 linux 型映射新增至 Azure Stack Hub Marketplace,以將 Linux 虛擬機器部署 (Vm) 在 Azure Stack Hub 上。You can deploy Linux virtual machines (VMs) on Azure Stack Hub by adding a Linux-based image to the Azure Stack Hub Marketplace. 將 Linux 映像新增到 Azure Stack Hub 的最簡單方式就是透過 Marketplace 管理。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 管理Marketplace management

若要從 Azure Marketplace 下載 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

請盡可能下載可透過 Marketplace 管理取得的映像。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 later). 請注意,在1910以後的 Azure Stack Hub 版本上支援 雲端 initNote that cloud-init is supported on Azure Stack Hub releases later than 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 版本可支援雲端 initCloud-init is supported on Azure Stack Hub releases later than 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 才支援使用雲端初始化進行 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 參考為旗標的一部分 -CustomDataYou 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-AzVMOperatingSystem -VM $VirtualMachine `
  -Linux `
  -ComputerName "MainComputer" `
  -Credential $cred -CustomData "#include https://cloudinitstrg.blob.core.windows.net/strg/cloud-init.txt"

將您的映像新增至 MarketplaceAdd your image to Marketplace

遵循將映像新增至 MarketplaceFollow Add the image to the Marketplace. 請確定已將 OSType 參數設定為 LinuxMake sure that the OSType parameter is set to Linux.

將映像新增至 Marketplace 之後,便會建立 Marketplace 項目,使用者就可以部署 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