Szybki start: tworzenie maszyny wirtualnej SQL Server przy użyciu szablonu usługi ARM

Użyj tego szablonu usługi Azure Resource Manager (szablonu usługi ARM), aby wdrożyć SQL Server na maszynie wirtualnej platformy Azure.

Szablon usługi ARM to plik w formacie JavaScript Object Notation (JSON) definiujący infrastrukturę i konfigurację projektu. W szablonie używana jest składnia deklaratywna. W składni deklaratywnej opisujesz rozwiązanie, które chcesz wdrożyć, bez konieczności pisania sekwencji poleceń programistycznych służących do tworzenia takiego wdrożenia.

Jeśli Twoje środowisko spełnia wymagania wstępne i masz doświadczenie w korzystaniu z szablonów ARM, wybierz przycisk Wdróż na platformie Azure. Szablon zostanie otwarty w witrynie Azure Portal.

Wdrażanie na platformie Azure

Wymagania wstępne

Szablon usługi ARM maszyny wirtualnej SQL Server wymaga następujących elementów:

Przegląd szablonu

Szablon używany w tym przewodniku Szybki start jest jednym z szablonów szybkiego startu platformy 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')]"
    }
  }
}

Pięć zasobów platformy Azure jest zdefiniowanych w szablonie:

Więcej SQL Server szablonów maszyn wirtualnych platformy Azure można znaleźć w galerii szablonów szybkiego startu.

Wdrożenie szablonu

  1. Wybierz poniższy obraz, aby zalogować się na platformie Azure i otworzyć szablon. Szablon tworzy maszynę wirtualną z zainstalowaną docelową wersją SQL Server i zarejestrowaną w rozszerzeniu agenta IaaS SQL.

    Wdrażanie na platformie Azure

  2. Wybierz lub wprowadź następujące wartości.

    • Subskrypcja: wybierz subskrypcję platformy Azure.
    • Grupa zasobów: przygotowana grupa zasobów dla maszyny wirtualnej SQL Server.
    • Region: wybierz region. Na przykład Środkowe stany USA.
    • Nazwa maszyny wirtualnej: wprowadź nazwę maszyny wirtualnej SQL Server.
    • Rozmiar maszyny wirtualnej: wybierz odpowiedni rozmiar maszyny wirtualnej z listy rozwijanej.
    • Istniejąca nazwa Virtual Network: wprowadź nazwę przygotowanej sieci wirtualnej dla maszyny wirtualnej SQL Server.
    • Istniejąca grupa zasobów sieci wirtualnej: wprowadź grupę zasobów, w której została przygotowana sieć wirtualna.
    • Nazwa istniejącej podsieci: nazwa przygotowanej podsieci.
    • Oferta obrazu: wybierz obraz SQL Server i Windows Server, który najlepiej odpowiada Twoim potrzebom biznesowym.
    • Jednostka SKU SQL: wybierz wersję jednostki SKU SQL Server, która najlepiej odpowiada Twoim potrzebom biznesowym.
    • Administracja Nazwa użytkownika: nazwa użytkownika administratora maszyny wirtualnej.
    • Administracja hasło: hasło używane przez konto administratora maszyny wirtualnej.
    • Typ obciążenia magazynu: typ magazynu dla obciążenia, który najlepiej odpowiada Twojej firmie.
    • Liczba dysków sql Data Disk: liczba dysków SQL Server używanych dla plików danych.
    • Ścieżka danych: ścieżka dla plików danych SQL Server.
    • Liczba dysków dziennika SQL: liczba dysków SQL Server używanych dla plików dziennika.
    • Ścieżka dziennika: ścieżka dla plików dziennika SQL Server.
    • Lokalizacja: lokalizacja wszystkich zasobów powinna pozostać domyślną wartością [resourceGroup().location].
  3. Wybierz pozycję Przejrzyj i utwórz. Po pomyślnym wdrożeniu maszyny wirtualnej SQL Server zostanie wyświetlone powiadomienie.

Szablon jest wdrażany za pomocą witryny Azure Portal. Oprócz Azure Portal można również użyć Azure PowerShell, interfejsu wiersza polecenia platformy Azure i interfejsu API REST. Aby poznać inne metody wdrażania, zobacz Wdrażanie szablonów.

Przeglądanie wdrożonych zasobów

Aby sprawdzić wdrożone zasoby, możesz użyć interfejsu wiersza polecenia platformy Azure.

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

Czyszczenie zasobów

Jeśli grupa zasobów nie jest już potrzebna, usuń je przy użyciu interfejsu wiersza polecenia platformy Azure lub Azure PowerShell:

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

Następne kroki

Aby zapoznać się z samouczkiem krok po kroku, który przeprowadzi Cię przez proces tworzenia szablonu, zobacz:

Aby uzyskać inne sposoby wdrażania maszyny wirtualnej SQL Server, zobacz:

Aby dowiedzieć się więcej, zobacz omówienie SQL Server na maszynach wirtualnych platformy Azure.