创建高度可用的 MySQL 数据库Create highly available MySQL databases

作为 Azure Stack 中心操作员,你可以将服务器虚拟机配置 (Vm) 来托管 MySQL Server 数据库。As an Azure Stack Hub operator, you can configure server virtual machines (VMs) to host MySQL Server databases. Azure Stack 中心成功创建并管理 MySQL 群集后,订阅 MySQL 服务的用户可以轻松地创建高度可用的 MySQL 数据库。After a MySQL cluster is successfully created and managed by Azure Stack Hub, users who have subscribed to MySQL services can easily create highly available MySQL databases.

本文介绍如何使用 Azure Stack Marketplace 项创建 具有复制群集的 MySQLThis article shows how to use Azure Stack Marketplace items to create a MySQL with replication cluster. 此解决方案使用多个 VM 将数据库从主节点复制到多个可配置的副本。This solution uses multiple VMs to replicate the databases from the master node to a configurable number of replicas. 创建群集后,可以将其作为 Azure Stack 中心 MySQL 宿主服务器添加,然后用户可以创建高度可用的 MySQL 数据库。Once created, the cluster can then be added as an Azure Stack Hub MySQL Hosting Server, and then users can create highly available MySQL databases.

重要

使用复制Azure Stack Marketplace 项的 MySQL 可能不适用于所有 Azure 云订阅环境。The MySQL with replication Azure Stack Marketplace item might not be available for all Azure cloud subscription environments. 尝试在本教程的其余部分进行操作之前,请验证 marketplace 项在你的订阅中是否可用。Verify that the marketplace item is available in your subscription before attempting to follow the rest of this tutorial.

学习内容:What you'll learn:

  • 从 marketplace 项创建 MySQL 服务器群集。Create a MySQL Server cluster from marketplace items.
  • 将 MySQL Server 群集配置为 Azure Stack 中心 MySQL 宿主服务器。Configure the MySQL Server cluster as an Azure Stack Hub MySQL Hosting Server.
  • 创建高度可用的 MySQL 数据库。Create a highly available MySQL database.

将使用可用 Azure Stack Marketplace 项创建和配置一个三 VM MySQL 服务器群集。A three-VM MySQL Server cluster will be created and configured using available Azure Stack Marketplace items.

在开始之前,请确保已成功安装 MySQL Server 资源提供程序 ,并且 Azure Stack Marketplace 中提供了以下各项:Before starting, ensure that the MySQL Server resource provider has been successfully installed and that the following items are available in Azure Stack Marketplace:

重要

需要以下所有项才能创建 MySQL 群集。All of the following are required to create the MySQL cluster.

  • 包含复制的 MySQL:这是将用于 MySQL 群集部署的 Bitnami 解决方案模板。MySQL with Replication: This is the Bitnami solution template that will be used for the MySQL cluster deployment.
  • Debian 8 "Jessie": Debian 8 "Jessie",precise-backports 内核提供 Microsoft Azure。Debian 8 "Jessie": Debian 8 "Jessie" with backports kernel for Microsoft Azure provided by credativ. Debian GNU/Linux 是最流行的 Linux 分发版之一。Debian GNU/Linux is one of the most popular Linux distributions.
  • 适用于 linux 的自定义脚本 2.0:自定义脚本扩展是一种工具,用于在 vm 设置后执行 vm 自定义任务。Custom script for linux 2.0: Custom Script Extension is a tool to execute your VM customization tasks post VM provision. 向 VM 添加此扩展时,它可以从 Azure 存储下载脚本并在 VM 上运行这些脚本。When this Extension is added to a VM, it can download scripts from Azure storage and run them on the VM. 自定义脚本扩展任务也可以使用 Azure PowerShell cmdlet 和 Azure 跨平台命令行接口 (xPlat CLI) 自动执行。Custom Script Extension tasks can also be automated using the Azure PowerShell cmdlets and Azure Cross-Platform Command-Line Interface (xPlat CLI).
  • 适用于 Linux 的 VM 访问扩展1.4.7: VM 访问扩展可用于重置密码、SSH 密钥或 SSH 配置,使你能够重新获得 VM 的访问权限。VM Access For Linux Extension 1.4.7: The VM Access extension enables you to reset the password, SSH key, or the SSH configurations so you can regain access to your VM. 你还可以使用密码或 SSH 密钥添加新用户,或使用此扩展来删除用户。You can also add a new user with password or SSH key, or delete a user using this extension. 此扩展以 Linux Vm 为目标。This extension targets Linux VMs.

