在 Azure Stack Hub 上部署 SQL Server 资源提供程序Deploy the SQL Server resource provider on Azure Stack Hub

可以使用 Azure Stack Hub SQL Server 资源提供程序来将 SQL 数据库公开为 Azure Stack Hub 服务。Use the Azure Stack Hub SQL Server resource provider to expose SQL databases as an Azure Stack Hub service. SQL 资源提供程序以服务的形式在 Windows Server 2016 Server Core 虚拟机 (VM) 上运行。The SQL resource provider runs as a service on a Windows Server 2016 Server Core virtual machine (VM).


只有资源提供程序才能在托管 SQL 或 MySQL 的服务器上创建项目。Only the resource provider is supported to create items on servers that host SQL or MySQL. 如果在不是由资源提供程序创建的主机服务器上创建项目,则此类项目可能导致状态不匹配。Items created on a host server that aren't created by the resource provider might result in a mismatched state.


需要先实施几个先决条件,然后才能部署 Azure Stack Hub SQL 资源提供程序。There are several prerequisites that need to be in place before you can deploy the Azure Stack Hub SQL resource provider. 若要满足这些要求,请在可访问特权终结点 VM 的计算机上完成以下步骤:To meet these requirements, complete the following steps on a computer that can access the privileged endpoint VM:

在离线场景中,请完成以下步骤下载所需的 PowerShell 模块,并手动注册存储库。In a disconnected scenario, complete the following steps to download the required PowerShell modules and register the repository manually.

  1. 登录到已建立 Internet 连接的计算机,使用以下脚本下载 PowerShell 模块。Sign in to a computer with internet connectivity and use the following scripts to download the PowerShell modules.
Import-Module -Name PowerShellGet -ErrorAction Stop
Import-Module -Name PackageManagement -ErrorAction Stop

# path to save the packages, c:\temp\azs1.6.0 as an example here
$Path = "c:\temp\azs1.6.0"
Save-Package -ProviderName NuGet -Source https://www.powershellgallery.com/api/v2 -Name AzureRM -Path $Path -Force -RequiredVersion 2.5.0
Save-Package -ProviderName NuGet -Source https://www.powershellgallery.com/api/v2 -Name AzureStack -Path $Path -Force -RequiredVersion 1.8.2
  1. 然后,将下载的包复制到 USB 设备。Then you copy the downloaded packages to a USB device.

  2. 登录到已断开连接的工作站,将包从 USB 设备复制到工作站中的某个位置。Sign in to the disconnected workstation and copy the packages from the USB device to a location on the workstation.

  3. 将此位置注册为本地存储库。Register this location as a local repository.

# requires -Version 5
# requires -RunAsAdministrator
# requires -Module PowerShellGet
# requires -Module PackageManagement

$SourceLocation = "C:\temp\azs1.6.0"
$RepoName = "azs1.6.0"

Register-PSRepository -Name $RepoName -SourceLocation $SourceLocation -InstallationPolicy Trusted

New-Item -Path $env:ProgramFiles -name "SqlMySqlPsh" -ItemType "Directory"


仅适用于集成系统安装For integrated systems installations only. 必须提供 Azure Stack Hub 部署 PKI 要求中的“可选 PaaS 证书”部分所述的 SQL PaaS PKI 证书。You must provide the SQL PaaS PKI certificate described in the optional PaaS certificates section of Azure Stack Hub deployment PKI requirements. 将 .pfx 文件放在 DependencyFilesLocalPath 参数指定的位置。Place the .pfx file in the location specified by the DependencyFilesLocalPath parameter. 对于 ASDK 系统,请不要提供证书。Don't provide a certificate for ASDK systems.

部署 SQL 资源提供程序Deploy the SQL resource provider

安装所有必备组件后,在可访问 Azure Stack Hub 管理员 Azure 资源管理终结点和特权终结点的计算机中运行 DeploySqlProvider.ps1 脚本,以部署 SQL 资源提供程序。After you've installed all the prerequisites, run the DeploySqlProvider.ps1 script from a computer that can access both the Azure Stack Hub Admin Azure Resource Management Endpoint and Privileged Endpoint to deploy the SQL resource provider. DeploySqlProvider.ps1 脚本是从针对 Azure Stack Hub 版本下载的 SQL 资源提供程序二进制文件中提取的。The DeploySqlProvider.ps1 script is extracted as part of the SQL resource provider binary that you downloaded for your version of Azure Stack Hub.


在部署资源提供程序之前,请查看发行说明,了解新功能、修补程序以及任何可能影响部署的已知问题。Before deploying the resource provider, review the release notes to learn about new functionality, fixes, and any known issues that could affect your deployment.

若要部署 SQL 资源提供程序,请打开一个权限提升的 PowerShell(不是 PowerShell ISE)窗口,并切换到解压缩后的 SQL 资源提供程序二进制文件所在的目录。To deploy the SQL resource provider, open a new elevated PowerShell window (not PowerShell ISE) and change to the directory where you extracted the SQL resource provider binary files.


