在 Azure Stack Hub 中添加 MySQL 宿主服务器Add MySQL hosting servers in Azure Stack Hub

可以在 Azure Stack Hub 中的虚拟机 (VM) 上或者在 Azure Stack Hub 环境外部的 VM 上托管 MySQL 宿主服务器实例,前提是 MySQL 资源提供程序能够连接到该实例。You can host a MySQL hosting server instance on a virtual machine (VM) in Azure Stack Hub, or on a VM outside your Azure Stack Hub environment, as long as the MySQL resource provider can connect to the instance.

备注

MySQL 资源提供程序应在默认提供程序订阅中创建,而 MySQL 宿主服务器则应在可计费用户订阅中创建。The MySQL resource provider should be created in the default provider subscription while MySQL hosting servers should be created in billable, user subscriptions. 资源提供程序服务器不应用于托管用户数据库。The resource provider server shouldn't be used to host user databases.

可以将 MySQL 版本 5.6、5.7 和 8.0 用于宿主服务器。MySQL versions 5.6, 5.7 and 8.0 may be used for your hosting servers. MySQL RP 不支持 caching_sha2_password 身份验证。The MySQL RP doesn't support caching_sha2_password authentication. 必须将 MySQL 8.0 服务器配置为使用 mysql_native_password。MySQL 8.0 servers must be configured to use mysql_native_password.

准备 MySQL 宿主服务器Prepare a MySQL hosting server

创建网络安全组规则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 server, an inbound network security group (NSG) rule needs to be created.

  1. 在管理员门户中,转到部署 MySQL 服务器时创建的资源组,并选择网络安全组 (default-subnet-sg)****:In the administrator portal, go to the resource group created when deploying the MySQL server 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 hosting server

必须先启用外部访问,然后才能将 MySQL 服务器添加为 Azure Stack Hub MySQL 服务器主机。Before the MySQL server can be added as an Azure Stack Hub MySQL Server host, external access must be enabled. 以 Azure Stack Hub 市场中提供的 Bitnami MySQL 为例,你可以采取以下步骤配置外部访问。Take Bitnami MySQL, which is available in Azure Stack Hub marketplace as an example, you can take the following steps to configure the external access.

  1. 使用 SSH 客户端(此示例使用 PuTTY)从可以访问公共 IP 的计算机登录 MySQL 服务器。Using an SSH client (this example uses PuTTY) log in to the MySQL server from a computer that can access the public IP.

    使用公共 IP 并使用你先前创建的用户名和应用程序密码(不带特殊字符)登录到 VM。Use the public IP and log in to the VM with the username 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. 如果 MySQL 宿主服务器是 8.0 或更高版本,则需要将身份验证方法更改为“mysql_native_password”****。If the MySQL hosting server is version 8.0 or above, you need to change the authentication method to mysql_native_password. 如果 MySQL 版本低于 8.0,则可以跳过此步骤。If the MySQL version is below 8.0, this step can be skipped.

    以 Bitnami MySQL 为例,配置文件位于“/opt/bitnami/mysql/conf/my.cnf”下****。Take Bitnami MySQL as example, the configuration file is under /opt/bitnami/mysql/conf/my.cnf. 将属性“default_authentication_plugin”设置为值“mysql_native_password”**** ****。Set the property default_authentication_plugin with value mysql_native_password.

    [mysqld]
    default_authentication_plugin=mysql_native_password
    

    重新启动 bitnami 服务并确保 bitnami 服务正常运行。Restart the bitnami service and make sure the bitnami service is running properly.

    sudo service bitnami restart
    sudo service bitnami status
    
  4. 创建一个远程访问用户帐户,供 Azure Stack Hub MySQL 宿主服务器用于连接到 MySQL。Create a remote access user account to be used by the Azure Stack Hub MySQL Hosting Server to connect to MySQL.

    运行以下命令以根用户身份登录 MySQL,使用记录在“~/bitnami_credentials”中的根密码**。Run the following commands to log in to MySQL as root, using the root password which is recorded in ~/bitnami_credentials. 创建一个新的管理员用户,并根据环境需要替换 <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;
    

    创建管理员用户

  5. 确保已创建的 sql 用户“sqlsa”的插件是“mysql_native_password”,然后退出 SSH 客户端**** ****。Make sure the plugin of the created sql user sqlsa is mysql_native_password and then exit the SSH client.

    SELECT user,host,plugin from mysql.user;
    
  6. 记录新的 MySQL 用户信息。Record the new MySQL user information.

    Azure Stack Hub 操作员使用此 MySQL 服务器创建 MySQL 宿主服务器时,将使用此用户名和密码。This username and password will be used while Azure Stack Hub operator creates a MySQL hosting server using this MySQL server.

