Mulai cepat: Membuat Azure SQL Managed Instance menggunakan templat ARM

Mulai cepat ini berfokus pada proses penyebaran templat Azure Resource Manager (templat ARM) untuk membuat Azure SQL Managed Instance dan vNet. Azure SQL Managed Instance adalah database cloud cerdas, dikelola sepenuhnya, dapat diskalakan, dengan paritas fitur hampir 100% dengan komputer database SQL Server.

Template ARM adalah file JavaScript Object Notation (JSON) yang menentukan infrastruktur dan konfigurasi untuk proyek Anda. Template tersebut menggunakan sintaksis deklaratif. Dalam sintaksis deklaratif, Anda menguraikan penyebaran yang Anda maksudkan tanpa menulis urutan perintah pemrograman untuk membuat penyebaran tersebut.

Jika lingkungan Anda telah memenuhi prasyarat dan Anda terbiasa menggunakan templat ARM, pilih tombol Sebarkan ke Azure. Templat akan terbuka di portal Microsoft Azure.

Deploy to Azure

Prasyarat

Jika Anda tidak memiliki langganan Azure, buat akun gratis.

Meninjau templat

Templat yang digunakan di mulai cepat ini berasal dari Templat Mulai Cepat 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": "2861010078937229146"
    }
  },
  "parameters": {
    "managedInstanceName": {
      "type": "string",
      "metadata": {
        "description": "Enter managed instance name."
      }
    },
    "administratorLogin": {
      "type": "string",
      "metadata": {
        "description": "Enter user name."
      }
    },
    "administratorLoginPassword": {
      "type": "securestring",
      "metadata": {
        "description": "Enter password."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Enter location. If you leave this field blank resource group location would be used."
      }
    },
    "virtualNetworkName": {
      "type": "string",
      "defaultValue": "SQLMI-VNET",
      "metadata": {
        "description": "Enter virtual network name. If you leave this field blank name will be created by the template."
      }
    },
    "addressPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/16",
      "metadata": {
        "description": "Enter virtual network address prefix."
      }
    },
    "subnetName": {
      "type": "string",
      "defaultValue": "ManagedInstance",
      "metadata": {
        "description": "Enter subnet name."
      }
    },
    "subnetPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/24",
      "metadata": {
        "description": "Enter subnet address prefix."
      }
    },
    "skuName": {
      "type": "string",
      "defaultValue": "GP_Gen5",
      "allowedValues": [
        "GP_Gen5",
        "BC_Gen5"
      ],
      "metadata": {
        "description": "Enter sku name."
      }
    },
    "vCores": {
      "type": "int",
      "defaultValue": 16,
      "allowedValues": [
        4,
        8,
        16,
        24,
        32,
        40,
        64,
        80
      ],
      "metadata": {
        "description": "Enter number of vCores."
      }
    },
    "storageSizeInGB": {
      "type": "int",
      "defaultValue": 256,
      "maxValue": 8192,
      "minValue": 32,
      "metadata": {
        "description": "Enter storage size."
      }
    },
    "licenseType": {
      "type": "string",
      "defaultValue": "LicenseIncluded",
      "allowedValues": [
        "BasePrice",
        "LicenseIncluded"
      ],
      "metadata": {
        "description": "Enter license type."
      }
    }
  },
  "variables": {
    "networkSecurityGroupName": "[format('SQLMI-{0}-NSG', parameters('managedInstanceName'))]",
    "routeTableName": "[format('SQLMI-{0}-Route-Table', parameters('managedInstanceName'))]"
  },
  "resources": [
    {
      "type": "Microsoft.Network/networkSecurityGroups",
      "apiVersion": "2021-08-01",
      "name": "[variables('networkSecurityGroupName')]",
      "location": "[parameters('location')]",
      "properties": {
        "securityRules": [
          {
            "name": "allow_tds_inbound",
            "properties": {
              "description": "Allow access to data",
              "protocol": "Tcp",
              "sourcePortRange": "*",
              "destinationPortRange": "1433",
              "sourceAddressPrefix": "VirtualNetwork",
              "destinationAddressPrefix": "*",
              "access": "Allow",
              "priority": 1000,
              "direction": "Inbound"
            }
          },
          {
            "name": "allow_redirect_inbound",
            "properties": {
              "description": "Allow inbound redirect traffic to Managed Instance inside the virtual network",
              "protocol": "Tcp",
              "sourcePortRange": "*",
              "destinationPortRange": "11000-11999",
              "sourceAddressPrefix": "VirtualNetwork",
              "destinationAddressPrefix": "*",
              "access": "Allow",
              "priority": 1100,
              "direction": "Inbound"
            }
          },
          {
            "name": "deny_all_inbound",
            "properties": {
              "description": "Deny all other inbound traffic",
              "protocol": "*",
              "sourcePortRange": "*",
              "destinationPortRange": "*",
              "sourceAddressPrefix": "*",
              "destinationAddressPrefix": "*",
              "access": "Deny",
              "priority": 4096,
              "direction": "Inbound"
            }
          },
          {
            "name": "deny_all_outbound",
            "properties": {
              "description": "Deny all other outbound traffic",
              "protocol": "*",
              "sourcePortRange": "*",
              "destinationPortRange": "*",
              "sourceAddressPrefix": "*",
              "destinationAddressPrefix": "*",
              "access": "Deny",
              "priority": 4096,
              "direction": "Outbound"
            }
          }
        ]
      }
    },
    {
      "type": "Microsoft.Network/routeTables",
      "apiVersion": "2021-08-01",
      "name": "[variables('routeTableName')]",
      "location": "[parameters('location')]",
      "properties": {
        "disableBgpRoutePropagation": false
      }
    },
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2021-08-01",
      "name": "[parameters('virtualNetworkName')]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('addressPrefix')]"
          ]
        },
        "subnets": [
          {
            "name": "[parameters('subnetName')]",
            "properties": {
              "addressPrefix": "[parameters('subnetPrefix')]",
              "routeTable": {
                "id": "[resourceId('Microsoft.Network/routeTables', variables('routeTableName'))]"
              },
              "networkSecurityGroup": {
                "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
              },
              "delegations": [
                {
                  "name": "managedInstanceDelegation",
                  "properties": {
                    "serviceName": "Microsoft.Sql/managedInstances"
                  }
                }
              ]
            }
          }
        ]
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]",
        "[resourceId('Microsoft.Network/routeTables', variables('routeTableName'))]"
      ]
    },
    {
      "type": "Microsoft.Sql/managedInstances",
      "apiVersion": "2021-11-01-preview",
      "name": "[parameters('managedInstanceName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('skuName')]"
      },
      "identity": {
        "type": "SystemAssigned"
      },
      "properties": {
        "administratorLogin": "[parameters('administratorLogin')]",
        "administratorLoginPassword": "[parameters('administratorLoginPassword')]",
        "subnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]",
        "storageSizeInGB": "[parameters('storageSizeInGB')]",
        "vCores": "[parameters('vCores')]",
        "licenseType": "[parameters('licenseType')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]"
      ]
    }
  ]
}

