다음을 통해 공유


빠른 시작: ARM 템플릿을 사용하여 Azure Database for PostgreSQL(미리 보기)을 사용하여 탄력적 클러스터 만들기

탄력적 클러스터가 있는 Azure Database for PostgreSQL은 수평 스케일 아웃 기능을 사용하여 클라우드에서 고가용성 PostgreSQL 데이터베이스를 실행, 관리 및 확장하는 데 사용하는 관리되는 서비스입니다. ARM 템플릿(Azure Resource Manager 템플릿)을 사용하여 탄력적 클러스터 인스턴스를 만들 수 있습니다.

Azure Resource Manager 템플릿은 프로젝트에 대한 인프라 및 구성을 정의하는 JSON(JavaScript Object Notation) 파일입니다. 이 템플릿은 선언적 구문을 사용합니다. 배포를 만들기 위한 프로그래밍 명령의 시퀀스를 작성하지 않고 의도하는 배포를 설명합니다.

Azure Resource Manager는 Azure용 배포 및 관리 서비스입니다. Azure 계정에서 리소스를 만들고, 업데이트하고, 삭제할 수 있는 관리 계층을 제공합니다. 배포 이후 액세스 제어, 잠금 및 태그와 같은 관리 기능을 사용하여 리소스를 보호하고 구성합니다. Azure Resource Manager 템플릿에 대한 자세한 내용은 템플릿 배포 개요를 참조하세요.

필수 조건

활성 구독이 있는 Azure 계정. 체험 계정 만들기

템플릿 검토

Azure Database for PostgreSQL 유연한 서버 인스턴스는 지역 내의 분산 데이터베이스에 대한 부모 리소스입니다. 클러스터에 적용되는 관리 정책의 범위(방화벽, 사용자, 역할 및 구성)를 제공합니다.

postgres-flexible-server-template.json 파일을 만들고 여기에 다음 JSON 스크립트를 복사합니다.

{
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "administratorLogin": {
      "type": "string"
    },
    "administratorLoginPassword": {
      "type": "securestring"
    },
    "location": {
      "type": "string",
      "defaultValue": "eastus"
    },
    "serverName": {
      "type": "string"
    },
    "serverEdition": {
      "type": "string",
      "defaultValue": "GeneralPurpose"
    },
    "storageSizeGB": {
      "type": "int",
      "defaultValue": 64
    },
    "haEnabled": {
      "type": "string",
      "defaultValue": "Disabled"
    },
    "availabilityZone": {
      "type": "string",
      "defaultValue": "1"
    },
    "standbyAvailabilityZone": {
      "type": "string",
      "defaultValue": ""
    },
    "backupRetentionDays": {
      "type": "int",
      "defaultValue": 7
    },
    "skuName": {
      "type": "string",
      "defaultValue": "Standard_D4ds_v5"
    },
    "clusterSize": {
      "type": "int",
      "defaultValue": 2
    },
    "guid": {
      "type": "string",
      "defaultValue": "[newGuid()]"
    },
    "firewallRules": {
      "type": "object",
      "defaultValue": {
        "rules": [
          {
            "name": "ClientIP",
            "startIPAddress": "131.107.1.255",
            "endIPAddress": "131.107.1.255"
          },
          {
            "name": "AllowAll",
            "startIPAddress": "0.0.0.0",
            "endIPAddress": "255.255.255.255"
          }
        ]
      }
    },
    "network": {
      "type": "object",
      "defaultValue": { "publicNetworkAccess": "Enabled" }
    }
  },
  "variables": {
    "firewallRules": "[parameters('firewallRules').rules]"
  },
  "resources": [
    {
      "apiVersion": "2024-05-01-privatepreview",
      "location": "[parameters('location')]",
      "name": "[parameters('serverName')]",
      "properties": {
        "createMode": "Default",
        "version": "16",
        "administratorLogin": "[parameters('administratorLogin')]",
        "administratorLoginPassword": "[parameters('administratorLoginPassword')]",
        "availabilityZone": "[parameters('availabilityZone')]",
        "Storage": {
          "StorageSizeGB": "[parameters('storageSizeGB')]",
          "Autogrow": "Disabled"
        },
        "Network": "[if(empty(parameters('network')), json('null'), parameters('network'))]",
        "Backup": {
          "backupRetentionDays": "[parameters('backupRetentionDays')]",
          "geoRedundantBackup": "Disabled"
        },
        "highAvailability": {
          "mode": "[parameters('haEnabled')]",
          "standbyAvailabilityZone": "[parameters('standbyAvailabilityZone')]"
        },
        "cluster": {
          "clusterSize": "[parameters('clusterSize')]"
        }
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "tier": "[parameters('serverEdition')]"
      },
      "type": "Microsoft.DBforPostgreSQL/flexibleServers"
    },
    {
      "condition": "[greater(length(variables('firewallRules')), 0)]",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2019-08-01",
      "name": "[concat('firewallRules-', parameters('guid'), '-', copyIndex())]",
      "copy": {
        "count": "[if(greater(length(variables('firewallRules')), 0), length(variables('firewallRules')), 1)]",
        "mode": "Serial",
        "name": "firewallRulesIterator"
      },
      "dependsOn": [
        "[concat('Microsoft.DBforPostgreSQL/flexibleServers/', parameters('serverName'))]"
      ],
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "resources": [
            {
              "type": "Microsoft.DBforPostgreSQL/flexibleServers/firewallRules",
              "name": "[concat(parameters('serverName'),'/',variables('firewallRules')[copyIndex()].name)]",
              "apiVersion": "2024-05-01-privatepreview",
              "properties": {
                "StartIpAddress": "[variables('firewallRules')[copyIndex()].startIPAddress]",
                "EndIpAddress": "[variables('firewallRules')[copyIndex()].endIPAddress]"
              }
            }
          ]
        }
      }
    }
  ]
}