连接到 MySQL 宿主服务器Connect to a MySQL hosting server

确保已准备好拥有管理特权的帐户的凭据。Make sure you have the credentials for an account with system admin privileges.

备注

对于 MySQL 8.0 及更高版本,默认情况下不启用远程访问。For MySQL 8.0 and above versions, the remote access isn't enabled by default. 需要创建新的用户帐户,并授予对此用户帐户的远程访问权限,然后才能将其添加为宿主服务器。You need to create a new user account and grant the previledge of remote access to this user account before adding it as a hosting server.

若要添加宿主服务器,请执行以下步骤:To add a hosting server, follow these steps:

  1. 以服务管理员身份登录到 Azure Stack Hub 管理员门户。Sign in to the Azure Stack Hub administrator portal as a service admin.

  2. 选择“所有服务”****。Select All services.

  3. 在“管理资源”**** 类别下,选择“MySQL 宿主服务器”**** > “+添加”****。Under the ADMINISTRATIVE RESOURCES category, select MySQL Hosting Servers > +Add. 此时会打开“添加 MySQL 宿主服务器”对话框,如以下屏幕捕获所示。****The Add a MySQL Hosting Server dialog will open, shown in the following screen capture.

    配置 MySQL 宿主服务器

  4. 提供 MySQL 服务器实例的连接详细信息。Provide the connection details of your MySQL Server instance.

    • 对于“MySQL 宿主服务器名称”,**** 请提供完全限定域名 (FQDN) 或有效的 IPv4 地址。For MySQL Hosting Server Name, provide the fully qualified domain name (FQDN) or a valid IPv4 address. 请勿使用短 VM 名称。Don't use the short VM name.
    • Azure Stack Hub 市场中提供的 Bitnami MySQL 映像的默认管理员用户名rootThe default admin Username for the Bitnami MySQL images available in Azure Stack Hub Marketplace is root.
    • 如果不知道 root 的密码,请参阅 Bitnami 文档,了解如何获取它。If you don't know the root Password, see the Bitnami documentation to learn how to get it.
    • 未提供默认的 MySQL 实例,因此需指定“宿主服务器的大小(GB)”。****A default MySQL instance isn't provided, so you have to specify the Size of Hosting Server in GB. 输入接近数据库服务器容量的大小。Enter a size that's close to the capacity of the database server.
    • 保留“订阅”的默认设置。****Keep the default setting for Subscription.
    • 对于“资源组”****,请创建新组或使用现有组。For Resource group, create a new one, or use an existing group.

    备注

    如果租户和管理 Azure 资源管理器可以访问 MySQL 实例,则可让资源提供程序控制此实例。If the MySQL instance can be accessed by the tenant and the admin Azure Resource Manager, you can put it under the control of the resource provider. 但是,必须专门将 SQL 实例分配给资源提供程序。But, the MySQL instance must be allocated exclusively to the resource provider.

  5. 选择“SKU”,打开“创建 SKU”对话框。**** ****Select SKUs to open the Create SKU dialog.

    创建 MySQL SKU

    SKU 名称应反映 SKU 的属性,这样用户就能将其数据库部署到适当的 SKU。The SKU Name should reflect the properties of the SKU so users can deploy their databases to the appropriate SKU.

  6. 选择“确定”**** 以创建 SKU。Select OK to create the SKU.

    备注

    SKU 最长可能需要在一小时后才显示在门户中。SKUs can take up to an hour to be visible in the portal. 在部署并运行 SKU 之前,无法创建数据库。You can't create a database until the SKU is deployed and running.

  7. 在“添加 MySQL 宿主服务器”下,选择“创建”。**** ****Under Add a MySQL Hosting Server, select Create.

