subscription="00000000-0000-0000-0000-000000000000" # Replace with your subscription ID
resourceGroup="hcicluster-rg" # Replace with your resource group name
az account set --subscription "${subscription}"
clusters=($(az graph query -q "resources | where type == 'microsoft.azurestackhci/clusters'| where resourceGroup =~ '${resourceGroup}' | project name" | jq -r '.data[].name'))
若要在资源组下的所有群集上安装 Windows Admin Center 扩展,请运行以下命令:
extensionName="AdminCenter"
extensionType="AdminCenter"
extensionPublisher="Microsoft.AdminCenter"
settingsConfig="{'port':'6516'}"
connectivityProps="{enabled:true}"
for cluster in ${clusters}; do
echo "Enabling Connectivity for cluster $currentCluster"
az stack-hci arc-setting update \
--resource-group ${resourceGroup} \
--cluster-name ${cluster} \
--name "default" \
--connectivity-properties ${connectivityProps}
echo "Installing extension: ${extensionName} on cluster: ${cluster}"
az stack-hci extension create \
--arc-setting-name "default" \
--cluster-name "${cluster}" \
--resource-group "${resourceGroup}" \
--name "${extensionName}" \
--auto-upgrade "true" \
--publisher "${extensionPublisher}" \
--type "${extensionType}" \
--settings "${settingsConfig}"
done
若要在资源组下的所有群集上安装 Azure Monitor 代理扩展,请运行以下命令:
extensionName="AzureMonitorWindowsAgent"
extensionType="AzureMonitorWindowsAgent"
extensionPublisher="Microsoft.Azure.Monitor"
for cluster in ${clusters}; do
echo "Installing extension: ${extensionName} on cluster: ${cluster}"
az stack-hci extension create \
--arc-setting-name "default" \
--cluster-name "${cluster}" \
--resource-group "${resourceGroup}" \
--name "${extensionName}" \
--auto-upgrade "true" \
--publisher "${extensionPublisher}" \
--type "${extensionType}"
done
若要在资源组下的所有群集上安装 Azure Site Recovery 扩展,请运行以下命令:
asrSubscription="00000000-0000-0000-0000-000000000000" # Replace with your ASR subscription ID
asrResourceGroup="asr-rg" # Replace with your ASR resource group
asrVaultName="asr-vault" # Replace with your ASR vault name
asrLocation="China East 2" # Replace with your ASR Location
asrSiteId="00000000-0000-0000-0000-000000000000" # Replace with your ASR Site ID
asrSiteName="asr-site" # Replace with your Site Name
asrSitePolicyId="/subscriptions/${asrSubscription}/resourceGroups/${asrResourceGroup}/providers/Microsoft.RecoveryServices/vaults/${asrVaultName}/replicationPolicies/s-cluster-policy" # Replace with your Site Policy name
extensionName="ASRExtension"
extensionType="Windows"
extensionPublisher="Microsoft.SiteRecovery.Dra"
jsonFile="./tmp-asr.json" #Temp JSON file
echo "{\"SubscriptionId\": \"${asrSubscription}\", \"Environment\": \"AzureChinaCloud\",\"ResourceGroup\": \"${asrResourceGroup}\",\"Location\": \"${asrLocation}\",\"SiteId\": \"${asrSiteId}\", \"SiteName\": \"${asrSiteName}\", \"PolicyId\": \"${asrSitePolicyId}\", \"PrivateEndpointStateForSiteRecovery\": \"None\" }" > ${jsonFile}
for cluster in ${clusters}; do
echo "Installing extension: ${extensionName} on cluster: ${cluster}"
az stack-hci extension create \
--arc-setting-name "default" \
--cluster-name "${cluster}" \
--resource-group "${resourceGroup}" \
--name "${extensionName}" \
--auto-upgrade "true" \
--publisher "${extensionPublisher}" \
--type "${extensionType}" \
--settings "${jsonFile}"
done
设置订阅、资源组和群集的参数:
$subscription = "00000000-0000-0000-0000-000000000000" # Replace with your subscription ID
$resourceGroup = "hcicluster-rg" # Replace with your resource group name
Set-AzContext -Subscription "${subscription}"
$clusters = Get-AzResource -ResourceType "Microsoft.AzureStackHCI/clusters" -ResourceGroupName ${resourceGroup} | Select-Object -Property Name
若要在资源组下的所有群集上安装 Azure Site Recovery 扩展,请创建 JSON 参数文件,然后运行以下命令:
$settings = @{
SubscriptionId = "<Replace with your Subscription Id>"
Environment = "<Replace with the cloud environment type. For example: AzureChinaCloud>"
ResourceGroup = "<Replace with your Site Recovery Vault resource group>"
ResourceName = "<Replace with your Site Recovery Vault Name>"
Location = "<Replace with your Site Recovery Azure Region>"
SiteId = "<Replace with the ID of your recovery site>"
SiteName = "<Replace with your recovery site name>"
PolicyId = "<Replace with resource ID of your recovery site policy>"
PrivateEndpointStateForSiteRecovery = "None"
}
$extensionName = "ASRExtension"
$extensionType = "Windows"
$extensionPublisher = "Microsoft.SiteRecovery.Dra"
foreach ($cluster in $clusters) {
$clusterName = ${cluster}.Name
Write-Output ("Installing Extension '${extensionType}/${extensionPublisher}' on cluster ${clusterName}")
New-AzStackHciExtension `
-ClusterName "${clusterName}" `
-ResourceGroupName "${resourceGroup}" `
-ArcSettingName "default" `
-Name "${extensionName}" `
-ExtensionParameterPublisher "${extensionPublisher}" `
-ExtensionParameterType "${extensionType}" `
-ExtensionParameterSetting ${settings} `
-NoWait
}
subscription="00000000-0000-0000-0000-000000000000" # Replace with your subscription ID
resourceGroup="hcicluster-rg" # Replace with your resource group name
clusterName="HCICluster" # Replace with your cluster name
extensionName="AzureMonitorWindowsAgent" # Replace with the extension name
az account set --subscription "${subscription}"
若要列出群集上的所有扩展,请运行以下命令:
az stack-hci extension list \
--arc-setting-name "default" \
--cluster-name "${clusterName}" \
--resource-group "${resourceGroup}" \
-o table
$subscription = "00000000-0000-0000-0000-000000000000" # Replace with your subscription ID
$resourceGroup = "hcicluster-rg" # Replace with your resource group name
Set-AzContext -Subscription "${subscription}"
$clusters = Get-AzResource -ResourceType "Microsoft.AzureStackHCI/clusters" -ResourceGroupName ${resourceGroup} | Select-Object -Property Name
extensionName="AzureMonitorWindowsAgent" # Replace with the extension name
resourceGroup="hcicluster-rg" # Replace with your resource group name
clusterName="HCICluster" # Replace with your cluster name
az stack-hci extension delete \
--arc-setting-name "default" \
--name "${extensionName}" \
--cluster-name "${clusterName}" \
--resource-group "${resourceGroup}"
若要删除特定扩展(如 AzureMonitorWindowsAgent),请运行以下命令:
$clusterName = "HCICluster" # Replace with your cluster name
$resourceGroup = "hcicluster-rg" # Replace with your resource group name
$extensionName = "AzureMonitorWindowsAgent"
Remove-AzStackHciExtension `
-ClusterName "${clusterName}" `
-ResourceGroupName "${resourceGroup}" `
-ArcSettingName "default" `
-Name "${extensionName}"