이러한 리소스는 템플릿에 정의되어 있습니다.

템플릿 배포

다음 PowerShell 코드 블록에서 사용해 보세요를 선택하여 Azure Cloud Shell을 엽니다. clusterSize 매개 변수는 탄력적 클러스터에 있는 노드 수를 정의합니다.

$serverName = Read-Host -Prompt "Enter a name for the new Azure Database for PostgreSQL flexible server instance"
$resourceGroupName = Read-Host -Prompt "Enter a name for the new resource group where the server will exist"
$location = Read-Host -Prompt "Enter an Azure region (for example, centralus) for the resource group"
$adminUser = Read-Host -Prompt "Enter the Azure Database for PostgreSQL flexible server instance's administrator account name"
$adminPassword = Read-Host -Prompt "Enter the administrator password" -AsSecureString
$clusterSize = Read-Host -Prompt "Enter the desired cluster size"

New-AzResourceGroup -Name $resourceGroupName -Location $location # Use this command when you need to create a new resource group for your deployment
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -clusterSize $clusterSize`
    -TemplateFile "postgres-flexible-server-template.json" `
    -serverName $serverName `
    -administratorLogin $adminUser `
    -administratorLoginPassword $adminPassword

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

배포된 리소스 검토

Azure에서 서버가 생성되었는지 확인하려면 다음 단계를 수행합니다.

  1. Azure Portal에서 Azure Database for PostgreSQL 유연한 서버를 검색하고 선택합니다.
  2. 데이터베이스 목록에서 새 서버를 선택하여 개요 페이지에서 서버를 관리합니다.

리소스 정리

관련 콘텐츠 섹션에 나열된 다음 제안된 단계를 계속 진행하려면 이 리소스 그룹 및 탄력적 클러스터를 유지합니다. 다음 단계에서는 다양한 애플리케이션 분할 모델 및 디자인에서 탄력적 클러스터를 사용하는 방법을 보여 줍니다.

리소스 그룹을 삭제하려면 다음을 수행합니다.

포털에서 삭제하려는 리소스 그룹을 선택합니다.

  1. 리소스 그룹 삭제를 선택합니다.
  2. 삭제를 확인하려면 리소스 그룹의 이름을 입력합니다.