這是劇本我使用Azure中創造了經典(ASM)VM如何在Azure ASM中指定DNS名稱(域名)前綴?
param(
[switch] $Help = $false,
$azurePassword,
$azureUsername ,
$azureSubscriptionName ,
$VMImageName,
$azureStorageAccountName,
$AzureResourceGroupName,
$VMSize,
$VMName,
$VMAdministratorUsername,
$VMAdministratorPassword,
$VNetName,
$VNetSubnetName
)
#Preparation steps
Clear-Host
$startTime = Get-Date
Write-Host -ForegroundColor Cyan "This script will create a classic VM '$VMName'"
Write-Host "Script started ($startTime)"
DetectPowershellVersion 4
$azurePassword = $azurePassword | ConvertTo-SecureString -asPlainText -Force
$azureCredentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $azureUsername,$azurePassword
Disable-AzureDataCollection -WarningAction SilentlyContinue
#1
Write-Host -ForegroundColor Cyan "Step 1: Logging in to Azure..."
Add-AzureAccount -credential $azureCredentials | Out-Null
Write-Host "Logged in."
#2
Write-Host -ForegroundColor Cyan "Step 2: Selecting subscription..."
Select-AzureSubscription -SubscriptionName $azureSubscriptionName -Current
New-AzureStorageAccount -StorageAccountName $azureStorageAccountName -Label $azureStorageAccountName -Location "North Europe" -ErrorAction SilentlyContinue
Set-AzureSubscription -SubscriptionName $azureSubscriptionName -CurrentStorageAccountName $azureStorageAccountName
Write-Host "Selected Subscription = $((Get-AzureSubscription -Current).SubscriptionName)"
Write-Host "Selected Storage Account Name = $azureStorageAccountName "
#3
Write-Host -ForegroundColor Cyan "Step 3: Locating VMImage subscription..."
$VMImage = (Get-AzureVMImage | Where { $_.Label -like "$($VMImageName)*" } | Sort-Object PublishedDate -Descending)[0]
write-host "Selected image = $($VMImage.Label)"
write-host "Selected image OS = $($VMImage.OS)"
#4
Write-Host -ForegroundColor Cyan "Step 4: Locating requested size..."
write-host "Requested size = $VMSize"
$VMConfig = New-AzureVMConfig -Name $VMName -InstanceSize $VMSize -ImageName $VMImage.ImageName
#5
Write-Host -ForegroundColor Cyan "Step 5: Creating credentials for VM..."
if ($VMImage.OS -eq "Windows")
{
$VMProvision = Add-AzureProvisioningConfig -Windows -AdminUsername $VMAdministratorUsername -Password $VMAdministratorPassword -VM $VMConfig
}
else #Linux
{
$VMProvision = Add-AzureProvisioningConfig -Linux -LinuxUser $VMAdministratorUsername -Password $VMAdministratorPassword -VM $VMConfig
}
Write-Host "Credentials created. Username = $VMAdministratorUsername Password = *******"
#6 Delete VM if exists
Write-Host -ForegroundColor Cyan "Step 6: Deleting VM '$VMName' if exists..."
$vmstatus = Get-AzureVM -ServiceName $azureResourceGroupName -Name $VMName
if ($vmstatus)
{
Write-Host "VM $VMName detected."
Write-Host "Stopping $VMName"
Stop-AzureVM -ServiceName $azureResourceGroupName -Name $VMName -Force
Write-Host "Deleting VM $VMName"
Remove-AzureVM -ServiceName $azureResourceGroupName -Name $VMName -DeleteVHD
}
else
{
Write-Host "VM $VMName NOT detected."
}
#7 PROVISION VM!
Write-Host -ForegroundColor Cyan "Step 7: Creating Virtual Machine in Azure..."
Write-Host "This will take a while"
Write-Host "Starting creation of VM $VMName"
Write-Host "Using VNET $VNETName and Subnet $VNetSubnetName"
Set-AzureSubnet -SubnetNames $VNetSubnetName -VM $VMConfig | Out-Null
New-AzureService -ServiceName $AzureResourceGroupName -Location "North Europe" -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$VMResult = $VMProvision | New-AzureVM -ServiceName $AzureResourceGroupName -WaitForBoot -VNetName $VNetName
# END
$endTime = Get-Date
Write-Host "Creation of VM $VMName finished ($endTime)"
$elapsedTime = new-timespan $startTime $endTime
Write-Host -ForegroundColor Cyan "SUCCESS: VM Creation time = $elapsedTime"
exit 0
我把它帶參數(其中包括)
- AzureResourceGroupName 「testBananas」
- VMNAME「testOranges 「
正如你可以看到虛擬機名稱爲testOranges,它是在服務(資源集團)testBananas創建。
但DNS名稱默認情況下創建testBananas .cloudapp.net 我想這是testOranges .cloudapp.net或我指定任何東西。我認爲DNS名稱默認被填充。
所以我的問題是:
如何在Azure中ASM指定DNS名稱的前綴?
我發現很多信息使用自定義DNS或加入到域中......但我不想這樣做,我只是想指定我的自定義DNSname.cloudapp.net,因爲我計劃有幾個虛擬機在同一資源組
注1:當我執行腳本我有這樣的警告:
警告:不要將部署在服務中找到:「testBananas」
注2::如果創建第二個VM「測試蘋果」的DNS名稱和PublicIP是一樣的「測試橙子」,雖然私有IP是不同的。測試橙子的外部SSH端口爲55525,測試蘋果爲53456.如果我在兩者中執行SSH並執行「主機名稱」,則名稱匹配...
定義上我的腳本有問題:-(
但隨後它會在不同的資源組結束... –
ASM不堅持像ARM資源組的概念它只會創建您指定的組件並使用其自己的邏輯來確定資源組名稱。如果你想要一個基於資源組的解決方案,你需要使用ARM –