在 Azure Stack Hub 中部署用于托管 Web 应用的 Linux VMDeploy a Linux VM to host a web app in Azure Stack Hub

可以使用 Azure 市场中的 Ubunutu 映像创建和部署基本 Linux 虚拟机 (VM),以托管使用 Web 框架创建的 Web 应用。You can create and deploy a basic Linux virtual machine (VM) by using the Ubuntu image in the Azure Marketplace to host a web app that you've created with a web framework.

此 VM 可以托管使用以下语言编写的 Web 应用:This VM can host web apps by using:

  • Python:常见的 Python Web 框架包括 Flask、Bottle 和 Django。Python: Common Python web frameworks include Flask, Bottle, and Django.
  • Go:常见的 Go 框架包括 Revel、Martini、Gocraft/Web 和 Gorilla。Go: Common Go frameworks include Revel, Martini, Gocraft/web, and Gorilla.
  • Ruby:将 Ruby on Rails 设置为交付 Ruby Web 应用的框架。Ruby: Set up Ruby on Rails as a framework to deliver your Ruby web apps.
  • Java:使用 Java 开发要发布到 Apache Tomcat 服务器的 Web 应用。Java: Use Java to develop web apps that you post to an Apache Tomcat Server. 可将 Tomcat 安装在 Linux 上,然后将 Java WAR 文件直接部署到服务器。You can install Tomcat on Linux and then deploy your Java WAR files directly to the server.

根据本文中的说明,通过任何 Web 应用、框架和使用 Linux OS 的后端技术来启动并运行。Use the instructions in this article to get up and running with any web app, framework, and back-end technology that uses the Linux OS. 然后可以使用 Azure Stack Hub 来管理基础结构,并使用技术内部的管理工具来处理应用的维护任务。You can then use Azure Stack Hub to manage your infrastructure and use the management tools within your technology to handle maintenance tasks for your app.

部署适用于 Web 应用的 Linux VMDeploy a Linux VM for a web app

在此过程中,你将创建机密密钥,使用 Linux VM 的基础映像,指定 VM 的特定属性,然后创建 VM。In this process, you create a secret key, use the base image of the Linux VM, specify the particular attributes of the VM, and then create the VM. 创建 VM 后,打开运行该 VM 所需的端口,并在该 VM 上托管你的应用。After you create the VM, you open the ports that are necessary for working with the VM and for the VM to host your app. 接下来,创建 DNS 名称。Next, you create the DNS name. 最后,连接到该 VM 并使用 apt-get 实用工具更新计算机。Finally, you connect to the VM and update the machine by using the apt-get utility. 完成此过程后,Azure Stack Hub 实例中已有一个准备好托管 Web 应用的 VM。After you've completed the process, you'll have a VM in your Azure Stack Hub instance that's ready to host your web app.

在开始之前,请确保一切已准备就绪。Before you begin, make sure that you have everything you need in place.

先决条件Prerequisites

  • 一个有权访问 Ubuntu Server 16.04 LTS 映像的 Azure Stack Hub 订阅。An Azure Stack Hub subscription, with access to the Ubuntu Server 16.04 LTS image. 可以使用更高版本的映像,但请注意,本文中的说明是根据 16.04 LTS 编写的。You can use a later version of the image, but these instructions are written with the 16.04 LTS in mind. 如果没有此映像,请联系云运营商,以将映像放入 Azure Stack Hub 市场。If you don't have this image, contact your cloud operator to get the image into the Azure Stack Hub Marketplace.

使用门户部署 VMDeploy the VM by using the portal

若要部署 VM,请遵循后续几个部分中的说明操作。To deploy the VM, follow the instructions in the next several sections.

