Migrera till Innovate Summit:
Lär dig hur migrering och modernisering till Azure kan öka företagets prestanda, motståndskraft och säkerhet, så att du kan använda AI fullt ut.Registrera dig nu
Den här webbläsaren stöds inte längre.
Uppgradera till Microsoft Edge och dra nytta av de senaste funktionerna och säkerhetsuppdateringarna, samt teknisk support.
Azure är värd för Azure Cloud Shell, en interaktiv gränssnittsmiljö som du kan använda via webbläsaren. Du kan använda antingen Bash eller PowerShell med Cloud Shell för att arbeta med Azure-tjänster. Du kan använda förinstallerade Cloud Shell-kommandon för att köra koden i den här artikeln, utan att behöva installera något i din lokala miljö.
Så här startar du Azure Cloud Shell:
Alternativ
Exempel/länk
Välj Prova i det övre högra hörnet av ett kodblock. Om du väljer Prova kopieras koden inte automatiskt till Cloud Shell.
Gå till https://shell.azure.com eller Välj knappen Starta Cloud Shell för att öppna Cloud Shell i webbläsaren.
Välj knappen Cloud Shell på menyn längst upp till höger i Azure-portalen.
Så här kör du koden i den här artikeln i Azure Cloud Shell:
Starta Cloud Shell.
Kopiera koden genom att klicka på knappen Kopiera på ett kodblock.
Klistra in koden i Cloud Shell-sessionen genom att välja Ctrl+Skift+V i Windows och Linux, eller genom att välja Cmd+Shift+V på macOS.
Välj Retur för att köra koden.
Om du väljer att installera och använda PowerShell lokalt kräver den här självstudien Azure PowerShell 1.4.0 eller senare. Om du behöver uppgradera kan du läsa Install Azure PowerShell module (Installera Azure PowerShell-modul). Om du kör PowerShell lokalt måste du också köra Connect-AzAccount för att skapa en anslutning till Azure.
Exempelskript
PowerShell
$NSnetworkModels = "Microsoft.Azure.Commands.Network.Models"$NScollections = "System.Collections.Generic"Connect-AzAccount# The SubscriptionId in which to create these objects$SubscriptionId = ''# Set the resource group name and location for your managed instance$resourceGroupName = "myResourceGroup-$(Get-Random)"$location = "eastus2"# Set the networking values for your managed instance$vNetName = "myVnet-$(Get-Random)"$vNetAddressPrefix = "10.0.0.0/16"$defaultSubnetName = "myDefaultSubnet-$(Get-Random)"$defaultSubnetAddressPrefix = "10.0.0.0/24"$miSubnetName = "myMISubnet-$(Get-Random)"$miSubnetAddressPrefix = "10.0.0.0/24"#Set the managed instance name for the new managed instance$instanceName = "myMIName-$(Get-Random)"# Set the admin login and password for your managed instance$miAdminSqlLogin = "SqlAdmin"$miAdminSqlPassword = "ChangeYourAdminPassword1"# Set the managed instance service tier, compute level, and license mode$edition = "General Purpose"$vCores = 8$maxStorage = 256$computeGeneration = "Gen5"$license = "LicenseIncluded"#"BasePrice" or LicenseIncluded if you have don't have SQL Server licence that can be used for AHB discount# Set subscription contextSet-AzContext -SubscriptionId$SubscriptionId# Create a resource group$resourceGroup = New-AzResourceGroup -Name$resourceGroupName -Location$location -Tag @{Owner="SQLDB-Samples"}
# Configure virtual network, subnets, network security group, and routing table$networkSecurityGroupMiManagementService = New-AzNetworkSecurityGroup `
-Name'myNetworkSecurityGroupMiManagementService' `
-ResourceGroupName$resourceGroupName `
-location$location$routeTableMiManagementService = New-AzRouteTable `
-Name'myRouteTableMiManagementService' `
-ResourceGroupName$resourceGroupName `
-location$location$virtualNetwork = New-AzVirtualNetwork `
-ResourceGroupName$resourceGroupName `
-Location$location `
-Name$vNetName `
-AddressPrefix$vNetAddressPrefixAdd-AzVirtualNetworkSubnetConfig `
-Name$miSubnetName `
-VirtualNetwork$virtualNetwork `
-AddressPrefix$miSubnetAddressPrefix `
-NetworkSecurityGroup$networkSecurityGroupMiManagementService `
-RouteTable$routeTableMiManagementService |
Set-AzVirtualNetwork$virtualNetwork = Get-AzVirtualNetwork -Name$vNetName -ResourceGroupName$resourceGroupName$subnet= $virtualNetwork.Subnets[0]
# Create a delegation$subnet.Delegations = New-Object"$NScollections.List``1[$NSnetworkModels.PSDelegation]"$delegationName = "dgManagedInstance" + (Get-Random -Maximum1000)
$delegation = New-AzDelegation -Name$delegationName -ServiceName"Microsoft.Sql/managedInstances"$subnet.Delegations.Add($delegation)
Set-AzVirtualNetwork -VirtualNetwork$virtualNetwork$miSubnetConfigId = $subnet.Id
$allowParameters = @{
Access = 'Allow'
Protocol = 'Tcp'
Direction= 'Inbound'
SourcePortRange = '*'
SourceAddressPrefix = 'VirtualNetwork'
DestinationAddressPrefix = '*'
}
$denyInParameters = @{
Access = 'Deny'
Protocol = '*'
Direction = 'Inbound'
SourcePortRange = '*'
SourceAddressPrefix = '*'
DestinationPortRange = '*'
DestinationAddressPrefix = '*'
}
$denyOutParameters = @{
Access = 'Deny'
Protocol = '*'
Direction = 'Outbound'
SourcePortRange = '*'
SourceAddressPrefix = '*'
DestinationPortRange = '*'
DestinationAddressPrefix = '*'
}
Get-AzNetworkSecurityGroup `
-ResourceGroupName$resourceGroupName `
-Name"myNetworkSecurityGroupMiManagementService" |
Add-AzNetworkSecurityRuleConfig `
@allowParameters `
-Priority1000 `
-Name"allow_tds_inbound" `
-DestinationPortRange1433 |
Add-AzNetworkSecurityRuleConfig `
@allowParameters `
-Priority1100 `
-Name"allow_redirect_inbound" `
-DestinationPortRange11000-11999 |
Add-AzNetworkSecurityRuleConfig `
@denyInParameters `
-Priority4096 `
-Name"deny_all_inbound" |
Add-AzNetworkSecurityRuleConfig `
@denyOutParameters `
-Priority4096 `
-Name"deny_all_outbound" |
Set-AzNetworkSecurityGroup# Create credentials$secpassword = ConvertTo-SecureString$miAdminSqlPassword -AsPlainText -Force$credential = New-Object System.Management.Automation.PSCredential ($miAdminSqlLogin, $secpassword)
# Create managed instanceNew-AzSqlInstance -Name$instanceName `
-ResourceGroupName$resourceGroupName -Location$location -SubnetId$miSubnetConfigId `
-AdministratorCredential$credential `
-StorageSizeInGB$maxStorage -VCore$vCores -Edition$edition `
-ComputeGeneration$computeGeneration -LicenseType$license# Clean up deployment # Remove-AzResourceGroup -ResourceGroupName $resourceGroupName
Rensa distribution
Använd följande kommando för att ta bort resursgruppen och alla resurser som är associerade med den.
Det här skriptet använder några av följande kommandon. Om du vill ha mer information om använda och andra kommandon i tabellen nedan klickar du på länkarna till kommandospecifik dokumentation.
Administrera en SQL Server-databasinfrastruktur för molndatabaser, lokala databaser och hybridrelationsdatabaser med hjälp av microsoft PaaS-relationsdatabaserbjudanden.