단일 SQL 데이터베이스 살펴보기

완료됨

단일 Azure SQL Database를 배포하는 몇 가지 방법을 살펴보겠습니다.

포털을 통해 배포

Azure Portal을 통해 SQL 데이터베이스를 만드는 것은 간단합니다. 먼저 Azure Portal로 이동하고 왼쪽 메뉴에서 "SQL Database"를 선택합니다. 표시되는 슬라이드 아웃 패널에서 "만들기"를 선택합니다.

Azure Portal Azure SQL Database 배포 페이지를 보여 주는 스크린샷.

아래 이미지에 있는 패널에서 구독이 이미 제공되어 있음을 확인할 수 있습니다. 다음 정보를 제공해야 합니다.

  • 리소스 그룹 – 사용하려는 기존 리소스 그룹이 있는 경우 드롭다운 목록에서 선택합니다. 이 Azure SQL Database에 대한 새 리소스 그룹을 만들려면 새 만들기 옵션을 선택합니다.
  • 데이터베이스 이름 – 데이터베이스의 이름을 제공합니다.
  • 서버 – 각 데이터베이스는 논리 서버에 있어야 합니다. 해당 지역에 이미 있는 경우 선택할 수 있습니다. 그렇지 않은 경우 새 만들기 링크를 선택하고 프롬프트에 따라 데이터베이스를 호스트할 새 논리 서버를 만듭니다.
  • SQL 탄력적 풀을 사용하시겠습니까? – 탄력적 풀을 사용할지 여부를 결정합니다.
  • 컴퓨팅 + 스토리지 – 필요한 컴퓨팅 리소스를 확인합니다. 기본적으로 32GB 스토리지가 있는 Gen5, 2vCore로 설정됩니다. 데이터베이스 구성을 선택하여 대체 구성 옵션을 보고 선택합니다.

Azure Portal의 SQL Database 만들기 페이지를 보여 주는 스크린샷.

여기서는 서비스 계층이 범용이며 컴퓨팅 계층은 앞에서 설명한 대로 서버리스임을 알 수 있습니다. 서버리스는 사용된 vCore 수에 따라 초당 청구됩니다. 대체 옵션은 프로비전됩니다. 여기서 컴퓨팅 리소스는 구성된 vCore 수에 따라 시간당 미리 할당되고 요금이 청구됩니다.

Azure Portal에서 서비스 계층 선택.

PowerShell/CLI를 통해 Azure SQL Database 배포

Azure PowerShell 또는 Azure CLI를 통해서도 데이터베이스를 배포할 수 있습니다. 아래 이미지는 새 리소스 그룹을 만들고 SqlAdmin이라는 관리자를 정의한 다음 새 서버, 데이터베이스 및 방화벽 규칙을 만드는 PowerShell 예제를 보여줍니다.

# Connect-AzAccount

# The SubscriptionId in which to create these objects
$SubscriptionId = ''

# Set the resource group name and ___location for your server
$resourceGroupName = "myResourceGroup-$(Get-Random)"
$___location = "westus2"

# Set an admin login and password for your server
$adminSqlLogin = "SqlAdmin"
$password = "ChangeYourAdminPassword1"

# Set server name - the logical server name has to be unique in the system
$serverName = "server-$(Get-Random)"

# The sample database name
$databaseName = "mySampleDatabase"

# The ip address range that you want to allow to access your server
$startIp = "0.0.0.0"
$endIp = "0.0.0.0"

# Set subscription
Set-AzContext -SubscriptionId $subscriptionId

# Create a resource group
$resourceGroup = New-AzResourceGroup -Name $resourceGroupName -Location $___location

