使用 Azure Stack Hub 來連線至 iSCSI 儲存體Connect to iSCSI storage with Azure Stack Hub

您可以使用本文中的範本,將 Azure Stack Hub 虛擬機器 (VM) 連線至內部部署 iSCSI 目標,將 VM 設定為使用裝載於 Azure Stack Hub 外部以及資料中心其他位置的儲存體。You can use the template in this article to connect an Azure Stack Hub virtual machine (VM) to an on-premises iSCSI target set up the VM to use storage hosted outside of our Azure Stack Hub and elsewhere in your datacenter. 本文會探討如何將 Windows 機器作為 iSCSI 目標。This article looks at using a Windows machine as the iSCSI target.

您可以在 Azure 智慧邊緣模式 GitHub 存放庫的 lucidqdreams 分支中找到範本。You can find the template in the lucidqdreams fork of Azure Intelligent Edge Patterns GitHub repository. 此範本位於 storage-iSCSI 資料夾中。The template is in the storage-iSCSI folder. 此範本可用來設定 Azure Stack Hub 這端所需的基礎結構,以便連線至 iSCSI 目標。The template has been designed to set up up the infrastructure necessary on the Azure Stack Hub side to connect to an iSCSI target. 這包括將作為 iSCSI 啟動器的虛擬機器,以及其隨附的 VNet、NSG、PIP 和儲存體。This includes a virtual machine that will act as the iSCSI Initiator along with its accompanying VNet, NSG, PIP, and storage. 範本部署好之後,必須執行兩個 PowerShell 指令碼才能完成設定。After the template has been deployed, two PowerShell scripts need to be, run to complete the configuration. 其中一個指令碼會在內部部署 VM (目標) 上執行,另一個則會在 Azure Stack Hub VM (啟動器) 上執行。One script will be run on the on-premises VM (target) and one will be run on the Azure Stack Hub VM (Initiator). 這些作業完成後,內部部署儲存體就已新增至 Azure Stack Hub VM。Once these are completed, you will have on-premises storage added to your Azure Stack Hub VM.

概觀Overview

下圖顯示的是裝載於 Azure Stack Hub 上的 VM,其具有來自內部部署 Windows 機器 (實體或虛擬) 的 iSCSI 掛接磁碟,可讓 Azure Stack Hub 外部的儲存體透過 iSCSI 通訊協定掛接到 Azure Stack Hub 裝載的 VM 內。The diagram shows a VM hosted on Azure Stack Hub with an iSCSI mounted disk from a Windows machine on premises (physical or virtual) allowing storage external to Azure Stack Hub to mount inside your Azure Stack Hub hosted VM over the iSCSI protocol.

此圖表顯示 Azure Stack Hub 存取外部 iSCSI 掛接的磁片時,所裝載的 VM。

需求Requirements

  • 執行 Windows Server 2016 Datacenter 或 Windows Server 2019 Datacenter 的內部部署機器 (實體或虛擬)。An on-premises machine (physical or virtual) running Windows Server 2016 Datacenter or Windows Server 2019 Datacenter.
  • 必要的 Azure Stack Hub Marketplace 項目:Required Azure Stack Hub Marketplace items:
    • Windows Server 2016 Datacenter 或 Windows Server 2019 Datacenter (建議使用最新組建)。Windows Server 2016 Datacenter or Windows Server 2019 Datacenter (latest build recommended).
    • PowerShell DSC 擴充功能。PowerShell DSC extension.
    • 自訂指令碼擴充功能。Custom Script Extension.
    • 現有的虛擬或實體機器。An existing virtual or physical machine. 在理想情況下,此機器會有兩張網路介面卡。Ideally this machine will have two network adapters. 這也可以是另一個 iSCSI 目標,例如執行個體的 SAN。This could also be another iSCSI target such as a SAN for instance.

