クイック スタート:ARM テンプレートを使用して SQL Server VM を作成する

この Azure Resource Manager テンプレート (ARM テンプレート) を使用して、Azure 仮想マシン (VM) に SQL Server をデプロイします。

ARM テンプレートは JavaScript Object Notation (JSON) ファイルであり、プロジェクトのインフラストラクチャと構成が定義されています。 このテンプレートでは、宣言型の構文が使用されています。 宣言型の構文では、デプロイしようとしているものを、デプロイを作成する一連のプログラミング コマンドを記述しなくても記述できます。

環境が前提条件を満たしていて、ARM テンプレートの使用に慣れている場合は、 [Azure へのデプロイ] ボタンを選択します。 Azure portal でテンプレートが開きます。

Azure へのデプロイ

前提条件

SQL Server VM ARM テンプレートには、次のものが必要です。

テンプレートを確認する

このクイックスタートで使用されるテンプレートは Azure クイックスタート テンプレートからのものです。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.17.1.54307",
      "templateHash": "3407567292495018002"
    }
  },
  "parameters": {
    "virtualMachineName": {
      "type": "string",
      "defaultValue": "myVM",
      "metadata": {
        "description": "The name of the VM"
      }
    },
    "virtualMachineSize": {
      "type": "string",
      "defaultValue": "Standard_D8s_v3",
      "metadata": {
        "description": "The virtual machine size."
      }
    },
    "existingVirtualNetworkName": {
      "type": "string",
      "metadata": {
        "description": "Specify the name of an existing VNet in the same resource group"
      }
    },
    "existingVnetResourceGroup": {
      "type": "string",
      "defaultValue": "[resourceGroup().name]",
      "metadata": {
        "description": "Specify the resrouce group of the existing VNet"
      }
    },
    "existingSubnetName": {
      "type": "string",
      "metadata": {
        "description": "Specify the name of the Subnet Name"
      }
    },
    "imageOffer": {
      "type": "string",
      "defaultValue": "sql2019-ws2022",
      "allowedValues": [
        "sql2019-ws2019",
        "sql2017-ws2019",
        "sql2019-ws2022",
        "SQL2016SP1-WS2016",
        "SQL2016SP2-WS2016",
        "SQL2014SP3-WS2012R2",
        "SQL2014SP2-WS2012R2"
      ],
      "metadata": {
        "description": "Windows Server and SQL Offer"
      }
    },
    "sqlSku": {
      "type": "string",
      "defaultValue": "standard-gen2",
      "allowedValues": [
        "standard-gen2",
        "enterprise-gen2",
        "SQLDEV-gen2",
        "web-gen2",
        "enterprisedbengineonly-gen2"
      ],
      "metadata": {
        "description": "SQL Server Sku"
      }
    },
    "adminUsername": {
      "type": "string",
      "metadata": {
        "description": "The admin user name of the VM"
      }
    },
    "adminPassword": {
      "type": "securestring",
      "metadata": {
        "description": "The admin password of the VM"
      }
    },
    "storageWorkloadType": {
      "type": "string",
      "defaultValue": "General",
      "allowedValues": [
        "General",
        "OLTP",
        "DW"
      ],
      "metadata": {
        "description": "SQL Server Workload Type"
      }
    },
    "sqlDataDisksCount": {
      "type": "int",
      "defaultValue": 1,
      "maxValue": 8,
      "minValue": 1,
      "metadata": {
        "description": "Amount of data disks (1TB each) for SQL Data files"
      }
    },
    "dataPath": {
      "type": "string",
      "defaultValue": "F:\\SQLData",
      "metadata": {
        "description": "Path for SQL Data files. Please choose drive letter from F to Z, and other drives from A to E are reserved for system"
      }
    },
    "sqlLogDisksCount": {
      "type": "int",
      "defaultValue": 1,
      "maxValue": 8,
      "minValue": 1,
      "metadata": {
        "description": "Amount of data disks (1TB each) for SQL Log files"
      }
    },
    "logPath": {
      "type": "string",
      "defaultValue": "G:\\SQLLog",
      "metadata": {
        "description": "Path for SQL Log files. Please choose drive letter from F to Z and different than the one used for SQL data. Drive letter from A to E are reserved for system"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "secureBoot": {
      "type": "bool",
      "defaultValue": true,
      "metadata": {
        "description": "Secure Boot setting of the virtual machine."
      }
    },
    "vTPM": {
      "type": "bool",
      "defaultValue": true,
      "metadata": {
        "description": "vTPM setting of the virtual machine."
      }
    }
  },
  "variables": {
    "networkInterfaceName": "[format('{0}-nic', parameters('virtualMachineName'))]",
    "networkSecurityGroupName": "[format('{0}-nsg', parameters('virtualMachineName'))]",
    "networkSecurityGroupRules": [
      {
        "name": "RDP",
        "properties": {
          "priority": 300,
          "protocol": "Tcp",
          "access": "Allow",
          "direction": "Inbound",
          "sourceAddressPrefix": "*",
          "sourcePortRange": "*",
          "destinationAddressPrefix": "*",
          "destinationPortRange": "3389"
        }
      }
    ],
    "publicIpAddressName": "[format('{0}-publicip-{1}', parameters('virtualMachineName'), uniqueString(parameters('virtualMachineName')))]",
    "publicIpAddressType": "Dynamic",
    "publicIpAddressSku": "Basic",
    "diskConfigurationType": "NEW",
    "nsgId": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]",
    "subnetRef": "[resourceId(parameters('existingVnetResourceGroup'), 'Microsoft.Network/virtualNetWorks/subnets', parameters('existingVirtualNetworkName'), parameters('existingSubnetName'))]",
    "dataDisksLuns": "[range(0, parameters('sqlDataDisksCount'))]",
    "logDisksLuns": "[range(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount'))]",
    "dataDisks": {
      "createOption": "Empty",
      "caching": "ReadOnly",
      "writeAcceleratorEnabled": false,
      "storageAccountType": "Premium_LRS",
      "diskSizeGB": 1023
    },
    "tempDbPath": "D:\\SQLTemp",
    "extensionName": "GuestAttestation",
    "extensionPublisher": "Microsoft.Azure.Security.WindowsAttestation",
    "extensionVersion": "1.0",
    "maaTenantName": "GuestAttestation"
  },
  "resources": [
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2022-01-01",
      "name": "[variables('publicIpAddressName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[variables('publicIpAddressSku')]"
      },
      "properties": {
        "publicIPAllocationMethod": "[variables('publicIpAddressType')]"
      }
    },
    {
      "type": "Microsoft.Network/networkSecurityGroups",
      "apiVersion": "2022-01-01",
      "name": "[variables('networkSecurityGroupName')]",
      "location": "[parameters('location')]",
      "properties": {
        "securityRules": "[variables('networkSecurityGroupRules')]"
      }
    },
    {
      "type": "Microsoft.Network/networkInterfaces",
      "apiVersion": "2022-01-01",
      "name": "[variables('networkInterfaceName')]",
      "location": "[parameters('location')]",
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "subnet": {
                "id": "[variables('subnetRef')]"
              },
              "privateIPAllocationMethod": "Dynamic",
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIpAddressName'))]"
              }
            }
          }
        ],
        "enableAcceleratedNetworking": true,
        "networkSecurityGroup": {
          "id": "[variables('nsgId')]"
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]",
        "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIpAddressName'))]"
      ]
    },
    {
      "type": "Microsoft.Compute/virtualMachines",
      "apiVersion": "2022-03-01",
      "name": "[parameters('virtualMachineName')]",
      "location": "[parameters('location')]",
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('virtualMachineSize')]"
        },
        "storageProfile": {
          "copy": [
            {
              "name": "dataDisks",
              "count": "[length(range(0, length(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount'))))))]",
              "input": {
                "lun": "[range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))[range(0, length(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))))[copyIndex('dataDisks')]]]",
                "createOption": "[variables('dataDisks').createOption]",
                "caching": "[if(greaterOrEquals(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))[range(0, length(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))))[copyIndex('dataDisks')]], parameters('sqlDataDisksCount')), 'None', variables('dataDisks').caching)]",
                "writeAcceleratorEnabled": "[variables('dataDisks').writeAcceleratorEnabled]",
                "diskSizeGB": "[variables('dataDisks').diskSizeGB]",
                "managedDisk": {
                  "storageAccountType": "[variables('dataDisks').storageAccountType]"
                }
              }
            }
          ],
          "osDisk": {
            "createOption": "FromImage",
            "managedDisk": {
              "storageAccountType": "Premium_LRS"
            }
          },
          "imageReference": {
            "publisher": "MicrosoftSQLServer",
            "offer": "[parameters('imageOffer')]",
            "sku": "[parameters('sqlSku')]",
            "version": "latest"
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
            }
          ]
        },
        "osProfile": {
          "computerName": "[parameters('virtualMachineName')]",
          "adminUsername": "[parameters('adminUsername')]",
          "adminPassword": "[parameters('adminPassword')]",
          "windowsConfiguration": {
            "enableAutomaticUpdates": true,
            "provisionVMAgent": true
          }
        },
        "securityProfile": {
          "uefiSettings": {
            "secureBootEnabled": "[parameters('secureBoot')]",
            "vTpmEnabled": "[parameters('vTPM')]"
          },
          "securityType": "TrustedLaunch"
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
      ]
    },
    {
      "condition": "[and(parameters('vTPM'), parameters('secureBoot'))]",
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "apiVersion": "2022-03-01",
      "name": "[format('{0}/{1}', parameters('virtualMachineName'), variables('extensionName'))]",
      "location": "[parameters('location')]",
      "properties": {
        "publisher": "[variables('extensionPublisher')]",
        "type": "[variables('extensionName')]",
        "typeHandlerVersion": "[variables('extensionVersion')]",
        "autoUpgradeMinorVersion": true,
        "enableAutomaticUpgrade": true,
        "settings": {
          "AttestationConfig": {
            "MaaSettings": {
              "maaEndpoint": "",
              "maaTenantName": "[variables('maaTenantName')]"
            },
            "AscSettings": {
              "ascReportingEndpoint": "",
              "ascReportingFrequency": ""
            },
            "useCustomToken": "false",
            "disableAlerts": "false"
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]"
      ]
    },
    {
      "type": "Microsoft.SqlVirtualMachine/sqlVirtualMachines",
      "apiVersion": "2022-07-01-preview",
      "name": "[parameters('virtualMachineName')]",
      "location": "[parameters('location')]",
      "properties": {
        "virtualMachineResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
        "sqlManagement": "Full",
        "sqlServerLicenseType": "PAYG",
        "storageConfigurationSettings": {
          "diskConfigurationType": "[variables('diskConfigurationType')]",
          "storageWorkloadType": "[parameters('storageWorkloadType')]",
          "sqlDataSettings": {
            "luns": "[variables('dataDisksLuns')]",
            "defaultFilePath": "[parameters('dataPath')]"
          },
          "sqlLogSettings": {
            "luns": "[variables('logDisksLuns')]",
            "defaultFilePath": "[parameters('logPath')]"
          },
          "sqlTempDbSettings": {
            "defaultFilePath": "[variables('tempDbPath')]"
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]"
      ]
    }
  ],
  "outputs": {
    "adminUsername": {
      "type": "string",
      "value": "[parameters('adminUsername')]"
    }
  }
}