添加服务器时,请将它们分配给新的或现有的 SKU,以区分服务套餐。As you add servers, assign them to a new or existing SKU to differentiate service offerings. 例如,可以通过一个 MySQL 企业实例来提供增加的数据库和自动备份。For example, you can have a MySQL enterprise instance that provides increased database and automatic backups. 可以将此高性能服务器保留给组织中的不同部门。You can reserve this high-performance server for different departments in your organization.

MySQL 安全注意事项Security considerations for MySQL

以下信息适用于 RP 和 MySQL 宿主服务器:The following information applies to the RP and MySQL hosting servers:

提高后端数据库容量Increase backend database capacity

可以在 Azure Stack Hub 门户中部署更多的 MySQL 服务器,以便提高后端数据库容量。You can increase backend database capacity by deploying more MySQL servers in the Azure Stack Hub portal. 将这些服务器添加到新的或现有的 SKU。Add these servers to a new or existing SKU. 如果向现有的 SKU 添加服务器,请确保该服务器的特征与 SKU 中其他服务器的特征相同。If you add a server to an existing SKU, make sure the server characteristics are the same as the other servers in the SKU.

SKU 说明SKU notes

使用可以描述 SKU 中服务器容量(例如容量和性能)的 SKU 名称。Use a SKU name that describes the capabilities of the servers in the SKU, such as capacity and performance. 名称可以协助用户将其数据库部署到相应的 SKU。The name serves as an aid to help users deploy their databases to the appropriate SKU. 例如,可以使用 SKU 名称通过以下特征来区分服务产品/服务:For example, you can use SKU names to differentiate service offerings by the following characteristics:

  • 高容量high capacity
  • 高性能high performance
  • 高可用性high availability

最佳做法是使 SKU 中的所有宿主服务器具有相同的资源和性能特征。As a best practice, all the hosting servers in a SKU should have the same resource and performance characteristics.

无法将 SKU 分配到特定的用户或组。SKUs can't be assigned to specific users or groups.

若要编辑某个 SKU,请转到“所有服务” > “MySQL 适配器” > “SKU”。**** **** ****To edit a SKU, go to All services > MySQL Adapter > SKUs. 选择要修改的 SKU,进行任何必要的更改,然后单击“保存”**** 以保存更改。Select the SKU to modify, make any necessary changes, and click Save to save changes.

若要删除不再需要的 SKU,请转到“所有服务” > “MySQL 适配器” > “SKU”。**** **** ****To delete a SKU that's no longer needed, go to All services > MySQL Adapter > SKUs. 右键单击 SKU 名称,然后选择“删除”**** 将其删除。Right-click the SKU name and select Delete to delete it.

重要

可能需要长达一小时的时间新的 SKU 才会在用户门户中可用。It can take up to an hour for new SKUs to be available in the user portal.

将 MySQL 数据库服务器提供给用户使用Make MySQL database servers available to your users

创建计划和套餐,使用户能够使用 MySQL 数据库服务器。Create plans and offers to make MySQL database servers available to users. 将 Microsoft.MySqlAdapter 服务添加到计划,并创建新配额。Add the Microsoft.MySqlAdapter service to the plan and create a new quota. MySQL 不允许限制数据库的大小。MySQL doesn't allow limiting the size of databases.

重要

在用户门户中出现可用的新配额或者强制实施更改的配额可能需要长达两小时的时间。It can take up to two hours for new quotas to be available in the user portal or before a changed quota is enforced.

后续步骤Next steps

创建 MySQL 数据库Create a MySQL database