[英]Install applications or software on Azure VM with ARM Template
我們正在嘗試使用ARM模板在 Azure VM 上安裝Kaspersky Network Agent 。
此外,我們需要使用SAS令牌從 VM 存儲中獲取.exe或.msi文件。 我正在尋找要操作的模板示例,但無法找到完成任務的模板。 你知道,如果有可能這樣做嗎?
如果是這樣,你能分享一個執行類似任務的模板嗎? 另外,請說明如何修改此案例的模板。
提前致謝
• 是的,您可以使用Azure VM 中ARM 模板中的自定義腳本擴展成功安裝應用程序,如下所示。 請檢查我為此目的部署的 ARM 模板文件。 此外,我在部署期間使用 SAS 令牌下載 Azure VM 中的應用程序包,還使用了 powershell 腳本來調用相關應用程序的靜默安裝。
ARM 模板:-
我正在使用默認快速入門模板通過 ARM 模板部署 Azure VM,如下鏈接所示: - https://docs.microsoft.com/en-us/azure/virtual-machines/windows/quick-create-template? toc=/azure/azure-resource-manager/templates/toc.json
在此模板中,我在上述 ARM 模板的“資源”部分添加了以下自定義腳本擴展安裝內容。 請正確檢查 ARM 模板代碼的格式,即逗號、大括號、方括號等。另外,請確保打開 HTTPS 端口 443 入站,如下所示:-
"securityRules": [
{
"name": "default-allow-3389",
"properties": {
"priority": 1000,
"access": "Allow",
"direction": "Inbound",
"destinationPortRange": "3389",
"protocol": "Tcp",
"sourcePortRange": "*",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*"
}
},
{
"name": "AllowHTTPSInBound",
"properties": {
"priority": 1010,
"access": "Allow",
"direction": "Inbound",
"destinationPortRange": "443",
"protocol": "Tcp",
"sourcePortRange": "*",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*"
}
}
]
自定義腳本 VM 擴展:-
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2021-04-01",
"name": "[concat(parameters('vmName'),'/', 'InstallWebServer')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/',parameters('vmName'))]"
],
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.7",
"autoUpgradeMinorVersion": true,
"protectedSettings": {
"storageAccountName": "techtrix",
"storageAccountKey": "EN6iUzOfVe8Ht0xvyxnqK/iXEGTEunznASsumuz0FR4SCvc2mFFHUJfbMy1/GSK7gXk0MB38MMo7+AStoKxC/w==",
"fileUris": [
"https://techtrix.blob.core.windows.net/executable/Testdemo2.ps1"
],
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File Testdemo2.ps1"
}
}
}
此外,請注意,您需要已預配存儲帳戶容器以在其中存儲 powershell 腳本和應用程序包,以便您可以使用該存儲帳戶的密鑰、其名稱和 powershell 腳本的 blob URI 來代替請求的相同以上。 此外,請通過“commandToExecute”部分中的擴展名更改要執行的 powershell 腳本的名稱。
完成上述操作后,請確保本地安裝應用程序包的靜默安裝命令成功執行,以便在powershell腳本中進行相應修改。 我在這里使用安裝的“7-zip”應用程序進行演示。 請在下面找到我的 powershell 腳本。 確保事先上傳了此腳本和應用程序包,並且容器的訪問級別設置為“匿名和公共訪問”:-
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name Az.Storage -AllowClobber -Force
Import-Module -Name Az.Storage -Force
$StorageAccountName = "techtrix"
$ContainerName = "executable"
$Blob1Name = "7z2107-x64.exe"
$TargetFolderPath = "C:\"
$context = New-AzStorageContext -StorageAccountName $StorageAccountName -SASToken "sp=r&st=2022-02-10T08:40:34Z&se=2022-02-10T16:40:34Z&spr=https&sv=2020-08-04&sr=b&sig=DRDulljKTJiRbVPAXAJkTHi8QlnlbjPpVR3aueEf9xU%3D"
Get-AzStorageBlobContent -Blob $Blob1Name -Container $ContainerName -Context $context -Destination $TargetFolderPath
$arg="/S"
Start-Process -FilePath "C:\7z2107-x64.exe" -ArgumentList $arg ’
然后使用“adminUsername”、“adminPassword”和“location”中的所需值編輯參數文件,並將其保存在存儲模板文件的相同位置。 現在,在本地使用提升的權限從 powershell 控制台執行以下命令,即通過在 powershell 本身中瀏覽到該路徑來存儲這些 ARM 模板文件的路徑。
az login
az deployment group create -n <name of the deployment> -g <name of the resource group> --template-file "azuredeployVM.json" --parameters "azuredeployVM.parameters.json" ’
成功部署后,您將能夠看到在虛擬機創建過程中安裝的應用程序,如下所示:-
這樣,您可以通過帶有自定義腳本擴展名的 ARM 模板安裝“.exe”或“.msi”。
安裝 .exe 文件需要提升權限才能以管理員身份運行。
自定義腳本在嘗試運行 .exe 文件時不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.