创建 VMCreate your VM

  1. 为服务器创建安全外壳 (SSH) 公钥。Create a Secure Shell (SSH) public key for your server. 有关详细信息,请参阅如何使用 SSH 公钥For more information, see How to use an SSH public key.

  2. 在 Azure Stack Hub 门户中,选择“创建资源” > “计算” > “Ubuntu Server 16.04 LTS”。 In the Azure Stack Hub portal, select Create a resource > Compute > Ubuntu Server 16.04 LTS.

    将 Web 应用部署到 Azure Stack Hub VM

  3. 在“创建虚拟机”窗格中,对于“1. 配置基本设置”:In the Create a virtual machine pane, for 1. Configure basic settings:

    a.a. 输入 VM 的名称Enter the Name of your VM.

    b.b. 选择“高级 SSD”(适用于高级磁盘 [SSD])或“标准 HDD”(适用于标准磁盘 [HDD])作为“VM 磁盘类型”。 Select the VM disk type, either Premium SSD (for Premium disks [SSD]) or Standard HDD (for Standard disks [HDD]).

    c.c. 输入你的 用户名Enter your Username.

    d.d. 选择“SSH 公钥”作为“身份验证类型”。 Select the Authentication type as SSH Public key.

    e.e. 检索创建的 SSH 公钥。Retrieve the SSH public key that you created. 在文本编辑器中打开此公钥,复制密钥并将其贴到“SSH 公钥”框中。 Open it in a text editor, copy the key, and then paste it into the SSH public key box. 包含从 ---- BEGIN SSH2 PUBLIC KEY -------- END SSH2 PUBLIC KEY ---- 的文本。Include the text from ---- BEGIN SSH2 PUBLIC KEY ---- to ---- END SSH2 PUBLIC KEY ----. 将整个文本块贴到密钥框中:Paste the entire block of text into the key box:

    ---- BEGIN SSH2 PUBLIC KEY ----
    Comment: "rsa-key-20190207"
    <Your key block>
    ---- END SSH2 PUBLIC KEY ----
    

    f.f. 选择 Azure Stack Hub 实例的订阅。Select the subscription for your Azure Stack Hub instance.

    g.g. 根据要为应用组织资源的方式,创建新的资源组或使用现有的资源组。Create a new resource group or use an existing one, depending on how you want to organize the resources for your app.

    h.如果该值不存在,请单击“添加行”。h. 选择你的位置。Select your location. Azure Stack 开发工具包 (ASDK) 通常位于本地区域。 The Azure Stack Development Kit (ASDK) is usually in a local region. 具体的位置取决于 Azure Stack Hub 实例。The location depends on your Azure Stack Hub instance.

  4. 对于“2. 大小”,请键入:For 2. Size, type:

    • 针对可在 Azure Stack Hub 实例中使用的 VM,选择数据大小和 RAM。Select the size of data and RAM for your VM that's available in your Azure Stack Hub instance.
    • 可以浏览列表,或根据“计算类型”、“CPU”和“存储空间”筛选 VM 的大小。 You can either browse the list or filter for the size of your VM by Compute type, CPUs, and Storage space.

    备注

    • 显示的价格是以当地货币计价的估算值。The prices presented are estimates in your local currency. 它们仅包含 Azure 基础结构费用以及订阅和位置的所有折扣。They include only Azure infrastructure costs and any discounts for the subscription and location. 这些价格不包括任何适用的软件费用。They don't include any applicable software costs.
    • 建议的大小基于硬件和软件要求,由所选映像的发布者确定。The recommended sizes are determined by the publisher of the selected image and are based on hardware and software requirements.
    • 使用标准磁盘 (HDD) 而不是高级磁盘 (SSD) 可能会影响操作系统性能。Using Standard disks (HDD) rather than Premium disks (SSD) might affect operating system performance.
  5. 在“3. 配置可选功能”中,键入:In 3. Configure optional features, type:

    a.a. 对于“高可用性”,请选择一个可用性集。 For High availability, select an availability set. 若要为应用程序提供冗余,请将两个或更多个虚拟机组合到一个可用性集中。To provide redundancy to your application, group two or more virtual machines in an availability set. 这种配置可以确保在发生计划内或计划外维护事件时,至少有一个虚拟机可用,并满足 99.95% 的 Azure 服务级别协议 (SLA) 要求。This configuration ensures that during a planned or unplanned maintenance event, at least one virtual machine will be available and meet the 99.95% Azure service-level agreement (SLA). 创建虚拟机后无法更改虚拟机的可用性集。The availability set of a virtual machine can't be changed after it's created.

    b.b. 对于“存储”,请选择“高级磁盘(SSD)”或“标准磁盘(HDD)”。 For Storage, select Premium disks (SSD) or Standard disks (HDD). 高级磁盘 (SSD) 基于固态硬盘,提供一致的低延迟性能。Premium disks (SSD) are backed by solid-state drives and offer consistent, low-latency performance. 高级磁盘可在价格与性能之间实现最佳平衡,非常适合用于 I/O 密集型应用程序和生产工作负荷。They provide the best balance between price and performance and are ideal for I/O-intensive applications and production workloads. 标准磁盘基于磁驱动器,适用于不经常访问数据的应用程序。Standard disks are backed by magnetic drives and are preferable for applications where data is accessed infrequently.

    c.c. 选择“使用托管磁盘”。 Select Use managed disks. 启用此功能时,Azure 会自动管理磁盘的可用性。When you enable this feature, Azure automatically manages the availability of disks. 你可以受益于数据冗余和容错能力,而无需自行创建和管理存储帐户。You benefit from data redundancy and fault tolerance, without having to create and manage storage accounts on your own. 托管磁盘并非在所有区域中均可用。Managed disks might not be available in all regions. 有关详细信息,请参阅 Azure 托管磁盘简介For more information, see Introduction to Azure managed disks.

    d.d. 若要配置网络,请选择“虚拟网络”。 To configure your network, select virtual network. 虚拟网络以逻辑方式在 Azure 中相互隔离。Virtual networks are logically isolated from each other in Azure. 虚拟网络与数据中心内的传统网络非常类似,可以配置其 IP 地址范围、子网、路由表、网关和安全设置。You can configure their IP address ranges, subnets, route tables, gateways, and security settings, much like a traditional network in your datacenter. 默认情况下,同一虚拟网络中的虚拟机可以相互访问。Virtual machines in the same virtual network can access each other by default.

    e.e. 若要配置子网,请选择“子网”。 To configure your subnet, select subnet. 子网是虚拟网络中某个范围内的 IP 地址。A subnet is a range of IP addresses in your virtual network. 可以使用子网来相互隔离虚拟机,或者将虚拟机与 Internet 相隔离。You can use a subnet to isolate virtual machines from each other or from the internet.

    f.f. 若要配置对 VM 或 VM 上运行的服务的访问,请选择“公共 IP 地址”。 To configure access to your VM or to services running on your VM, select Public IP address. 使用公共 IP 地址可与虚拟网络外部的虚拟机通信。Use a public IP address to communicate with the virtual machine from outside the virtual network.

    g.g. 选择“基本”或“高级”网络安全组Select Network Security Group, Basic, or Advanced. 设置允许或拒绝发往 VM 的网络流量的规则。Set rules that allow or deny network traffic to the VM.

    h.如果该值不存在,请单击“添加行”。h. 若要设置使用常用或自定义协议对 VM 设置的访问,请选择“公共入站端口”。 To set access for common or custom protocols to your VM, select public inbound ports. 该服务会指定此规则的目标协议和端口范围。The service specifies the destination protocol and port range for this rule. 可以选择预先定义的服务(例如远程桌面协议 (RDP) 或 SSH),或提供自定义端口范围。You can choose a predefined service, such as Remote Desktop Protocol (RDP) or SSH, or provide a custom port range. 对于 Web 服务器,请使用打开的 HTTP (80)、HTTPS (443) 和 SSH (22)。For the web server, use HTTP (80), HTTPS (443), and SSH (22) open. 如果你打算使用 RDP 连接来管理计算机,请打开端口 3389。If you plan to manage the machine by using an RDP connection, open port 3389.

    i.i. 若要将扩展添加到 VM,请选择“扩展”。 To add extensions to your VM, select Extensions. 扩展可为虚拟机添加新功能,例如配置管理或防病毒保护。Extensions add new features, such as configuration management or antivirus protection, to your virtual machine.

    j.j. 禁用或启用“监视”。 Disable or enable Monitoring. 若要帮助诊断启动问题,可以使用监视功能来捕获串行控制台输出,以及主机上运行的虚拟机的屏幕截图。To help diagnose startup issues, you can use monitoring to capture the serial console output and screenshots of a virtual machine that's running on a host.

    k.k. 若要指定用于保存指标的存储帐户,请选择“诊断存储帐户”。 To specify the storage account that holds your metrics, select diagnostics storage account. 指标将写入存储帐户,你可以使用自己的工具对其进行分析。Metrics are written to a storage account so that you can analyze them with your own tools.

    l.l. 选择“确定” 。Select OK.

  6. 复查“4. 摘要”:Review 4. Summary:

    • 门户将验证你的设置。The portal validates your settings.
    • 若要将设置重复用于 Azure 资源管理器工作流,可以下载适用于你的 VM 的 Azure 资源管理器模板。To reuse your settings with an Azure Resource Manager workflow, you can download the Azure Resource Manager template for your VM.
    • 通过验证后,选择“确定”。 When the validation has passed, select OK. VM 部署需要花费几分钟时间。VM deployment takes several minutes.