若要了解有关将项目添加到 Azure Stack Marketplace 的详细信息,请参阅 Azure Stack marketplace 概述To learn more about adding items to Azure Stack Marketplace, see the Azure Stack Marketplace overview.

还需要使用 SSH 客户端(如 PuTTY ),以便在部署 Linux vm 后登录到这些 vm。You'll also need an SSH client like PuTTY to log in to the Linux VMs after they're deployed.

创建 MySQL Server 群集Create a MySQL Server cluster

使用本部分中的步骤,使用 包含复制 marketplace 项的 MySQL 部署 mysql Server 群集。Use the steps in this section to deploy the MySQL Server cluster using the MySQL with Replication marketplace item. 此模板部署在高可用性 MySQL 群集中配置的三个 MySQL Server 实例。This template deploys three MySQL Server instances configured in a highly available MySQL cluster. 默认情况下,它会创建以下资源:By default, it creates the following resources:

  • 虚拟网络A virtual network
  • 网络安全组A network security group
  • 一个存储帐户A storage account
  • 一个可用性集An availability set
  • 三个网络接口 (每个默认 Vm 一个) Three network interfaces (one for each of the default VMs)
  • 主 MySQL 群集 VM 的公共 IP 地址 () A public IP address (for the primary MySQL cluster VM)
  • 用于托管 MySQL 群集的三个 Linux VmThree Linux VMs to host the MySQL cluster
  1. 登录到用户门户:Sign in to the user portal:

    • 对于集成系统部署,门户地址将根据解决方案的区域和外部域名而有所不同。For an integrated system deployment, the portal address will vary based on your solution's region and external domain name. 它将采用 https://portal.<region>.<FQDN> 格式。It will be in the format of https://portal.<region>.<FQDN>.
    • 对于 Azure Stack 开发工具包 (ASDK),门户地址为 https://portal.local.azurestack.externalFor the Azure Stack Development Kit (ASDK), the portal address is https://portal.local.azurestack.external.
  2. 如果尚未分配订阅,请从仪表板中选择 " 获取订阅 "。If no subscriptions were assigned yet, select Get a Subscription from the Dashboard. 在边栏选项卡中,键入订阅的名称,然后选择 "产品/服务"。In the blade, type a name for the subscription, and then select an offer. 建议你在自己的订阅中保留 MySQL 群集部署,以防止意外删除。It is recommended that you keep the MySQL cluster deployment in its own subscription to prevent accidental removal.

  3. 选择 + "创建资源 > " "计算",然后选择 "使用复制的 MySQL"。Select + Create a resource > Compute, and then MySQL with Replication.

    Azure Stack 中心中的自定义模板部署

  4. 在 " 基本 信息" 页上提供基本的部署信息。Provide basic deployment information on the Basics page. 查看默认值并根据需要进行更改,然后选择 "确定"Review the default values and change as needed and select OK.

    至少提供以下信息:At a minimum, provide the following info:

    • 部署名称 (默认值为 mymysql) 。Deployment name (default is mymysql).

    • 应用程序根密码。Application root password. 提供12个字符的字母数字的密码, 不含任何特殊字符Provide a 12 character alphanumeric password with no special characters.

    • 默认 (的应用程序数据库名称为 bitnami) 。Application database name (default is bitnami).

    • 默认情况下,要创建 (的 MySQL 数据库副本 Vm 数为 2) 。Number of MySQL database replica VMs to create (default is 2).

    • 选择要使用的订阅。Select the subscription to use.

    • 选择要使用的资源组,或者创建一个新资源组。Select the resource group to use or create a new one.

    • 选择位置 (默认为 ASDK) 的本地位置。Select the location (default is local for ASDK).

      部署基础知识-创建包含复制的 MySQL

  5. 在 " 环境配置 " 页上,提供以下信息,然后选择 "确定"On the Environment Configuration page, provide the following information and then select OK:

    • 用于安全 shell (SSH) 身份验证的密码或 SSH 公钥。Password or SSH public key to use for secure shell (SSH) authentication. 如果使用密码,则它必须包含字母、数字,并且 可以 包含特殊字符。If using a password, it must contain letters, numbers, and can contain special characters.

    • VM 大小 (默认值为标准 D1 v2 Vm) 。VM size (default is Standard D1 v2 VMs).

    • 数据磁盘大小(GB)Data disk size in GB

      环境配置-创建包含复制的 MySQL

  6. 查看部署 摘要Review the deployment Summary. 还可以选择下载自定义模板和参数,然后选择 "确定"Optionally, you can download the customized template and parameters and then select OK.

    摘要-创建包含复制的 MySQL

  7. 在 "购买" 页上选择 "创建" 以开始部署。Select Create on the Buy page to start the deployment.

    购买页面-创建包含复制的 MySQL

    备注

    部署需要大约一小时。The deployment will take about an hour. 在继续之前,请确保已完成部署并且已完全配置 MySQL 群集。Ensure that the deployment has finished and the MySQL cluster has been completely configured before continuing.

  8. 所有部署都成功完成后,查看资源组项,并选择 " mysqlip " 公共 IP 地址项。After all deployments have completed successfully, review the resource group items and select the mysqlip Public IP address item. 记录群集的公共 ip 地址和公共 IP 的完全 FQDN。Record the public IP address and full FQDN of the public IP for the cluster.

    需要为 Azure Stack 中心操作员提供此 IP 地址,以便他们可以利用此 MySQL 群集创建 MySQL 宿主服务器。You'll need to provide this IP address to an Azure Stack Hub operator so they can create a MySQL hosting server leveraging this MySQL cluster.

