Azure CLI를 사용하여 Azure SQL Managed Instance 만들기

적용 대상:Azure SQL Managed Instance

이 Azure CLI 스크립트 예제는 새 가상 네트워크 내에서 전용 서브넷에 Azure SQL Managed Instance를 만듭니다. 또한 가상 네트워크에 대한 네트워크 보안 그룹과 경로 테이블을 구성합니다. 스크립트가 성공적으로 실행되면 가상 네트워크나 온-프레미스 환경 내에서 관리형 인스턴스에 액세스할 수 있습니다. Azure SQL Managed Instance에 연결하도록 Azure VM 구성온-프레미스에서 Azure SQL Managed Instance로의 지점 및 사이트 간 연결 구성을 참조하세요.

중요

제한 사항은 지원되는 지역지원되는 구독 유형을 참조하세요.

Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만듭니다.

사전 요구 사항

샘플 스크립트

이 스크립트의 경우 Cloud Shell에서 실행하기에 너무 오래 걸리므로 Azure CLI를 로컬로 사용하세요.

Azure에 로그인

다음 스크립트를 사용하여 특정 구독을 사용하여 로그인합니다.

subscription="<subscriptionId>" # add subscription here

az account set -s $subscription # ...or use 'az login'

자세한 내용은 활성 구독 설정 또는 대화형으로 로그인을 참조하세요.

스크립트 실행

# Create an Azure SQL Managed Instance


# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-azuresql-rg-$randomIdentifier"
tag="create-managed-instance"
vNet="msdocs-azuresql-vnet-$randomIdentifier"
subnet="msdocs-azuresql-subnet-$randomIdentifier"
nsg="msdocs-azuresql-nsg-$randomIdentifier"
route="msdocs-azuresql-route-$randomIdentifier"
instance="msdocs-azuresql-instance-$randomIdentifier"
login="azureuser"
password="Pa$$w0rD-$randomIdentifier"
dbname="SampleDB"

echo "Using resource group $resourceGroup with login: $login, password: $password..."



echo "Creating $resourceGroup in $location..."
az group create --name $resourceGroup --location "$location" --tags $tag 



echo "Creating $vNet with $subnet..."
az network vnet create --name $vNet --resource-group $resourceGroup --location "$location" --address-prefixes 10.0.0.0/16
az network vnet subnet create --name $subnet --resource-group $resourceGroup --vnet-name $vNet --address-prefixes 10.0.0.0/24 --delegations Microsoft.Sql/managedInstances

echo "Creating $nsg..."
az network nsg create --name $nsg --resource-group $resourceGroup --location "$location"

az network nsg rule create --name "allow_management_inbound" --nsg-name $nsg --priority 100 --resource-group $resourceGroup --access Allow --destination-address-prefixes 10.0.0.0/24 --destination-port-ranges 9000 9003 1438 1440 1452 --direction Inbound --protocol Tcp --source-address-prefixes "*" --source-port-ranges "*"
az network nsg rule create --name "allow_misubnet_inbound" --nsg-name $nsg --priority 200 --resource-group $resourceGroup --access Allow --destination-address-prefixes 10.0.0.0/24 --destination-port-ranges "*" --direction Inbound --protocol "*" --source-address-prefixes 10.0.0.0/24 --source-port-ranges "*"
az network nsg rule create --name "allow_health_probe_inbound" --nsg-name $nsg --priority 300 --resource-group $resourceGroup --access Allow --destination-address-prefixes 10.0.0.0/24 --destination-port-ranges "*" --direction Inbound --protocol "*" --source-address-prefixes AzureLoadBalancer --source-port-ranges "*"
az network nsg rule create --name "allow_management_outbound" --nsg-name $nsg --priority 1100 --resource-group $resourceGroup --access Allow --destination-address-prefixes AzureCloud --destination-port-ranges 443 12000 --direction Outbound --protocol Tcp --source-address-prefixes 10.0.0.0/24 --source-port-ranges "*"
az network nsg rule create --name "allow_misubnet_outbound" --nsg-name $nsg --priority 200 --resource-group $resourceGroup --access Allow --destination-address-prefixes 10.0.0.0/24 --destination-port-ranges "*" --direction Outbound --protocol "*" --source-address-prefixes 10.0.0.0/24 --source-port-ranges "*"

echo "Creating $route..."
az network route-table create --name $route --resource-group $resourceGroup --location "$location"

az network route-table route create --address-prefix 0.0.0.0/0 --name "primaryToMIManagementService" --next-hop-type Internet --resource-group $resourceGroup --route-table-name $route
az network route-table route create --address-prefix 10.0.0.0/24 --name "ToLocalClusterNode" --next-hop-type VnetLocal --resource-group $resourceGroup --route-table-name $route

echo "Configuring $subnet with $nsg and $route..."
az network vnet subnet update --name $subnet --network-security-group $nsg --route-table $route --vnet-name $vNet --resource-group $resourceGroup 


# This step will take awhile to complete. You can monitor deployment progress in the activity log within the Azure portal.
echo "Creating $instance with $vNet and $subnet..."
az sql mi create --admin-password $password --admin-user $login --name $instance --resource-group $resourceGroup --subnet $subnet --vnet-name $vNet --location "$location"



az sql midb create -g $resourceGroup --mi $instance -n $dbname --collation Latin1_General_100_CS_AS_SC

리소스 정리

다음 명령을 사용하여 이러한 리소스가 계속해서 필요한 경우가 아니면 az group delete 명령을 사용하여 리소스 그룹 및 연결된 모든 리소스를 제거합니다. 이러한 리소스 중 일부는 만들고 삭제하는 데 시간이 걸릴 수 있습니다.

az group delete --name $resourceGroup

샘플 참조

이 스크립트는 다음 명령을 사용합니다. 테이블에 있는 각 명령은 명령에 해당하는 문서에 연결됩니다.

명령 설명
az network vnet 가상 네트워크 명령입니다.
az network vnet subnet Virtual Network 서브넷 명령입니다.
az network route-table 네트워크 경로 테이블 명령입니다.
az sql mi SQL Managed Instance 명령입니다.
az sql midb SQL Managed Instance의 데이터베이스 명령입니다.

다음 단계

Azure CLI에 대한 자세한 내용은 Azure CLI 문서를 참조하세요.

기타 SQL Database CLI 스크립트 샘플은 Azure SQL 데이터베이스 문서를 참조하세요.