適用対象: Azure Database for PostgreSQL - フレキシブル サーバー
エラスティック クラスターを使用する Azure Database for PostgreSQL フレキシブル サーバーは、クラウドで水平スケールアウト機能を備えた高可用性の PostgreSQL データベースを実行、管理、スケーリングするために使うマネージド サービスです。 Azure Resource Manager テンプレート (ARM テンプレート) を使って、エラスティック クラスター インスタンスを作成できます。
Azure Resource Manager テンプレートは JavaScript Object Notation (JSON) ファイルであり、プロジェクトのインフラストラクチャと構成が定義されています。 このテンプレートでは、宣言型の構文が使用されています。 デプロイしようとしているものを、デプロイを作成する一連のプログラミング コマンドを記述しなくても記述できます。
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 で作成されたかどうかを確認するには、次の手順に従います。
適用対象: Azure Database for PostgreSQL - フレキシブル サーバー
- Azure portal で、Azure Database for PostgreSQL フレキシブル サーバー を検索して選びます。
- データベースの一覧で、新しいサーバーを選択し、サーバーを管理するための [概要] ページを表示します。
リソースをクリーンアップする
「関連コンテンツ」 セクションに記載されている次の推奨手順で、このリソース グループと作成したエラスティック クラスターを引き続き使用する場合は、そのままにしておきます。 次の手順では、さまざまなアプリケーション シャーディング モデルと設計でエラスティック クラスターを使う方法を示します。
リソース グループを削除するには:
適用対象: Azure Database for PostgreSQL - フレキシブル サーバー
ポータルで、削除するリソース グループを選択します。
- [リソース グループの削除] を選択します。
- 削除を確認するには、リソース グループの名前を入力します。