我们建议使用新的 PowerShell 窗口,以避免已加载的 PowerShell 模块造成问题。We recommend using a new PowerShell window to avoid potential problems caused by PowerShell modules that are already loaded. 或者,可以使用 clear-azurermcontext 在运行更新脚本之前清除缓存。Or you can use clear-azurermcontext to clear the cache before running the update script.

运行 DeploySqlProvider.ps1 脚本,以完成以下任务:Run the DeploySqlProvider.ps1 script, which completes the following tasks:

  • 将证书和其他项目上传到 Azure Stack Hub 上的存储帐户。Uploads the certificates and other artifacts to a storage account on Azure Stack Hub.
  • 发布库包,以便可以使用库部署 SQL 数据库。Publishes gallery packages so you can deploy SQL databases using the gallery.
  • 发布用于部署宿主服务器的库包。Publishes a gallery package for deploying hosting servers.
  • 使用下载的 Windows Server 2016 核心映像部署 VM,然后安装 SQL 资源提供程序。Deploys a VM using the Windows Server 2016 core image you downloaded, and then installs the SQL resource provider.
  • 注册映射到资源提供程序 VM 的本地 DNS 记录。Registers a local DNS record that maps to your resource provider VM.
  • 将资源提供程序注册到操作员帐户的本地 Azure 资源管理器。Registers your resource provider with the local Azure Resource Manager for the operator account.


当 SQL 资源提供程序部署开始时,将创建 system.local.sqladapter 资源组。When the SQL resource provider deployment starts, the system.local.sqladapter resource group is created. 可能需要花费多达 75 分钟才能完成此资源组的必需部署。It may take up to 75 minutes to finish the required deployments to this resource group. 不要将任何其他资源置于 system.local.sqladapter 资源组中。You should not place any other resources in the system.local.sqladapter resource group.

DeploySqlProvider.ps1 参数DeploySqlProvider.ps1 parameters

可在命令行中指定以下参数。You can specify the following parameters from the command line. 如果未指定参数或任何参数验证失败,系统会提示提供所需的参数。If you don't, or if any parameter validation fails, you're prompted to provide the required parameters.

参数名称Parameter name 说明Description 注释或默认值Comment or default value
CloudAdminCredentialCloudAdminCredential 访问特权终结点时所需的云管理员凭据。The credential for the cloud admin, necessary for accessing the privileged endpoint. 必需Required
AzCredentialAzCredential Azure Stack Hub 服务管理员帐户的凭据。The credentials for the Azure Stack Hub service admin account. 使用部署 Azure Stack Hub 时所用的相同凭据。Use the same credentials that you used for deploying Azure Stack Hub. 如果用于 AzCredential 的帐户需要多重身份验证 (MFA),则脚本将失败。The script will fail if the account you use with AzCredential requires multi-factor authentication (MFA). 必需Required
VMLocalCredentialVMLocalCredential SQL 资源提供程序 VM 的本地管理员帐户的凭据。The credentials for the local admin account of the SQL resource provider VM. 必需Required
PrivilegedEndpointPrivilegedEndpoint 特权终结点的 IP 地址或 DNS 名称。The IP address or DNS name of the privileged endpoint. 必需Required
AzureEnvironmentAzureEnvironment 用于部署 Azure Stack Hub 的服务管理员帐户的 Azure 环境。The Azure environment of the service admin account used for deploying Azure Stack Hub. 仅对于 Azure AD 部署是必需的。Required only for Azure AD deployments. 受支持的环境名称是 AzureChinaCloudSupported environment name is AzureChinaCloud. AzureChinaCloudAzureChinaCloud
DependencyFilesLocalPathDependencyFilesLocalPath 对于集成系统,必须将证书 .pfx 文件放在此目录中。For integrated systems only, your certificate .pfx file must be placed in this directory. 还可以在此处复制一个 Windows Update MSU 包。You can optionally copy one Windows Update MSU package here. 可选(对于集成系统为强制的 )Optional (mandatory for integrated systems)
DefaultSSLCertificatePasswordDefaultSSLCertificatePassword .pfx 证书的密码。The password for the .pfx certificate. 必需Required
MaxRetryCountMaxRetryCount 操作失败时,想要重试每个操作的次数。The number of times you want to retry each operation if there's a failure. 22
RetryDurationRetryDuration 每两次重试的超时间隔(秒)。The timeout interval between retries, in seconds. 120120
卸载Uninstall 删除资源提供程序和所有关联的资源(请参阅下面的注释)。Removes the resource provider and all associated resources (see the following notes). No
DebugModeDebugMode 防止在失败时自动清除。Prevents automatic cleanup on failure. No

使用自定义脚本部署 SQL 资源提供程序Deploy the SQL resource provider using a custom script