指定打开的端口和 DNS 名称Specify the open ports and DNS name

若要使网络中的用户能够访问你的 Web 应用,请打开用于连接到计算机的端口,并添加可让用户在其 Web 浏览器中使用的 DNS 友好名称(例如 mywebapp.local.cloudapp.azurestack.external)。To make your web app accessible to users on your network, open the ports that are used to connect to the machine and add a friendly DNS name, such as mywebapp.local.cloudapp.azurestack.external, that users can use in their web browsers.

打开入站端口Open inbound ports

可以修改预定义服务(例如 RDP 或 SSH)的目标协议和端口范围,或提供自定义端口范围。You can modify the destination protocol and port range for a predefined service, such as RDP or SSH, or provide a custom port range. 例如,你可能想要使用 Web 框架的端口范围。For example, you might want to work with the port range of your web framework. GO,例如在端口 3000 上通信。GO, for example, communicates on port 3000.

  1. 打开租户的 Azure Stack Hub 门户。Open the Azure Stack Hub portal for your tenant.

  2. 搜索你的 VM。Search for your VM. 你可能已将 VM 固定到仪表板;或者,可以在“搜索资源”框中搜索该 VM。 You might have pinned the VM to your dashboard, or you can search for it in the Search resources box.

  3. 在 VM 窗格中选择“网络”。 Select Networking in your VM pane.

  4. 选择“添加入站端口”规则以打开一个端口。 Select Add inbound port rule to open a port.

  5. 对于“源”,请保留默认选项“任何”。 For Source, leave the default selection, Any.

  6. 对于“源端口范围”,请保留通配符 (*)。 For Source port range, leave the wildcard (*).

  7. 对于“目标端口范围”,请输入要打开的端口,例如 3000For Destination port range, enter the port that you want to open, such as 3000.

  8. 对于“协议”,请保留默认选项“任何”。 For Protocol, leave the default selection, Any.

  9. 对于“操作”,请选择“允许”。 For Action, select Allow.

  10. 对于“优先级”,请保留默认选项。 For Priority, leave the default selection.

  11. 输入 名称说明,以帮助记住打开端口的原因。Enter a Name and Description to help you remember why the port is open.

  12. 选择“添加” 。Select Add.