创建网络安全组规则Create a network security group rule

默认情况下,不会为 MySQL 配置到主机 VM 的公共访问权限。By default, no public access is configured for MySQL into the host VM. 要使 Azure Stack Hub MySQL 资源提供程序连接和管理 MySQL 群集,需要创建一个 (NSG) 规则的入站网络安全组。For the Azure Stack Hub MySQL resource provider to connect and manage the MySQL cluster, an inbound network security group (NSG) rule needs to be created.

  1. 在管理员门户中,切换到部署 MySQL 群集时创建的资源组,并选择 " (默认子网-sg) 的网络安全组:In the administrator portal, go to the resource group created when deploying the MySQL cluster and select the network security group (default-subnet-sg):

    在 Azure Stack Hub 管理员门户中选择网络安全组

  2. 选择“入站安全规则”,并选择“添加”**** ****。Select Inbound security rules and then select Add.

    在“目标端口范围”中输入“3306”,并在“名称”和“说明”字段中提供说明**** **** **** ****。Enter 3306 in the Destination port range and optionally provide a description in the Name and Description fields.

    开门

  3. 选择“添加”以关闭“入站安全规则”对话框****。Select Add to close the inbound security rule dialog.

配置对 MySQL 群集的外部访问Configure external access to the MySQL cluster