如果要部署 SQL 资源提供程序版本 或更早版本,则需要在 PowerShell 中安装特定版本的 AzureRm.BootStrapper 和 Azure Stack Hub 模块。If you're deploying the SQL resource provider version or previous versions, you need to install specific versions of AzureRm.BootStrapper and Azure Stack Hub modules in PowerShell. 如果要部署 SQL 资源提供程序版本,则部署脚本会自动下载所需的 PowerShell 模块并将其安装到路径 C:\Program Files\SqlMySqlPsh。If you're deploying the SQL resource provider version, the deployment script will automatically download and install the necessary PowerShell modules for you to path C:\Program Files\SqlMySqlPsh.

# Install the AzureRM.Bootstrapper module, set the profile, and install the AzureStack module
# Note that this might not be the most currently available version of Azure Stack Hub PowerShell
Install-Module -Name AzureRm.BootStrapper -RequiredVersion 0.5.0 -Force
Use-AzureRmProfile -Profile 2018-03-01-hybrid -Force
Install-Module -Name AzureStack -RequiredVersion 1.6.0


在断开连接的情况下,需要下载所需的 PowerShell 模块并手动注册存储库,这是先决条件。In disconnected scenario, you need to download the required PowerShell modules and register the repository manually as a prerequisite.

若要在部署资源提供程序时消除任何手动配置,可以自定义以下脚本。To eliminate any manual configuration when deploying the resource provider, you can customize the following script. 更改 Azure Stack Hub 部署所需的默认帐户信息和密码。Change the default account information and passwords as needed for your Azure Stack Hub deployment.

# Use the NetBIOS name for the Azure Stack Hub domain. On the Azure Stack Hub SDK, the default is AzureStack but could have been changed at install time.
$domain = "AzureStack"

# For integrated systems, use the IP address of one of the ERCS VMs
$privilegedEndpoint = "AzS-ERCS01"

# Provide the Azure environment used for deploying Azure Stack Hub. Required only for Azure AD deployments. Supported values for the <environment name> parameter is AzureChinaCloud depending which Azure subscription you're using.
$AzureEnvironment = "<EnvironmentName>"

# Point to the directory where the resource provider installation files were extracted.
$tempDir = 'C:\TEMP\SQLRP'

# The service admin account can be Azure Active Directory or Active Directory Federation Services.
$serviceAdmin = "admin@mydomain.partner.onmschina.cn"
$AdminPass = ConvertTo-SecureString "P@ssw0rd1" -AsPlainText -Force
$AdminCreds = New-Object System.Management.Automation.PSCredential ($serviceAdmin, $AdminPass)

# Set credentials for the new resource provider VM local admin account.
$vmLocalAdminPass = ConvertTo-SecureString "P@ssw0rd1" -AsPlainText -Force
$vmLocalAdminCreds = New-Object System.Management.Automation.PSCredential ("sqlrpadmin", $vmLocalAdminPass)

# Add the cloudadmin credential that's required for privileged endpoint access.
$CloudAdminPass = ConvertTo-SecureString "P@ssw0rd1" -AsPlainText -Force
$CloudAdminCreds = New-Object System.Management.Automation.PSCredential ("$domain\cloudadmin", $CloudAdminPass)

# Change the following as appropriate.
$PfxPass = ConvertTo-SecureString "P@ssw0rd1" -AsPlainText -Force

# For version, the PowerShell modules used by the RP deployment are placed in C:\Program Files\SqlMySqlPsh
# The deployment script adds this path to the system $env:PSModulePath to ensure correct modules are used.
$rpModulePath = Join-Path -Path $env:ProgramFiles -ChildPath 'SqlMySqlPsh'
$env:PSModulePath = $env:PSModulePath + ";" + $rpModulePath 

# Change to the directory folder where you extracted the installation files. Don't provide a certificate on ASDK!
. $tempDir\DeploySQLProvider.ps1 `
    -AzCredential $AdminCreds `
    -VMLocalCredential $vmLocalAdminCreds `
    -CloudAdminCredential $cloudAdminCreds `
    -PrivilegedEndpoint $privilegedEndpoint `
    -AzureEnvironment $AzureEnvironment `
    -DefaultSSLCertificatePassword $PfxPass `
    -DependencyFilesLocalPath $tempDir\cert

资源提供程序安装脚本完成后,刷新浏览器以确保能够看到最新的更新,然后关闭当前 PowerShell 会话。When the resource provider installation script finishes, refresh your browser to make sure you can see the latest updates and close the current PowerShell session.

使用 Azure Stack Hub 门户验证部署Verify the deployment using the Azure Stack Hub portal

  1. 以服务管理员身份登录到管理员门户。Sign in to the administrator portal as the service admin.
  2. 选择“资源组” 。Select Resource Groups.
  3. 选择 system.<location>.sqladapter 资源组。Select the system.<location>.sqladapter resource group.
  4. 在资源组概述摘要页上,应当没有失败的部署。On the summary page for Resource group Overview, there should be no failed deployments.
  5. 最后,在管理员门户中选择“虚拟机” ,以验证 SQL 资源提供程序 VM 是否已成功创建且正在运行。Finally, select Virtual machines in the administrator portal to verify that the SQL resource provider VM was successfully created and is running.

后续步骤Next steps

添加宿主服务器Add hosting servers