考量事項Things to consider

  • 網路安全性群組會套用至範本子網路。A Network Security Group is applied to the template Subnet. 請檢閱這一點,並視需要另外預留額度。Review this and make additional allowances as needed.
  • RDP 拒絕規則會套用至通道 NSG,而且如果您傾向透過公用 IP 位址來存取 VM,則必須將此規則設定為 [允許]。An RDP Deny rule is applied to the Tunnel NSG and will need to be set to allow if you intend to access the VMs via the Public IP address.
  • 此解決方案不會考慮到 DNS 解析。This solution does not take into account DNS resolution.
  • 請變更 Chapusername 和 Chappassword。You should change your Chapusername and Chappassword. Chappassword 的長度必須是 12 到 16 個字元。The Chappassword must be 12 to 16 characters in length.
  • 此範本會讓 VM 使用靜態 IP 位址,因為 iSCSI 連線會使用設定中的本機位址。This template is using a static IP address for the VM as the iSCSI connection uses the local address in the configuration.
  • 此範本會使用 BYOL Windows 授權。This template is using BYOL Windows License.
  • 您也可以將 Linux 型系統連線至 iSCSI 目標。You can also connect Linux-based systems to the iSCSI targets. 您可以在 ubuntu 文件的 iSCSI 啟動器一文中找到相關指示。You can find instructions in the iSCSI Initiator article in the ubuntu documentation.

選項。Options

  • 您可以透過 _artifactsLocation_artifactsLocationSasToken 參數來使用您自己的 Blob 儲存體帳戶和 SAS 權杖,這能讓您搭配 SAS 權杖使用您自己的儲存體 Blob。You can use your own Blob storage account and SAS token using the _artifactsLocation and _artifactsLocationSasToken parameters the ability to use your own storage blob with SAS token.
  • 此範本會提供 VNet 命名和 IP 位址的預設值。This template provides default values for VNet naming and IP addressing.
  • 此設定只有一個來自 iSCSI 用戶端的 iSCSI NIC。This configuration only has one iSCSI nic coming from the iSCSI client. 我們已測試過數個設定,以利用不同的子網路和 NIC,但全都在使用多個閘道時遇到問題,因此我們嘗試建立不同的儲存體子網路來隔離流量,且實際上真的多餘。We had tested a number of configurations to utilize separate subnets and NICs however ran into issues with multiple gateways and trying to create a separate storage subnet to isolate traffic and actually be truly redundant.
  • 請仔細地讓這些值保持在合法的子網路和位址範圍內,否則部署可能會失敗。Be careful to keep these values within legal subnet and address ranges as deployment may fail.
  • PowerShell DSC 套件的主要目的是要檢查是否有擱置的重新開機。The PowerShell DSC packages primary purpose is to check for pending reboots. 如有需要,則可進一步自訂此 DSC。This DSC can be customized further, if needed. 如需詳細資訊,請參閱 omputerManagementDscFor more information see omputerManagementDsc.

資源群組範本 (iSCSI 用戶端)Resource group template (iSCSI client)

下圖顯示透過範本部署的資源,其作用是建立可供您連線至 iSCSI 目標的 iSCSI 用戶端。The diagram shows the resources deployed from the template to create the iSCSI client you can use to connect to the iSCSI target. 此範本會部署 VM 和其他資源,此外,它還會執行 prepare-iSCSIClient.ps1 並將 VM 重新開機。This template will deploy the VM and other resources, In addition, it will run the prepare-iSCSIClient.ps1 and reboot the VM.

此圖顯示從範本部署的資源,以建立 iSCSI 用戶端以連線到 iSCSI 目標。

部署程序The Deployment process

資源群組範本會產生輸出,以供作為下一個步驟的輸入。The resource group template generates output, which is meant to be the input for the next step. 其主要著重在發出 iSCSI 流量的伺服器名稱和 Azure Stack Hub 公用 IP 位址。It is mainly focused on the server name and the Azure Stack Hub public IP address where the iSCSI traffic originates. 針對此範例:For this example:

  1. 部署基礎結構範本。Deploy the infrastructure template.
  2. 將 Azure Stack Hub VM 部署至裝載於資料中心其他位置的 VM。Deploy an Azure Stack Hub VM to a VM hosted elsewhere in your datacenter.
  3. 使用範本所輸出的 IP 位址和伺服器名稱作為 iSCSI 目標 (可以是虛擬機器或實體伺服器) 上指令碼的輸入輸出參數,來執行 Create-iSCSITarget.ps1Run Create-iSCSITarget.ps1 using the IP address and server name outputs from the template as in-out parameters for the script on the iSCSI target, which can be a virtual machine or physical server.
  4. 使用 iSCSI 目標伺服器的外部 IP 位址作為輸入來執行 Connect-toiSCSITarget.ps1 指令碼。Use the external IP address or addresses of the iSCSI Target server as inputs to run the Connect-toiSCSITarget.ps1 script.