必须先启用外部访问,然后才能将 MySQL 群集添加为 Azure Stack Hub MySQL Server 主机。Before the MySQL cluster can be added as an Azure Stack Hub MySQL Server host, external access must be enabled.

  1. 使用 SSH 客户端 (此示例使用 PuTTY) 从可以访问公共 IP 的计算机登录到主 MySQL 计算机。Using an SSH client (this example uses PuTTY) log in to the primary MySQL machine from a computer that can access the public IP. 主要 MySQL VM 名称通常以 0 结尾,并分配有一个公共 IP。The primary MySQL VM name usually ends with 0 and has a public IP assigned to it.

    使用公共 IP,并使用 bitnami 的用户名和之前创建的应用程序密码(不包含特殊字符)登录到 VM。Use the public IP and log in to the VM with the username of bitnami and the application password you created earlier without special characters.

    LinuxLogin

  2. 在 SSH 客户端窗口中,使用以下命令确保 bitnami 服务处于活动状态且正在运行。In the SSH client window, use the following command to ensure the bitnami service is active and running. 出现提示时,再次提供 bitnami 密码:Provide the bitnami password again when prompted:

    sudo service bitnami status

    检查 bitnami 服务

  3. 创建 Azure Stack 中心 MySQL 宿主服务器用来连接 MySQL 的远程访问用户帐户,然后退出 SSH 客户端。Create a remote access user account to be used by the Azure Stack Hub MySQL Hosting Server to connect to MySQL and then exit the SSH client.

    运行以下命令,使用前面创建的根密码以 root 身份登录 MySQL。Run the following commands to log in to MySQL as root, using the root password created earlier. 创建一个新的管理员用户,并根据环境需要替换 <username> 和 <password>** **。Create a new admin user and replace <username> and <password> as required for your environment. 在此示例中,创建的用户名为 sqlsa,并使用强密码:In this example, the created user is named sqlsa and a strong password is used:

    mysql -u root -p
    create user <username>@'%' identified by '<password>';
    grant all privileges on *.* to <username>@'%' with grant option;
    flush privileges;
    

    创建管理员用户

  4. 记录新的 MySQL 用户信息。Record the new MySQL user information.

    需要将此用户名和密码以及群集公共 IP 的公共 ip 地址或完整 FQDN 提供给 Azure Stack 中心操作员,以便他们可以使用此 MySQL 群集创建 MySQL 宿主服务器。You'll need to provide this username and password, along with the public IP address or full FQDN of the public IP for the cluster, to an Azure Stack Hub operator so they can create a MySQL hosting server using this MySQL cluster.

配置 Azure Stack 中心 MySQL 宿主服务器Configure an Azure Stack Hub MySQL Hosting Server

创建并正确配置 MySQL Server 群集后,Azure Stack 中心操作员必须将其添加为 Azure Stack 中心 MySQL 宿主服务器。After the MySQL Server cluster is created and properly configured, an Azure Stack Hub operator must add it as an Azure Stack Hub MySQL Hosting Server.