# Create a server with a system wide unique server name
$server = New-AzSqlServer -ResourceGroupName $resourceGroupName `
 -ServerName $serverName `
 -Location $___location `
 -SqlAdministratorCredentials $(New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminSqlLogin, $(ConvertTo-SecureString -String $password -AsPlainText -Force))

# Create a server firewall rule that allows access from the specified IP range

$serverFirewallRule = New-AzSqlServerFirewallRule -ResourceGroupName $resourceGroupName `
 -ServerName $serverName `
 -FirewallRuleName "AllowedIPs" -StartIpAddress $startIp -EndIpAddress $endIp

# Create a blank database with an S0 performance level

$database = New-AzSqlDatabase -ResourceGroupName $resourceGroupName `
 -ServerName $serverName `
 -DatabaseName $databaseName `
 -RequestedServiceObjectiveName "S0" `
 -SampleName "AdventureWorksLT"

Azure CLI를 사용하여 아래와 같이 Azure SQL Database를 배포할 수도 있습니다.

#!/bin/bash

# set execution context (if necessary)
az account set --subscription <replace with your subscription name or id>

# Set the resource group name and ___location for your server
resourceGroupName=myResourceGroup-$RANDOM
___location=westus2

# Set an admin login and password for your database
adminlogin=ServerAdmin
password=`openssl rand -base64 16`

# password=<EnterYourComplexPasswordHere1>

# The logical server name has to be unique in all of Azure 
servername=server-$RANDOM

# The ip address range that you want to allow to access your DB
startip=0.0.0.0
endip=0.0.0.0

# Create a resource group
az group create \
 --name $resourceGroupName \
 --___location $___location

# Create a logical server in the resource group
az sql server create \
 --name $servername \
 --resource-group $resourceGroupName \
 --___location $___location \
 --admin-user $adminlogin \
 --admin-password $password

# Configure a firewall rule for the server

az sql server firewall-rule create \
 --resource-group $resourceGroupName \
 --server $servername \
 -n AllowYourIp \
 --start-ip-address $startip \
 --end-ip-address $endip

# Create a database in the server
az sql db create \
 --resource-group $resourceGroupName \
 --server $servername 
 --name mySampleDatabase \
 --sample-name AdventureWorksLT \
 --edition GeneralPurpose \
 --family Gen4 \
 --capacity 1 \

# Echo random password
echo $password

Azure Resource Manager 템플릿을 사용하여 Azure SQL Database 배포

리소스를 배포하는 또 다른 방법은 앞서 설명한 바와 같이 Azure Resource Manager 템플릿을 사용하는 것입니다. Resource Manager 템플릿은 리소스에 대한 가장 세분화된 제어를 제공하며, Microsoft는 배포에서 참조할 수 있는 Azure Resource Manager 템플릿을 호스트하는 GitHub 리포지토리를 Azure-Quickstart-Templates제공합니다. GitHub 기반 템플릿을 배포하는 PowerShell 예제는 다음과 같습니다.

#Define Variables for parameters to pass to template
$projectName = Read-Host -Prompt "Enter a project name"
$___location = Read-Host -Prompt "Enter an Azure ___location (i.e. centralus)"
$adminUser = Read-Host -Prompt "Enter the SQL server administrator username"
$adminPassword = Read-Host -Prompt "Enter the SQl server administrator password" -AsSecureString
$resourceGroupName = "${projectName}rg"

#Create Resource Group and Deploy Template to Resource Group
New-AzResourceGroup -Name $resourceGroupName -Location $___location

New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName `
 -TemplateUri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-sql-logical-server/azuredeploy.json" `
 -administratorLogin $adminUser -administratorLoginPassword $adminPassword

Read-Host -Prompt "Press [ENTER] to continue ..."

이 스크립트는 Azure 리소스 그룹 만들기 및 그 안에 있는 SQL 논리 서버의 배포를 자동화합니다. 사용자에게 프로젝트 이름, Azure 위치 및 SQL Server 관리자 자격 증명을 묻는 메시지를 표시한 다음 제공된 세부 정보를 사용하여 리소스 그룹을 만듭니다. 마지막으로 지정된 URI에서 미리 정의된 ARM 템플릿을 사용하여 리소스 그룹에 SQL 논리 서버를 배포하고 사용자가 누를 때까지 실행을 일시 중지합니다 ENTER.