下圖顯示上述四個步驟中的前三個步驟,並包含輸入和輸出。

azuredeploy.json 輸入Inputs for azuredeploy.json

參數Parameters 預設值default descriptiondescription
WindowsImageSKUWindowsImageSKU 2019-Datacenter2019-Datacenter 請選取 Windows VM 基礎映像Please select the base Windows VM image
VMSizeVMSize Standard_D2_v2Standard_D2_v2 請輸入 VM 大小Please enter the VM size
VMNameVMName FileServerFileServer VM 名稱VM name
adminUsernameadminUsername storageadminstorageadmin 新 VM 的系統管理員名稱The name of the Administrator of the new VM
adminPasswordadminPassword 新 VM 的系統管理員帳戶密碼。The password for the Administrator account of the new VMs. 預設值為訂用帳戶識別碼Default value is subscription ID
VNetNameVNetName 儲存體Storage VNet 的名稱。The name of VNet. 這會用來標示資源This will be used to label the resources
VNetAddressSpaceVNetAddressSpace 10.10.0.0/2310.10.0.0/23 VNet 的位址空間Address Space for VNet
VNetInternalSubnetNameVNetInternalSubnetName 內部Internal VNet 內部子網路名稱VNet Internal Subnet Name
VNetInternalSubnetRangeVNetInternalSubnetRange 10.10.1.0/2410.10.1.0/24 VNet 內部子網路的位址範圍Address Range for VNet Internal Subnet
InternalVNetIPInternalVNetIP 10.10.1.410.10.1.4 檔案伺服器內部 IP 的靜態位址。Static Address for the internal IP of the File Server.
_artifactsLocation_artifactsLocation
_artifactsLocationSasToken_artifactsLocationSasToken

部署步驟Deployment steps

  1. 使用 azuredeploy.json 部署 iSCSI 用戶端基礎結構Deploy iSCSI client Infrastructure using azuredeploy.json
  2. 在內部部署伺服器 iSCSI 目標上執行 Create-iSCSITarget.ps1Run Create-iSCSITarget.ps1 on the on-premises server iSCSI target. 範本完成之後,您必須在內部部署伺服器 iSCSI 目標上,使用第一個步驟的輸出來執行 Create-iSCSITarget.ps1Once the template completes, you will need to run the Create-iSCSITarget.ps1 on the on-premises server iSCSI target with the outputs from the first step
  3. 在 iSCSI 用戶端上執行 Connect-toiSCSITarget.ps1Run Connect-toiSCSITarget.ps1 on the on iSCSI client. 使用 iSCSI 目標的詳細資料,在 iSCSI 用戶端上執行 Connect-toiSCSITarget.ps1un the Connect-toiSCSITarget.ps1 on the on iSCSI client with the details of the iSCSI target

將 iSCSI 儲存體新增至現有 VMAdding iSCSI storage to existing VMs

您也可以在現有虛擬機器上執行指令碼,以從 iSCSI 用戶端連線至 iSCSI 目標。You can also run the scripts on an existing Virtual Machine to connect from the iSCSI client to a iSCSI target. 如果您要自行建立 iSCSI 目標,則此流程為。This flow is if you are creating the iSCSI target yourself. 下圖顯示 PowerShell 指令碼的執行流程。This diagram shows the execution flow of the PowerShell scripts. 這些指令碼可在 Script 目錄中找到:These scripts can be found in the Script directory:

下圖顯示三個腳本,如下所述。

Prepare-iSCSIClient.ps1Prepare-iSCSIClient.ps1