添加服务器的 DNS 名称Add a DNS name for your server

此外,可以创建服务器的 DNS 名称,使用户能够使用 URL 连接到你的网站。In addition, you can create a DNS name for your server, so that users can connect to your website by using a URL.

  1. 打开租户的 Azure Stack Hub 门户。Open the Azure Stack Hub portal for your tenant.

  2. 搜索你的 VM。Search for your VM. 你可能已将 VM 固定到仪表板;或者,可以在“搜索资源”框中搜索该 VM。 You might have pinned the VM to your dashboard, or you can search for it in the Search resources box.

  3. 选择“概述”。 Select Overview.

  4. 在“VM”下选择“配置”。 Under VM, select Configure.

  5. 对于“分配”,请选择“动态”。 For Assignment, select Dynamic.

  6. 输入 DNS 名称标签(例如 mywebapp),因此,完整的 URL 将是 mywebapp.local.cloudapp.azurestack.external(适用于 ASDK 应用)。Enter the DNS name label, such as mywebapp, so that your full URL becomes mywebapp.local.cloudapp.azurestack.external (for an ASDK app).

通过 SSH 进行连接以更新 VMConnect via SSH to update your VM

  1. 在 Azure Stack Hub 实例所在的同一网络中打开 SSH 客户端。On the same network as your Azure Stack Hub instance, open your SSH client. 有关详细信息,请参阅使用 SSH 公钥For more information, see Use an SSH public key.

  2. 输入以下命令:Enter the following commands:

        sudo apt-get update
        sudo apt-get -y upgrade
    

后续步骤Next steps

了解如何在 Azure Stack Hub 中设置开发环境Learn how to Set up a development environment in Azure Stack Hub.