Sumber daya ini ditentukan dalam templat:

Semakin banyak sampel templat dapat ditemukan di Templat Azure Quickstart.

Menyebarkan templat

Pilih Cobalah dari blok kode PowerShell berikut ini untuk membuka Azure Cloud Shell.

Penting

Menerapkan instans terkelola adalah operasi yang memakan waktu. Penyebaran instans pertama di subnet biasanya memakan waktu lebih lama daripada menyebar ke subnet dengan instans terkelola yang ada. Untuk waktu penyediaan rata-rata, lihat operasi manajemen SQL Managed Instance.

$projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
$location = Read-Host -Prompt "Enter the location (i.e. centralus)"
$templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.sql/sqlmi-new-vnet/azuredeploy.json"

$resourceGroupName = "${projectName}rg"

New-AzResourceGroup -Name $resourceGroupName -Location $location
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri

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

Meninjau sumber daya yang disebarkan

Kunjungi portal Microsoft Azure dan verifikasi instans terkelola ada di grup sumber daya yang Anda pilih. Karena membuat instans terkelola dapat memakan waktu, Anda mungkin perlu memeriksa tautan Penyebaran di halaman Gambaran Umum grup sumber daya Anda.

Membersihkan sumber daya

Pertahankan instans terkelola jika Anda ingin pergi ke langkah-langkah berikutnya, tetapi hapus instans terkelola dan sumber daya terkait setelah menyelesaikan tutorial tambahan. Setelah menghapus instans terkelola, lihat Menghapus subnet setelah menghapus instans terkelola.

Untuk menghapus grup sumber daya:

$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name"
Remove-AzResourceGroup -Name $resourceGroupName

Langkah berikutnya