Prepare-iSCSIClient.ps1 指令碼會在 iSCSI 用戶端上安裝必要條件,這包括:The Prepare-iSCSIClient.ps1 script installs the prerequisites on the iSCSI client, this includes;

  • 安裝多重路徑 I/O 服務installation of Multipath-IO services
  • 將 iSCSI 啟動器服務設定為自動啟動setting the iSCSI initiator service start up to automatic
  • 啟用對 iSCSI 多重路徑 MPIO 的支援enabling support for multipath MPIO to iSCSI
  • 啟用所有 iSCSI 磁碟區的自動宣告Enable automatic claiming of all iSCSI volumes
  • 將磁碟逾時設定為 60 秒Set the disk timeout to 60 seconds

安裝好這些必要條件後,請務必將系統重新開機。It is important to reboot the system after installation of these prerequisites. MPIO 負載平衡原則需要重新開機才能進行設定。The MPIO load-balancing policy requires a reboot so that it can be set.

Create-iSCSITarget.ps1Create-iSCSITarget.ps1

Create-iSCSITarget.ps1腳本會在存放裝置伺服器上執行。The Create-iSCSITarget.ps1 script is to be run on the storage server. 您可以建立數量受到啟動器限制的多個磁碟和目標。You can create multiple disks and targets restricted by initiators. 您可以執行此指令碼多次,以建立多個可連結至不同目標的虛擬磁碟。You can run this script multiple times to create many virtual disks you can attach to different targets. 您可以將多個磁碟連線至一個目標。You can connect multi-disks to one target.

輸入Input 預設值default descriptiondescription
RemoteServerRemoteServer FileServerFileServer 連線至 iSCSI 目標的伺服器名稱The name of the server connecting to the iSCSI Target
RemoteServerIPsRemoteServerIPs 1.1.1.11.1.1.1 將會作為 iSCSI 流量發源地的 IP 位址The IP Address the iSCSI traffic will be coming from
DiskFolderDiskFolder C:\iSCSIVirtualDisksC:\iSCSIVirtualDisks 將作為虛擬磁碟儲存位置的資料夾和磁碟機The folder and drive where the virtual disks will be stored
DiskNameDiskName DiskNameDiskName 磁碟 VHDX 檔案的名稱The name of the disk VHDX file
DiskSizeDiskSize 5GB5GB VHDX 磁碟大小The VHDX disk size
TargetNameTargetName RemoteTarget01RemoteTarget01 用來定義 iSCSI 用戶端目標設定的目標名稱。The target name used to define the target configuration for the iSCSI client.
ChapUsernameChapUsername usernameusername CHAP 驗證的使用者名稱The username name for Chap authentication
ChapPasswordChapPassword userP@ssw0rd!userP@ssw0rd! CHAP 驗證的密碼名稱。The password name for Chap authentication. 其必須是 12 到 16 個字元It must be 12 to 16 characters

Connect-toiSCSITarget.ps1Connect-toiSCSITarget.ps1

Connect-toiSCSITarget.ps1 是最後一個指令碼,其會在 iSCSI 用戶端上執行,並將 iSCSI 目標所提供的磁碟掛接至 iSCSI 用戶端。The Connect-toiSCSITarget.ps1 is the final script, which is run on the iSCSI client and mounts the disk presented by the iSCSI target to the iSCSI client.

輸入Input 預設值default descriptiondescription
TargetiSCSIAddressesTargetiSCSIAddresses "2.2.2.2","2.2.2.3""2.2.2.2","2.2.2.3" iSCSI 目標的 IP 位址The IP addresses of the iSCSI target
LocalIPAddressesLocalIPAddresses "10.10.1.4""10.10.1.4" 這是將會作為 iSCSI 流量發源地的內部 IP 位址This is internal IP Address the iSCSI traffic will be coming from
LoadBalancePolicyLoadBalancePolicy C:\iSCSIVirtualDisksC:\iSCSIVirtualDisks 將會作為 iSCSI 流量發源地的 IP 位址The IP Address the iSCSI traffic will be coming from
ChapUsernameChapUsername usernameusername CHAP 驗證的使用者名稱The username name for Chap authentication
ChapPasswordChapPassword userP@ssw0rd!userP@ssw0rd! CHAP 驗證的密碼名稱。The password name for Chap authentication. 其必須是 12 到 16 個字元It must be 12 to 16 characters

後續步驟Next steps

Azure Stack Hub 網路服務的差異與注意事項Differences and considerations for Azure Stack Hub networking