mysqlip) (创建 mysql 群集的资源组时,请确保为之前记录的 mysql 群集主 VM 公共 ip 使用公共 ip 或完全 FQDN。Be sure to use the public IP or full FQDN for the public IP of the MySQL cluster primary VM recorded previously when the MySQL cluster's resource group was created (mysqlip). 此外,操作员需要知道创建的 MySQL Server 身份验证凭据以远程访问 MySQL 群集数据库。In addition, the operator needs to know the MySQL Server authentication credentials you created to remotely access the MySQL cluster database.

备注

此步骤必须由 Azure Stack Hub 操作员从 Azure Stack Hub 管理员门户运行。This step must be run from the Azure Stack Hub administrator portal by an Azure Stack Hub operator.

使用 MySQL 群集的公共 IP 和 MySQL 身份验证登录信息,Azure Stack 中心操作员现在可以 使用新的 mysql 群集创建 MySQL 宿主服务器Using the MySQL cluster's Public IP and MySQL authentication login information, an Azure Stack Hub operator can now create a MySQL Hosting Server using the new MySQL cluster.

此外,请确保已创建计划和产品/服务,以便用户可以创建 MySQL 数据库。Also ensure that you've created plans and offers to make MySQL database creation available for users. 操作员需要将 mysqladapter.dbadapter 服务添加到计划并为高度可用的数据库创建新的配额。An operator will need to add the Microsoft.MySqlAdapter service to a plan and create a new quota specifically for highly available databases. 有关创建计划的详细信息,请参阅服务、计划、套餐和订阅概述For more information about creating plans, see Service, plan, offer, subscription overview.

提示

部署 MySQL Server 资源提供程序之前,不能向计划中添加mysqladapter.dbadapter服务。The Microsoft.MySqlAdapter service won't be available to add to plans until the MySQL Server resource provider has been deployed.

创建高度可用的 MySQL 数据库Create a highly available MySQL database

创建并配置 MySQL 群集并将其作为 Azure Stack 中心 MySQL 宿主服务器添加到 Azure Stack 中心操作员后,具有订阅的租户用户(包括 MySQL Server 数据库功能)可以按照本部分中的步骤创建高度可用的 MySQL 数据库。After the MySQL cluster is created and configured, and added as an Azure Stack Hub MySQL Hosting Server by an Azure Stack Hub operator, a tenant user with a subscription including MySQL Server database capabilities can create highly available MySQL databases by following the steps in this section.

备注

在 Azure Stack 中心用户门户中以租户用户的身份运行这些步骤,其中包含) 提供 MySQL 服务器 (功能的订阅。Run these steps from the Azure Stack Hub user portal as a tenant user with a subscription providing MySQL Server capabilities (Microsoft.MySQLAdapter service).

  1. 登录到用户门户:Sign in to the user portal:

    • 对于集成系统部署,门户地址将根据解决方案的区域和外部域名而有所不同。For an integrated system deployment, the portal address will vary based on your solution's region and external domain name. 它将采用 https://portal.<region>.<FQDN> 格式。It will be in the format of https://portal.<region>.<FQDN>.
    • 对于 Azure Stack 开发工具包 (ASDK),门户地址为 https://portal.local.azurestack.externalFor the Azure Stack Development Kit (ASDK), the portal address is https://portal.local.azurestack.external.
  2. + 依次选择 "创建资源 > " "数据 + 存储" 和 " MySQL 数据库"。Select + Create a resource > Data + Storage, and then MySQL Database.

    提供所需的数据库属性信息,包括名称、排序规则、要使用的订阅以及要用于部署的位置。Provide the required database property information including name, collation, the subscription to use, and location to use for the deployment.

    在 Azure Stack Hub 用户门户中创建 MySQL 数据库

  3. 选择 " SKU ",然后选择要使用的相应 MySQL 宿主服务器 SKU。Select SKU and then choose the appropriate MySQL Hosting Server SKU to use. 在此示例中,Azure Stack 中心操作员创建了 mysql-HA SKU,以支持 MySQL 群集数据库的高可用性。In this example, the Azure Stack Hub operator has created the MySQL-HA SKU to support high availability for MySQL cluster databases.

    在 Azure Stack Hub 用户门户中选择 SKU

  4. 选择 "登录" " > 创建新的登录名",然后提供要用于新数据库的 MySQL 身份验证凭据。Select Login > Create a new login and then provide the MySQL authentication credentials to be used for the new database. 完成后,选择“确定”****,然后选择“创建”**** 以开始数据库部署过程。When finished, select OK and then Create to begin the database deployment process.

    在 Azure Stack Hub 用户门户中添加登录名

  5. MySQL 数据库部署成功完成后,请查看数据库属性,以发现用于连接到新的高可用性数据库的连接字符串。When the MySQL database deployment completes successfully, review the database properties to discover the connection string to use for connecting to the new highly available database.

    在 Azure Stack Hub 用户门户中查看连接字符串

后续步骤Next steps

更新 MySQL 资源提供程序Update the MySQL resource provider