Azure Database for MySQL - 유연한 서버는 클라우드에서 고가용성 MySQL 데이터베이스를 실행, 관리 및 확장하는 데 사용하는 관리형 서비스입니다. ARM 템플릿(Azure Resource Manager 템플릿)을 사용하여 Azure Database for MySQL - 유연한 서버를 프로비전하여 여러 서버에 배포하거나 서버에 여러 데이터베이스를 배포할 수 있습니다.
Bicep은 선언적 구문을 사용하여 Azure 리소스를 배포하는 DSL(도메인 특정 언어)입니다. 간결한 구문, 신뢰할 수 있는 형식 안전성 및 코드 다시 사용에 대한 지원을 제공합니다. Bicep은 Azure에서 코드형 인프라 솔루션에 대한 최고의 제작 환경을 제공합니다.
필수 조건
- 활성 구독이 있는 Azure 계정.
Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만듭니다. 현재 Azure 무료 계정을 사용하면 Azure Database for MySQL - 유연한 서버를 12개월 동안 무료로 사용해 볼 수 있습니다. 자세한 내용은 Azure 체험 계정을 사용하여 Azure Database for MySQL - 유연한 서버를 무료로 사용해 보세요.
공용 액세스 권한이 있는 서버 만들기
main.bicep 파일 및 CreateFirewallRules.bicep 파일을 만들려면 다음 코드 예제를 수정합니다. 파일을 사용하여 공용 액세스 권한이 있는 Azure Database for MySQL 유연한 서버를 만들고 서버에 데이터베이스를 만듭니다. 의 기본값 firewallRules을 수정해야 할 수도 있습니다.
main.bicep:
@description('Provide a prefix for creating resource names.')
param resourceNamePrefix string
@description('Provide the location for all the resources.')
param location string = resourceGroup().location
@description('Provide the administrator login username for the flexible server.')
param administratorLogin string
@description('Provide the administrator login password for the flexible server.')
@secure()
param administratorLoginPassword string
@description('Provide an array of firewall rules to apply to the flexible server.')
param firewallRules array = [
{
name: 'rule1'
startIPAddress: '192.168.0.1'
endIPAddress: '192.168.0.255'
}
{
name: 'rule2'
startIPAddress: '192.168.1.1'
endIPAddress: '192.168.1.255'
}
]
@description('The tier of the particular SKU. High availability mode is available only in the GeneralPurpose and MemoryOptimized SKUs.')
@allowed([
'Burstable'
'GeneralPurpose'
'MemoryOptimized'
])
param serverEdition string = 'Burstable'
@description('Server version')
@allowed([
'5.7'
'8.0.21'
])
param version string = '8.0.21'
@description('The availability zone information for the server. (If you don't have a preference, leave blank.)')
param availabilityZone string = '1'
@description('High availability mode for a server: Disabled, SameZone, or ZoneRedundant.')
@allowed([
'Disabled'
'SameZone'
'ZoneRedundant'
])
param haEnabled string = 'Disabled'
@description('The availability zone of the standby server.')
param standbyAvailabilityZone string = '2'
param storageSizeGB int = 20
param storageIops int = 360
@allowed([
'Enabled'
'Disabled'
])
param storageAutogrow string = 'Enabled'
@description('The name of the SKU, such as Standard_D32ds_v4.')
param skuName string = 'Standard_B1ms'
param backupRetentionDays int = 7
@allowed([
'Disabled'
'Enabled'
])
param geoRedundantBackup string = 'Disabled'
param serverName string = '${resourceNamePrefix}sqlserver'
param databaseName string = '${resourceNamePrefix}mysqldb'
resource server 'Microsoft.DBforMySQL/flexibleServers@2021-12-01-preview' = {
location: location
name: serverName
sku: {
name: skuName
tier: serverEdition
}
properties: {
version: version
administratorLogin: administratorLogin
administratorLoginPassword: administratorLoginPassword
availabilityZone: availabilityZone
highAvailability: {
mode: haEnabled
standbyAvailabilityZone: standbyAvailabilityZone
}
storage: {
storageSizeGB: storageSizeGB
iops: storageIops
autoGrow: storageAutogrow
}
backup: {
backupRetentionDays: backupRetentionDays
geoRedundantBackup: geoRedundantBackup
}
}
}
@batchSize(1)
module createFirewallRules './CreateFirewallRules.bicep' = [for i in range(0, ((length(firewallRules) > 0) ? length(firewallRules) : 1)): {
name: 'firewallRules-${i}'
params: {
ip: firewallRules[i]
serverName: serverName
}
dependsOn: [
server
]
}]
resource database 'Microsoft.DBforMySQL/flexibleServers/databases@2021-12-01-preview' = {
parent: server
name: databaseName
properties: {
charset: 'utf8'
collation: 'utf8_general_ci'
}
}
CreateFirewallRules.bicep:
param serverName string
param ip object
resource firewallRules 'Microsoft.DBforMySQL/flexibleServers/firewallRules@2021-12-01-preview' = {
name: '${serverName}/${ip.name}'
properties: {
startIpAddress: ip.startIPAddress
endIpAddress: ip.endIPAddress
}
}
두 Bicep 파일을 동일한 디렉터리에 저장합니다.
프라이빗 액세스 권한이 있는 서버 만들기
다음 코드 샘플을 수정하여 가상 네트워크 내에서 프라이빗 액세스 권한이 있는 Azure Database for MySQL 유연한 서버를 배포합니다.
@description('Provide a prefix for creating resource names.')
param resourceNamePrefix string
@description('Provide the location for all the resources.')
param location string = resourceGroup().location
@description('Provide the administrator login name for the MySQL server.')
param administratorLogin string
@description('Provide the administrator login password for the MySQL server.')
@secure()
param administratorLoginPassword string
@description('Provide Virtual Network Address Prefix')
param vnetAddressPrefix string = '10.0.0.0/16'
@description('Provide Subnet Address Prefix')
param subnetPrefix string = '10.0.0.0/24'
@description('Provide the tier of the specific SKU. High availability is available only in the GeneralPurpose and MemoryOptimized SKUs.')
@allowed([
'Burstable'
'Generalpurpose'
'MemoryOptimized'
])
param serverEdition string = 'Burstable'
@description('Provide Server version')
@allowed([
'5.7'
'8.0.21'
])
param serverVersion string = '8.0.21'
@description('The availability zone information for the server. (If you don't have a preference, leave blank.)')
param availabilityZone string = '1'
@description('Provide the high availability mode for a server: Disabled, SameZone, or ZoneRedundant.')
@allowed([
'Disabled'
'SameZone'
'ZoneRedundant'
])
param haEnabled string = 'Disabled'
@description('Provide the availability zone of the standby server.')
param standbyAvailabilityZone string = '2'
param storageSizeGB int = 20
param storageIops int = 360
@allowed([
'Enabled'
'Disabled'
])
param storageAutogrow string = 'Enabled'
@description('The name of the sku, e.g. Standard_D32ds_v4.')
param skuName string = 'Standard_B1ms'
param backupRetentionDays int = 7
@allowed([
'Disabled'
'Enabled'
])
param geoRedundantBackup string = 'Disabled'
var serverName = '${resourceNamePrefix}mysqlserver'
var databaseName = '${resourceNamePrefix}mysqldatabase'
var vnetName = '${resourceNamePrefix}mysqlvnet'
var subnetName = '${resourceNamePrefix}mysqlsubnet'
resource vnet 'Microsoft.Network/virtualNetworks@2022-07-01' = {
name: vnetName
location: location
properties: {
addressSpace: {
addressPrefixes: [
vnetAddressPrefix
]
}
}
}
resource subnet 'Microsoft.Network/virtualNetworks/subnets@2022-07-01' = {
parent: vnet
name: subnetName
properties: {
addressPrefix: subnetPrefix
delegations: [
{
name: 'MySQLflexibleServers'
properties: {
serviceName: 'Microsoft.DBforMySQL/flexibleServers'
}
}
]
}
}
resource server 'Microsoft.DBforMySQL/flexibleServers@2021-12-01-preview' = {
location: location
name: serverName
sku: {
name: skuName
tier: serverEdition
}
properties: {
version: serverVersion
administratorLogin: administratorLogin
administratorLoginPassword: administratorLoginPassword
availabilityZone: availabilityZone
highAvailability: {
mode: haEnabled
standbyAvailabilityZone: standbyAvailabilityZone
}
storage: {
storageSizeGB: storageSizeGB
iops: storageIops
autoGrow: storageAutogrow
}
network: {
delegatedSubnetResourceId: subnet.id
}
backup: {
backupRetentionDays: backupRetentionDays
geoRedundantBackup: geoRedundantBackup
}
}
}
resource database 'Microsoft.DBforMySQL/flexibleServers/databases@2021-12-01-preview' = {
parent: server
name: databaseName
properties: {
charset: 'utf8'
collation: 'utf8_general_ci'
}
}
템플릿 배포
Azure CLI 또는 Azure PowerShell을 사용하여 Bicep 파일을 배포합니다.
az group create --name exampleRG --location eastus
az deployment group create --resource-group exampleRG --template-file main.bicep
지침에 따라 매개 변수 값을 입력합니다. 배포가 완료되면 배포에 성공했음을 나타내는 메시지가 표시됩니다.
배포된 리소스 검토
Azure Database for MySQL 유연한 서버가 리소스 그룹에 생성되었는지 확인하려면 다음을 수행합니다.
az resource list --resource-group exampleRG
리소스 정리
리소스 그룹 및 리소스 그룹에 포함된 리소스를 삭제하려면 다음을 수행합니다.
az group delete --name exampleRG