このテンプレートには、次の 5 つの Azure リソースが定義されています。

その他の Azure VM 上の SQL Server のテンプレートについては、クイック スタート テンプレート ギャラリーをご覧ください。

テンプレートのデプロイ

  1. Azure にサインインし、テンプレートを開くには次のイメージを選択します。 このテンプレートでは、目的の SQL Server バージョンがインストールされており、SQL IaaS Agent 拡張機能に登録されている仮想マシンが作成されます。

    Azure へのデプロイ

  2. 次の値を選択または入力します。

    • サブスクリプション:Azure サブスクリプションを選択します。
    • [リソース グループ] :SQL Server VM 用に準備されたリソース グループ。
    • [リージョン] :リージョンを選択します。 たとえば [米国中部] です。
    • [仮想マシン名] : SQL Server 仮想マシンの名前を入力します。
    • 仮想マシンのサイズ: ドロップダウンから、ご利用の仮想マシンに適したサイズを選びます。
    • Existing Virtual Network Name (既存の仮想ネットワーク名) : SQL Server VM 用に準備された仮想ネットワークの名前を入力します。
    • Existing Vnet Resource Group (既存の VNet リソース グループ) : 仮想ネットワークが準備されたリソース グループを入力します。
    • 既存のサブネットの名前: 準備したサブネットの名前。
    • イメージ プラン: ビジネス ニーズに最も適した SQL Server と Windows Server イメージを選択します。
    • SQL Sku (SQL SKU) : ビジネス ニーズに最も適した SQL Server SKU のエディションを選択します。
    • 管理ユーザー名: 仮想マシンの管理者のユーザー名。
    • 管理パスワード: VM 管理者アカウントによって使用されるパスワード。
    • [Storage Workload Type](ストレージ ワークロードの種類): ビジネスに最適なワークロードのストレージの種類。
    • [Sql Data Disks Count](SQL データ ディスクの数): SQL Server でデータ ファイルに使用されるディスクの数。
    • [データ パス]: SQL Server データ ファイルのパス。
    • Sql Log Disks Count(SQL ログ ディスクの数): SQL Server でログ ファイルに使用されるディスクの数。
    • [ログ パス]: SQL Server ログ ファイルのパス。
    • [場所]: すべてのリソースの場所。この値は、既定値の [resourceGroup().location] のままにしておく必要があります。
  3. [Review + create](レビュー + 作成) を選択します。 SQL Server VM が正常にデプロイされた後、通知が表示されます。

テンプレートをデプロイするには Azure portal を使用します。 Azure portal だけでなく、Azure PowerShell、Azure CLI、REST API を使用することもできます。 他のデプロイ方法については、「テンプレートのデプロイ」を参照してください。

デプロイされているリソースを確認する

Azure CLI を使用して、デプロイされたリソースを確認できます。

echo "Enter the resource group where your SQL Server VM exists:" &&
read resourcegroupName &&
az resource list --resource-group $resourcegroupName 

リソースをクリーンアップする

不要になったら、Azure CLI または Azure PowerShell を使用してリソース グループを削除します。

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

次のステップ

テンプレートの作成手順について説明したチュートリアルについては、次のページを参照してください。

SQL Server VM をデプロイするその他の方法については、以下を参照してください。

詳細については、Azure VM 上の SQL Server の概要に関するページを参照してください。