Azure 虚拟机中的 SQL Server 的应用程序模式和开发策略Application Patterns and Development Strategies for SQL Server in Azure Virtual Machines

Note

Azure 具有用于创建和处理资源的两个不同的部署模型:资源管理器部署模型和经典部署模型Azure has two different deployment models for creating and working with resources: Resource Manager and classic. 这篇文章介绍了如何使用这两种模型,但 Azure 建议大多数最新部署使用 Resource Manager 模型。This article covers using both models, but Azure recommends that most new deployments use the Resource Manager model.

摘要:Summary:

确定要将哪些应用程序模式用于 Azure 环境中基于 SQL Server 的应用程序是一个重要设计决策,要求用户深入了解 SQL Server 和每个 Azure 基础结构组件的协同工作方式。Determining which application pattern or patterns to use for your SQL-Server-based applications in Azure environment is an important design decision and it requires a solid understanding of how SQL Server and each infrastructure component of Azure work together. 使用 Azure 基础结构服务中的 SQL Server,可以轻松地将基于 Windows Server 构建的现有 SQL Server 应用程序迁移到 Azure 中的虚拟机,并且进行维护和监视。With SQL Server in Azure Infrastructure Services, you can easily migrate, maintain, and monitor your existing SQL Server applications built-on Windows Server to virtual machines in Azure.

本文旨在为解决方案架构师和开发者构建良好的应用程序体系结构和进行设计奠定基础,在将现有应用程序迁移到 Azure 和开发 Azure 中的新应用程序时,他们可以遵循其中的模式。The goal of this article is to provide solution architects and developers a foundation for good application architecture and design, which they can follow when migrating existing applications to Azure as well as developing new applications in Azure.

对于每种应用程序模式,都将找到本地方案及其相应的云解决方案,还可以找到相关的技术建议。For each application pattern, you will find an on-premises scenario, its respective cloud-enabled solution, and the related technical recommendations. 此外,本文还讨论了 Azure 特定开发策略,方便用户正确设计应用程序。In addition, the article discusses Azure-specific development strategies so that you can design your applications correctly. 由于各种应用程序模式千变万化,建议架构师和开发人员为其应用程序和用户选择最合适的模式。Due to the many possible application patterns, it's recommended that architects and developers should choose the most appropriate pattern for their applications and users.

技术供稿人: Luis Carlos Vargas Herring、Madhan Arumugam RamakrishnanTechnical Contributors: Luis Carlos Vargas Herring, Madhan Arumugam Ramakrishnan

技术审校: Corey Sanders、Drew McDaniel、Narayan Annamalai、Nir Mashkowski、Sanjay Mishra、Silvano Coriani、Stefan Schackow、Tim Hickey、Tim Wieman、Xin JinTechnical Reviewers: Corey Sanders, Drew McDaniel, Narayan Annamalai, Nir Mashkowski, Sanjay Mishra, Silvano Coriani, Stefan Schackow, Tim Hickey, Tim Wieman, Xin Jin

简介Introduction

可以通过将不同应用程序层级的组件放入不同计算机以及不同的组件中,开发多种类型的 n 层应用程序。You can develop many types of n-tier applications by separating the components of the different application layers on different machines as well as in separate components. 例如,可将客户端应用程序和业务规则组件放置在一台计算机中,而将前端 Web 层和数据访问层组件放置在另一台计算机中,再将后端数据库层放置在另一台计算机中。For example, you can place the client application and business rules components in one machine, front-end web tier and data access tier components in another machine, and a back-end database tier in another machine. 这种类型的结构有助于将每个层相互隔离。This kind of structuring helps isolate each tier from each other. 如果更改了数据来源,则无需更改客户端或 Web 应用程序,而只需更改数据访问层组件。If you change where data comes from, you don't need to change the client or web application but only the data access tier components.

典型的 n 层 应用程序包括表示层、业务层和数据层:A typical n-tier application includes the presentation tier, the business tier, and the data tier:

Tier 说明Description
呈现Presentation 呈现层(Web 层、前端层)是用户与应用程序进行交互的层。The presentation tier (web tier, front-end tier) is the layer in which users interact with an application.
业务Business 业务层(中间层)是呈现层和数据层用来相互通信的层,包括了系统的核心功能。The business tier (middle tier) is the layer that the presentation tier and the data tier use to communicate with each other and includes the core functionality of the system.
数据Data 数据层是存储应用程序数据的服务器(例如运行 SQL Server 的服务器)。The data tier is basically the server that stores an application's data (for example, a server running SQL Server).

应用程序层级描述应用程序中的功能和组件的逻辑分组;而层则描述独立物理服务器、计算机、网络或远程地点的功能和组件的物理分布。Application layers describe the logical groupings of the functionality and components in an application; whereas tiers describe the physical distribution of the functionality and components on separate physical servers, computers, networks, or remote locations. 应用程序的多个层级可能位于同一台物理计算机上(同一层),也可能分布在多台单独计算机上(n 层),每个层级中的组件通过明确定义的接口,与其他层级中的组件进行通信。The layers of an application may reside on the same physical computer (the same tier) or may be distributed over separate computers (n-tier), and the components in each layer communicate with components in other layers through well-defined interfaces. 可将“层”这个词视为物理分布模式,例如两层、三层和 n 层。You can think of the term tier as referring to physical distribution patterns such as two-tier, three-tier, and n-tier. 2 层应用程序模式 包含两个应用程序层:应用程序服务器和数据库服务器。A 2-tier application pattern contains two application tiers: application server and database server. 直接通信发生在应用程序服务器和数据库服务器之间。The direct communication happens between the application server and the database server. 应用程序服务器包含 Web 层和业务层组件。The application server contains both web-tier and business-tier components. 3 层应用程序模式中,有三个应用程序层:Web 服务器、应用程序服务器(包含业务逻辑层和/或业务层数据访问组件)、数据库服务器。In 3-tier application pattern, there are three application tiers: web server, application server, which contains the business logic tier and/or business tier data access components, and the database server. Web 服务器和数据库服务器之间的通信在应用程序服务器上进行。The communication between the web server and the database server happens over the application server. 有关应用层和层级的详细信息,请参阅 Microsoft 应用程序体系结构指南For detailed information on application layers and tiers, see Microsoft Application Architecture Guide.

开始阅读本文之前,应该掌握有关 SQL Server 和 Azure 的基本概念知识。Before you start reading this article, you should have knowledge on the fundamental concepts of SQL Server and Azure. 有关信息,请参阅 SQL Server 联机丛书Azure 虚拟机中的 SQL ServerAzure.cnFor information, see SQL Server Books Online, SQL Server in Azure Virtual Machines and Azure.cn.

本文介绍了几种应用程序模式,它们可能适合简单应用程序,也可能适合非常复杂的企业应用程序。This article describes several application patterns that can be suitable for your simple applications as well as the highly complex enterprise applications. 在详细介绍每种模式前,建议熟悉 Azure 中的可用数据存储服务,例如 Azure 存储Azure SQL 数据库Azure 虚拟机中的 SQL ServerBefore detailing each pattern, we recommend that you should familiarize yourself with the available data storage services in Azure, such as Azure Storage, Azure SQL Database, and SQL Server in an Azure Virtual Machine. 要为应用程序做出最好的设计决策,必须明确了解何时使用何种数据存储服务。To make the best design decisions for your applications, understand when to use which data storage service clearly.

在以下情况下,应选择 Azure 虚拟机中的 SQL Server:Choose SQL Server in an Azure Virtual Machine, when:

  • 需要在 SQL Server 和 Winodws 上进行控制。You need control on SQL Server and Windows. 例如,想要控制 SQL Server 版本、特殊修补程序、性能配置等。For example, this might include the SQL Server version, special hotfixes, performance configuration, etc.

  • 需要与本地 SQL Server 完全兼容,并希望将现有应用程序按现状迁移至 Azure。You need a full compatibility with SQL Server on-premises and want to move existing applications to Azure as-is.

  • 希望充分利用 Azure 环境的功能,但 Azure SQL 数据库不支持应用程序需要的全部功能。You want to leverage the capabilities of the Azure environment but Azure SQL Database does not support all the features that your application requires. 这可能包括以下方面:This could include the following areas:

1 层(简单):单个虚拟机1-tier (simple): single virtual machine

在这种应用程序模式中,将 SQL Server 应用程序和数据库部署到 Azure 中的独立虚拟机上。In this application pattern, you deploy your SQL Server application and database to a standalone virtual machine in Azure. 同一个虚拟机还包含客户端/Web 应用程序、业务组件、数据访问层级和数据库服务器。The same virtual machine contains your client/web application, business components, data access layer, and the database server. 呈现、业务和数据访问代码在逻辑上是分离的,但从物理位置来看是位于单台服务器计算机上。The presentation, business, and data access code are logically separated but are physically located in a single-server machine. 大多数客户首先使用这种应用程序模式,然后通过向系统添加更多 Web 角色或虚拟机进行扩大。Most customers start with this application pattern and then, they scale out by adding more web roles or virtual machines to their system.

此应用程序模式适用于以下情况:This application pattern is useful when:

  • 用户希望执行向 Azure 平台的简单迁移,以评估平台是否能够满足应用程序的要求。You want to perform a simple migration to Azure platform to evaluate whether the platform answers your application's requirements or not.
  • 希望将所有应用程序层都承载在同一 Azure 数据中心的同一虚拟机上,以减少层之间的延迟。You want to keep all the application tiers hosted in the same virtual machine in the same Azure data center to reduce the latency between tiers.
  • 希望快速预配短期的开发和测试环境。You want to quickly provision development and test environments for short periods of time.
  • 希望执行不同工作负载级别的压力测试,但同时又不希望始终拥有和维护很多物理计算机。You want to perform stress testing for varying workload levels but at the same time you do not want to own and maintain many physical machines all the time.

下图演示了一个简单的本地方案,以及如何将它的云解决方案部署在 Azure 中的单个虚拟机上。The following diagram demonstrates a simple on-premises scenario and how you can deploy its cloud enabled solution in a single virtual machine in Azure.

1 层应用程序模式

将业务层(业务逻辑和数据访问组件)部署在呈现层所在的同一物理层级上可以最大程度地提高应用程序性能,除非可扩展性或安全问题必须使用单独的层级。Deploying the business layer (business logic and data access components) on the same physical tier as the presentation layer can maximize application performance, unless you must use a separate tier due to scalability or security concerns.

由于这是客户在开始时经常使用的一种模式,可能会发现以下有关将数据迁移到 SQL Server VM 的文章非常有用:将数据库迁移到 Azure VM 上的 SQL ServerSince this is a very common pattern to start with, you might find the following article on migration useful for moving your data to your SQL Server VM: Migrating a Database to SQL Server on an Azure VM.

3 层(简单):多个虚拟机3-tier (simple): multiple virtual machines

在这种应用程序模式中,在 Azure 中部署 3 层应用程序,方法是将每个应用程序层放置在不同的虚拟机中。In this application pattern, you deploy a 3-tier application in Azure by placing each application tier in a different virtual machine. 这样可为简单的向上缩放和向外缩放方案提供灵活的环境。This provides a flexible environment for an easy scale-up and scale-out scenarios. 一个虚拟机包含客户端/Web 应用程序,另一个虚拟机托管业务组件,另一个虚拟机则托管数据库服务器。When one virtual machine contains your client/web application, the other one hosts your business components, and the other one hosts the database server.

此应用程序模式适用于以下情况:This application pattern is useful when:

  • 希望执行复杂数据库应用程序向 Azure 虚拟机的迁移。You want to perform a migration of complex database applications to Azure Virtual Machines.
  • 希望在不同区域托管不同应用程序层。You want different application tiers to be hosted in different regions. 例如,可能会将一些共享数据库部署到不同区域,用于报告目的。For example, you might have shared databases that are deployed to multiple regions for reporting purposes.
  • 希望将企业应用程序从本地虚拟化平台迁移到 Azure 虚拟机。You want to move enterprise applications from on-premises virtualized platforms to Azure Virtual Machines. 有关企业应用程序的详细讨论,请参阅 What is an Enterprise Application(什么是企业应用程序)。For a detailed discussion on enterprise applications, see What is an Enterprise Application.
  • 希望快速预配短期的开发和测试环境。You want to quickly provision development and test environments for short periods of time.
  • 希望执行不同工作负载级别的压力测试,但同时又不希望始终拥有和维护很多物理计算机。You want to perform stress testing for varying workload levels but at the same time you do not want to own and maintain many physical machines all the time.

下图演示如何将简单的 3 层应用程序置于 Azure 中,方法是将每个应用程序层置于不同的虚拟机中。The following diagram demonstrates how you can place a simple 3-tier application in Azure by placing each application tier in a different virtual machine.

3 层应用程序模式

在这种应用程序模式中,每层只有一个虚拟机 (VM)。In this application pattern, there is only one virtual machine (VM) in each tier. 如果使用 Azure 中的多个 VM,我们建议设置虚拟网络。If you have multiple VMs in Azure, we recommend that you set up a virtual network. Azure 虚拟网络创建受信任安全边界,并允许 VM 通过专用 IP 地址相互通信。Azure Virtual Network creates a trusted security boundary and also allows VMs to communicate among themselves over the private IP address. 此外,请始终确保所有 Internet 连接仅进入呈现层。In addition, always make sure that all Internet connections only go to the presentation tier. 按此应用程序模式操作时,可通过管理网络安全组规则来控制访问。When following this application pattern, manage the network security group rules to control access. 有关详细信息,请参阅允许通过 Azure 门户对 VM 进行外部访问For more information, see Allow external access to your VM using the Azure portal.

图中的 Internet 协议可以是 TCP、UDP、HTTP 或 HTTPS。In the diagram, Internet Protocols can be TCP, UDP, HTTP, or HTTPS.

Note

在 Azure 中设置虚拟网络是免费的。Setting up a virtual network in Azure is free of charge. 但是,要为连接到本地的 VPN 网关付费。However, you are charged for the VPN gateway that connects to on-premises. 此费用的依据是预配和提供连接的时间长度。This charge is based on the amount of time that connection is provisioned and available.

2 层和 3 层模式,呈现层向外缩放2-tier and 3-tier with presentation tier scale-out

在这种应用程序模式中,将 2 层或 3 层数据库应用程序部署到 Azure 虚拟机,并将每个应用程序层放置在不同的虚拟机中。In this application pattern, you deploy 2-tier or 3-tier database application to Azure Virtual Machines by placing each application tier in a different virtual machine. 此外,由于传入客户端请求数量增加,还将呈现层向外缩放。In addition, you scale out the presentation tier due to increased volume of incoming client requests.

此应用程序模式适用于以下情况:This application pattern is useful when:

  • 希望将企业应用程序从本地虚拟化平台迁移到 Azure 虚拟机。You want to move enterprise applications from on-premises virtualized platforms to Azure Virtual Machines.
  • 由于传入客户端请求数量增加,还将呈现层向外缩放。You want to scale out the presentation tier due to increased volume of incoming client requests.
  • 希望快速预配短期的开发和测试环境。You want to quickly provision development and test environments for short periods of time.
  • 希望执行不同工作负载级别的压力测试,但同时又不希望始终拥有和维护很多物理计算机。You want to perform stress testing for varying workload levels but at the same time you do not want to own and maintain many physical machines all the time.
  • 想要拥有可以按需纵向扩展和减少的基础结构环境。You want to own an infrastructure environment that can scale up and down on demand.

下图演示由于传入客户端请求数量增加,如何才能通过将呈现层向外缩放,将应用程序层放置在 Azure 中的多个虚拟机中。The following diagram demonstrates how you can place the application tiers in multiple virtual machines in Azure by scaling out the presentation tier due to increased volume of incoming client requests. 正如图中所示,Azure 负载均衡器负责将流量分布到多个虚拟机,并确定要连接到哪个 Web 服务器。As seen in the diagram, Azure Load Balancer is responsible for distributing traffic across multiple virtual machines and also determining which web server to connect to. 负载均衡器之后有多个 Web 服务器实例,可以确保呈现层的高可用性。Having multiple instances of the web servers behind a load balancer ensures the high availability of the presentation tier.

应用程序模式 - 呈现层扩展

在一层中包含多个 VM 的 2 层、3 层或 n 层应用程序模式的最佳实践Best practices for 2-tier, 3-tier, or n-tier patterns that have multiple VMs in one tier

建议将属于同一层的虚拟机放置在同一云服务和同一可用性集中。It's recommended that you place the virtual machines that belong to the same tier in the same cloud service and in the same the availability set. 例如,将一组 Web 服务器放置在 CloudService1 和 AvailabilitySet1 中,而将一组数据库服务器放置在 CloudService2 和 AvailabilitySet2 中。For example, place a set of web servers in CloudService1 and AvailabilitySet1 and a set of database servers in CloudService2 and AvailabilitySet2. 利用 Azure 中的可用性集,可将高可用性节点放置在单独的容错域和升级域中。An availability set in Azure enables you to place the high availability nodes into separate fault domains and upgrade domains.

若要充分利用一层的多个 VM 实例,必须配置应用程序层之间的 Azure 负载均衡器。To leverage multiple VM instances of a tier, you need to configure Azure Load Balancer between application tiers. 若要配置每个层中的负载均衡器,请在每个层的 VM 上单独创建负载均衡终结点。To configure Load Balancer in each tier, create a load-balanced endpoint on each tier's VMs separately. 对于特定层,请首先在同一云服务中创建 VM。For a specific tier, first create VMs in the same cloud service. 这样可以确保它们具有同一公共虚拟 IP 地址。This ensures that they have the same public Virtual IP address. 接下来,在该层的一个虚拟机上创建终结点。Next, create an endpoint on one of the virtual machines on that tier. 然后,将同一终结点分配给该层上的其他虚拟机,以便进行负载均衡。Then, assign the same endpoint to the other virtual machines on that tier for load balancing. 通过创建负载均衡集,可将流量分布到多个虚拟机,并让负载均衡器能够在后端 VM 节点出现故障时确定连接哪一个节点。By creating a load-balanced set, you distribute traffic across multiple virtual machines and also allow the Load Balancer to determine which node to connect when a backend VM node fails. 例如,负载均衡器之后有多个 Web 服务器实例,可以确保呈现层的高可用性。For example, having multiple instances of the web servers behind a load balancer ensures the high availability of the presentation tier.

最佳做法是始终确保所有 Internet 连接首先进入呈现层。As a best practice, always make sure that all internet connections first go to the presentation tier. 呈现层访问业务层,业务层再访问数据层。The presentation layer accesses the business tier, and then the business tier accesses the data tier. 若要深入了解如何允许对呈现层的访问,请参阅允许通过 Azure 门户对 VM 进行外部访问For more information on how to allow access to the presentation layer, see Allow external access to your VM using the Azure portal.

请注意,Azure 中的负载均衡器的工作方式类似于本地环境中的负载均衡器。Note that the Load Balancer in Azure works similar to load balancers in an on-premises environment. 有关详细信息,请参阅 Azure 基础结构服务的负载均衡For more information, see Load balancing for Azure infrastructure services.

此外,我们建议使用 Azure 虚拟网络为虚拟机设置专用网络。In addition, we recommend that you set up a private network for your virtual machines by using Azure Virtual Network. 这让虚拟机能够通过专用 IP 地址相互通信。This allows them to communicate among themselves over the private IP address. 有关详细信息,请参阅 Azure 虚拟网络For more information, see Azure Virtual Network.

2 层和 3 层模式,业务层扩展2-tier and 3-tier with business tier scale-out

在这种应用程序模式中,将 2 层或 3 层数据库应用程序部署到 Azure 虚拟机,并将每个应用程序层放置在不同的虚拟机中。In this application pattern, you deploy 2-tier or 3-tier database application to Azure Virtual Machines by placing each application tier in a different virtual machine. 此外,考虑到应用程序的复杂性,可能需要将应用程序服务器组件分布到多个虚拟机。In addition, you might want to distribute the application server components to multiple virtual machines due to the complexity of your application.

此应用程序模式适用于以下情况:This application pattern is useful when:

  • 希望将企业应用程序从本地虚拟化平台迁移到 Azure 虚拟机。You want to move enterprise applications from on-premises virtualized platforms to Azure Virtual Machines.
  • 考虑到应用程序的复杂性,可将应用程序服务器组件分布到多个虚拟机。You want to distribute the application server components to multiple virtual machines due to the complexity of your application.
  • 希望将承受很重业务逻辑负荷的本地 LOB(业务线)应用程序迁移到 Azure 虚拟机。You want to move business logic heavy on-premises LOB (line-of-business) applications to Azure Virtual Machines. LOB 应用程序是对企业运营很重要的一组关键计算机应用程序,例如会计、人力资源 (HR)、工资单、供应链管理和资源计划应用程序。LOB applications are a set of critical computer applications that are vital to running an enterprise, such as accounting, human resources (HR), payroll, supply chain management, and resource planning applications.
  • 希望快速预配短期的开发和测试环境。You want to quickly provision development and test environments for short periods of time.
  • 希望执行不同工作负载级别的压力测试,但同时又不希望始终拥有和维护很多物理计算机。You want to perform stress testing for varying workload levels but at the same time you do not want to own and maintain many physical machines all the time.
  • 想要拥有可以按需纵向扩展和减少的基础结构环境。You want to own an infrastructure environment that can scale up and down on demand.

下图演示本地方案及其云解决方案。The following diagram demonstrates an on-premises scenario and its cloud enabled solution. 在此方案中,将应用程序层放置在 Azure 的多个虚拟机中,方法是将包含业务逻辑层和数据访问组件的业务层向外缩放。In this scenario, you place the application tiers in multiple virtual machines in Azure by scaling out the business tier, which contains the business logic tier and data access components. 正如图中所示,Azure 负载均衡器负责将流量分布到多个虚拟机,并确定要连接到哪个 Web 服务器。As seen in the diagram, Azure Load Balancer is responsible for distributing traffic across multiple virtual machines and also determining which web server to connect to. 负载均衡器之后有多个应用程序服务器实例,可以确保业务层的高可用性。Having multiple instances of the application servers behind a load balancer ensures the high availability of the business tier. 有关详细信息,请参阅 在一层中包含多个虚拟机的 2 层、3 层或 n 层应用程序模式的最佳实践For more information, see Best practices for 2-tier, 3-tier, or n-tier application patterns that have multiple virtual machines in one tier.

应用程序模式 - 业务展向外缩放

2 层和 3 层模式,呈现层和业务层横向扩展,提供 HADR2-tier and 3-tier with presentation and business tiers scale-out and HADR

在此应用程序模式中,通过将呈现层(Web 服务器)和业务层(应用程序服务器)组件分布到多个虚拟机,从而将 2 层或 3 层数据库应用程序部署到 Azure 虚拟机。In this application pattern, you deploy 2-tier or 3-tier database application to Azure Virtual Machines by distributing the presentation tier (web server) and the business tier (application server) components to multiple virtual machines. 此外,还在 Azure 虚拟机中为数据库实现高可用性和灾难恢复解决方案。In addition, you implement high-availability and disaster recovery solutions for your databases in Azure virtual machines.

此应用程序模式适用于以下情况:This application pattern is useful when:

  • 希望将企业应用程序从本地虚拟化平台迁移到 Azure,实现 SQL Server 高可用性和灾难恢复功能。You want to move enterprise applications from virtualized platforms on-premises to Azure by implementing SQL Server high availability and disaster recovery capabilities.
  • 考虑到传入客户端请求数量增加以及应用程序的复杂性,希望将呈现层和业务层向外缩放。You want to scale out the presentation tier and the business tier due to increased volume of incoming client requests and the complexity of your application.
  • 希望快速预配短期的开发和测试环境。You want to quickly provision development and test environments for short periods of time.
  • 希望执行不同工作负载级别的压力测试,但同时又不希望始终拥有和维护很多物理计算机。You want to perform stress testing for varying workload levels but at the same time you do not want to own and maintain many physical machines all the time.
  • 想要拥有可以按需纵向扩展和减少的基础结构环境。You want to own an infrastructure environment that can scale up and down on demand.

下图演示本地方案及其云解决方案。The following diagram demonstrates an on-premises scenario and its cloud enabled solution. 在此方案中,将 Azure 的多个虚拟机中的呈现层和业务层组件扩大。In this scenario, you scale out the presentation tier and the business tier components in multiple virtual machines in Azure. 此外,还要为 Azure 中的 SQL Server 数据库实施高可用性和灾难恢复 (HADR) 技术。In addition, you implement high availability and disaster recovery (HADR) techniques for SQL Server databases in Azure.

在不同 VM 上运行一个应用程序的多个副本,确保在这些虚拟机上实现请求的负载均衡。Running multiple copies of an application in different VMs make sure that you are load balancing requests across them. 使用多个虚拟机时,需要确保所有 VM 都是可访问的,并且同一时间点都在运行。When you have multiple virtual machines, you need to make sure that all your VMs are accessible and running at one point in time. 如果配置了负载均衡,Azure 负载均衡器会跟踪 VM 的运行状况,并将传入调用正确定向到正常运行的 VM 节点。If you configure load balancing, Azure Load Balancer tracks the health of VMs and directs incoming calls to the healthy functioning VM nodes properly. 有关如何设置虚拟机负载均衡的信息,请参阅 Azure 基础结构服务的负载均衡For information on how to set up load balancing of the virtual machines, see Load balancing for Azure infrastructure services. 负载均衡器之后有多个 Web 服务器和应用程序服务器实例,可以确保呈现层和业务层的高可用性。Having multiple instances of web and application servers behind a load balancer ensures the high availability of the presentation and business tiers.

横向扩展和高可用性

需要 SQL HADR 的应用程序模式的最佳做法Best practices for application patterns requiring SQL HADR

在 Azure 虚拟机中设置 SQL Server 高可用性和灾难恢复解决方案时,必须使用 Azure 虚拟网络为虚拟机设置虚拟网络。When you set up SQL Server high availability and disaster recovery solutions in Azure Virtual Machines, setting up a virtual network for your virtual machines using Azure Virtual Network is mandatory. 即便在服务停机之后,虚拟网络内的虚拟机也将具有静态专用 IP 地址,因此可以避免 DNS 名称解析所需的更新时间。Virtual machines within a Virtual Network will have a stable private IP address even after a service downtime, thus you can avoid the update time required for DNS name resolution. 此外,虚拟网络允许将本地网络扩展到 Azure,并创建受信任的安全边界。In addition, the virtual network allows you to extend your on-premises network to Azure and creates a trusted security boundary. 例如,如果应用程序具有企业域限制(例如 Windows 身份验证、Active Directory),则必须设置 Azure 虚拟网络For example, if your application has corporate domain restrictions (such as, Windows authentication, Active Directory), setting up Azure Virtual Network is necessary.

在 Azure 上运行生产代码的大多数客户都在 Azure 中保存主要副本和次要副本。Most of customers, who are running production code on Azure, are keeping both primary and secondary replicas in Azure.

有关高可用性和灾难恢复技术的综合信息和教程,请参阅 Azure 虚拟机中 SQL Server 的高可用性和灾难恢复For comprehensive information and tutorials on high availability and disaster recovery techniques, see High Availability and Disaster Recovery for SQL Server in Azure Virtual Machines.

使用 Azure VM 和云服务的 2 层和 3 层模式2-tier and 3-tier using Azure VMs and Cloud Services

在此应用程序模式中,使用 Azure 云服务(Web 角色和辅助角色 - 平台即服务 (PaaS))和 Azure 虚拟机(基础结构即服务 (IaaS)),将 2 层或 3 层应用程序部署到 Azure。In this application pattern, you deploy 2-tier or 3-tier application to Azure by using both Azure Cloud Services (web and worker roles - Platform as a Service (PaaS)) and Azure Virtual Machines (Infrastructure as a Service (IaaS)). Azure 云服务用于呈现层/业务层,将 Azure 虚拟机中的 SQL Server 用于数据层,这对于在 Azure 上运行的大多数应用程序都是有利的。Using Azure Cloud Services for the presentation tier/business tier and SQL Server in Azure Virtual Machines for the data tier is beneficial for most applications running on Azure. 原因是,在云服务上运行一个计算实例可以简化管理、部署、监控和扩展操作。The reason is that having a compute instance running on Cloud Services provides an easy management, deployment, monitoring, and scale-out.

通过云服务,Azure 可维护基础结构、执行日常维护、为操作系统安装修补程序,并尝试从服务和硬件故障中恢复。With Cloud Services, Azure maintains the infrastructure for you, performs routine maintenance, patches the operating systems, and attempts to recover from service and hardware failures. 当应用程序需要向外缩放时,可以通过增加或减少应用程序使用的实例或虚拟机的数量,使用云服务项目的自动和手动向外缩放选项。When your application needs scale-out, automatic, and manual scale-out options are available for your cloud service project by increasing or decreasing the number of instances or virtual machines that are used by your application. 此外,可以使用本地 Visual Studio,将应用程序部署到 Azure 中的云服务项目。In addition, you can use on-premises Visual Studio to deploy your application to a cloud service project in Azure.

总之,如果不希望自行承担呈现层/业务层的大量管理任务,而且应用程序也不需要软件或操作系统的任何复杂配置,则请使用 Azure 云服务。In summary, if you don't want to own extensive administrative tasks for the presentation/business tier and your application does not require any complex configuration of software or the operating system, use Azure Cloud Services. 如果 Azure SQL 数据库无法支持需要的全部功能,请将 Azure 虚拟机中的 SQL Server 用于数据层。If Azure SQL Database does not support all the features you are looking for, use SQL Server in an Azure Virtual Machine for the data tier. 在 Azure 云服务上运行应用程序,并将数据存储在 Azure 虚拟机中,可以综合两种服务的优点。Running an application on Azure Cloud Services and storing data in Azure Virtual Machines combines the benefits of both services. 如需详细的比较,请参阅此主题中有关 比较 Azure 中的开发策略的部分。For a detailed comparison, see the section in this topic on Comparing development strategies in Azure.

在此应用程序模式中,呈现层包括 Web 角色,它是在 Azure 执行环境中运行的云服务组件,为 IIS 和 ASP.NET 支持的 Web 应用程序编程进行了自定义。In this application pattern, the presentation tier includes a web role, which is a Cloud Services component running in the Azure execution environment and it is customized for web application programming as supported by IIS and ASP.NET. 业务或后端层包括辅助角色,它是在 Azure 执行环境中运行的云服务组件,对通用开发非常有用,可为 Web 角色执行后台处理。The business or backend tier includes a worker role, which is a Cloud Services component running in the Azure execution environment and it is useful for generalized development, and may perform background processing for a web role. 数据库层驻留在 Azure 中的 SQL Server 虚拟机中。The database tier resides in a SQL Server virtual machine in Azure. 呈现层和数据库层之间的通信直接进行,或者通过业务层(也就是辅助角色组件)进行。The communication between the presentation tier and the database tier happens directly or over the business tier - worker role components.

此应用程序模式适用于以下情况:This application pattern is useful when:

  • 希望将企业应用程序从本地虚拟化平台迁移到 Azure,实现 SQL Server 高可用性和灾难恢复功能。You want to move enterprise applications from virtualized platforms on-premises to Azure by implementing SQL Server high availability and disaster recovery capabilities.
  • 想要拥有可以按需纵向扩展和减少的基础结构环境。You want to own an infrastructure environment that can scale up and down on demand.
  • Azure SQL 数据库无法支持应用程序或数据库需要的所有功能。Azure SQL Database does not support all the features that your application or database needs.
  • 希望执行不同工作负载级别的压力测试,但同时又不希望始终拥有和维护很多物理计算机。You want to perform stress testing for varying workload levels but at the same time you do not want to own and maintain many physical machines all the time.

下图演示本地方案及其云解决方案。The following diagram demonstrates an on-premises scenario and its cloud enabled solution. 在此方案中,将呈现层放置在 Web 角色中,将业务层放置在辅助角色中,而将数据层放置在 Azure 的虚拟机中。In this scenario, you place the presentation tier in web roles, the business tier in worker roles but the data tier in virtual machines in Azure. 在不同 Web 角色中运行呈现层的多个副本,可以确保实现其请求的负载均衡。Running multiple copies of the presentation tier in different web roles ensures to load balance requests across them. 将 Azure 云服务和 Azure 虚拟机结合使用时,建议同时设置 Azure 虚拟网络When you combine Azure Cloud Services with Azure Virtual Machines, we recommend that you set up Azure Virtual Network as well. 使用 Azure 虚拟网络,可以在云中的同一云服务内拥有稳定持久的专用 IP 地址。With Azure Virtual Network, you can have stable and persistent private IP addresses within the same cloud service in the cloud. 在为虚拟机和云服务定义虚拟网络后,它们就可以通过专用 IP 地址开始相互通信。Once you define a virtual network for your virtual machines and cloud services, they can start communicating among themselves over the private IP address. 此外,使虚拟机与 Azure Web/辅助角色处于同一 Azure 虚拟网络中可缩短连接延迟并使连接更安全。In addition, having virtual machines and Azure web/worker roles in the same Azure Virtual Network provides low latency and more secure connectivity. 有关详细信息,请参阅什么是云服务For more information, see What is a cloud service.

正如图中所示,Azure 负载均衡器将流量分布到多个虚拟机,并确定要连接到哪个 Web 服务器或应用程序服务器。As seen in the diagram, Azure Load Balancer distributes traffic across multiple virtual machines and also determines which web server or application server to connect to. 负载均衡器之后有多个 Web 服务器和应用程序服务器实例,可以确保呈现层和业务层的高可用性。Having multiple instances of the web and application servers behind a load balancer ensures the high availability of the presentation tier and the business tier. 有关详细信息,请参阅 需要 SQL HADR 的应用程序模式的最佳实践For more information, see Best practices for application patterns requiring SQL HADR.

使用云服务的应用程序模式

实现此应用程序模式的另一种方法是使用包含呈现层和业务层组件的整合 Web 角色,如下图所示。Another approach to implement this application pattern is to use a consolidated web role that contains both presentation tier and business tier components as shown in the following diagram. 此应用程序模式适用于需要状态设计的应用程序。This application pattern is useful for applications that require stateful design. 由于 Azure 在 Web 角色和辅助角色上提供无状态计算节点,建议实现一个使用以下技术之一存储会话状态的逻辑:Azure 缓存Azure 表存储Azure SQL 数据库Since Azure provides stateless compute nodes on web and worker roles, we recommend that you implement a logic to store session state using one of the following technologies: Azure Caching, Azure Table Storage or Azure SQL Database.

使用云服务的应用程序模式

混合 Azure VM、Azure SQL 数据库和 Azure 应用服务(Web 应用)的模式Pattern with Azure VMs, Azure SQL Database, and Azure App Service (Web Apps)

此应用程序模式的主要目标是演示如何在解决方案中将 Azure 基础结构即服务 (IaaS) 组件和 Azure 平台即服务 (PaaS) 组件结合使用。The primary goal of this application pattern is to show you how to combine Azure infrastructure as a service (IaaS) components with Azure platform-as-a-service components (PaaS) in your solution. 此模式的重点是用于关系数据存储的 Azure SQL 数据库。This pattern is focused on Azure SQL Database for relational data storage. 它不将 SQL Server 包括在 Azure 虚拟机中,而将其作为 Azure 基础结构即服务。It does not include SQL Server in an Azure virtual machine, which is part of the Azure infrastructure as a service offering.

在此应用程序模式中,将数据库应用程序部署到 Azure,方法是将呈现层和业务层放置到同一虚拟机中,并访问 Azure SQL 数据库(SQL 数据库)服务器中的数据库。In this application pattern, you deploy a database application to Azure by placing the presentation and business tiers in the same virtual machine and accessing a database in Azure SQL Database (SQL Database) servers. 可以使用基于 IIS 的传统 Web 解决方案来实现呈现层。You can implement the presentation tier by using traditional IIS-based web solutions. 或者,可以使用 Azure Web 应用实现组合形式的呈现层和业务层。Or, you can implement a combined presentation and business tier by using Azure Web Apps.

此应用程序模式适用于以下情况:This application pattern is useful when:

  • 现在已经拥有了在 Azure 中配置的 SQL 数据库服务器,因此希望快速测试应用程序。You already have an existing SQL Database server configured in Azure and you want to test your application quickly.
  • 希望测试 Azure 环境的功能。You want to test the capabilities of Azure environment.
  • 希望快速预配短期的开发和测试环境。You want to quickly provision development and test environments for short periods of time.
  • 业务逻辑和数据访问组件可以自包含在 Web 应用程序中。Your business logic and data access components can be self-contained within a web application.

下图演示本地方案及其云解决方案。The following diagram demonstrates an on-premises scenario and its cloud enabled solution. 在此方案中,将应用程序层放置在 Azure 的单个虚拟机中,并访问 Azure SQL 数据库中的数据。In this scenario, you place the application tiers in a single virtual machine in Azure and access data in Azure SQL Database.

混合应用程序模式

如果选择使用 Azure Web 应用来实现组合形式的 Web 和应用层,我们建议保留中间层或应用层,作为 Web 应用程序上下文中的动态链接库 (DLL)。If you choose to implement a combined web and application tier by using Azure Web Apps, we recommend that you keep the middle-tier or application tier as dynamic-link libraries (DLLs) in the context of a web application.

此外,请查看本文末尾的 比较 Azure 中的 Web 开发策略 中提供的建议,以详细了解编程技巧。In addition, review the recommendations given in the Comparing web development strategies in Azure section at the end of this article to learn more about programming techniques.

N 层混合应用程序模式N-tier hybrid application pattern

在 n 层混合应用程序模式中,在分布在本地和 Azure 上的多个层中实现应用程序。In n-tier hybrid application pattern, you implement your application in multiple tiers distributed between on-premises and Azure. 因此,创建的是一个灵活和可重用的混合系统,可以修改该系统或添加特定层,而不对其他层进行更改。Therefore, you create a flexible and reusable hybrid system, which you can modify or add a specific tier without changing the other tiers. 若要将企业网络扩展到云,请使用 Azure 虚拟网络服务。To extend your corporate network to the cloud, you use Azure Virtual Network service.

此混合应用程序模式适用于以下情况:This hybrid application pattern is useful when:

  • 希望生成部分在云中运行、部分在本地运行的应用程序。You want to build applications that run partly in the cloud and partly on-premises.
  • 希望将现有本地应用程序的部分或全部元素迁移到云。You want to migrate some or all elements of an existing on-premises application to the cloud.
  • 希望将企业应用程序从本地虚拟化平台迁移到 Azure。You want to move enterprise applications from on-premises virtualized platforms to Azure.
  • 想要拥有可以按需纵向扩展和减少的基础结构环境。You want to own an infrastructure environment that can scale up and down on demand.
  • 希望快速预配短期的开发和测试环境。You want to quickly provision development and test environments for short periods of time.
  • 需要一种经济高效的方式来执行企业数据库应用程序的备份。You want a cost effective way to take backups for enterprise database applications.

下图演示横跨本地和 Azure 的 n 层混合应用程序模式。The following diagram demonstrates an n-tier hybrid application pattern that spans across on-premises and Azure. 如图中所示,本地基础结构包括 Active Directory 域服务域控制器,用于支持用户身份验证和授权。As shown in the diagram, on-premises infrastructure includes Active Directory Domain Services domain controller to support user authentication and authorization. 请注意,下图演示了一种方案,数据层的某些部分位于本地数据中心,而其他一些部分则位于 Azure 中。Note that the diagram demonstrates a scenario, where some parts of the data tier live in an on-premises data center whereas some parts of the data tier live in Azure. 根据应用程序的需求,可以实现多种其他混合方案。Depending on your application's needs, you can implement several other hybrid scenarios. 例如,可将呈现层和业务层保留在本地环境中,而将数据层保留在 Azure 中。For example, you might keep the presentation tier and the business tier in an on-premises environment but the data tier in Azure.

N 层应用程序模式

在 Azure 中,可以使用 Active Directory 作为组织的独立云目录,也可以将现有本地 Active Directory 与 Azure Active Directory 相集成。In Azure, you can use Active Directory as a standalone cloud directory for your organization, or you can also integrate existing on-premises Active Directory with Azure Active Directory. 正如图中所示,业务层组件可以访问多个数据源,例如通过专用内部 IP 地址访问 Azure 中的 SQL Server、通过 Azure 虚拟网络访问本地 SQL Server 或使用 .NET Framework 数据提供程序技术访问 SQL 数据库As seen in the diagram, the business tier components can access to multiple data sources, such as to SQL Server in Azure via a private internal IP address, to on-premises SQL Server via Azure Virtual Network, or to SQL Database using the .NET Framework data provider technologies. 在此图中,Azure SQL 数据库是一种可选的数据存储服务。In this diagram, Azure SQL Database is an optional data storage service.

在 n 层混合应用程序模式中,可以按照指定顺序实现以下工作流:In n-tier hybrid application pattern, you can implement the following workflow in the order specified:

  1. 使用 Microsoft Assessment and Planning (MAP) Toolkit,识别需要迁移到云的企业数据库应用程序。Identify enterprise database applications that need to be moved up to cloud by using the Microsoft Assessment and Planning (MAP) Toolkit. MAP 工具包从准备虚拟化的计算机中收集清单和性能数据,提供有关容量和评估计划的建议。The MAP Toolkit gathers inventory and performance data from computers you are considering for virtualization and provides recommendations on capacity and assessment planning.

  2. 计划在 Azure 平台中需要的资源和配置,例如存储帐户和虚拟机。Plan the resources and configuration needed in the Azure platform, such as storage accounts and virtual machines.

  3. 设置本地企业网络和 Azure 虚拟网络之间的网络连接。Set up network connectivity between the corporate network on-premises and Azure Virtual Network. 若要设置本地企业网络和 Azure 中虚拟机之间的连接,请使用以下两种方法之一:To set up the connection between the corporate network on-premises and a virtual machine in Azure, use one of the following two methods:

    1. 通过 Azure 中虚拟机上的公共终结点,在本地和 Azure 之间建立连接。Establish a connection between on-premises and Azure via public end points on a virtual machine in Azure. 这种方法提供简单的设置,可在虚拟机中使用 SQL Server 身份验证。This method provides an easy setup and enables you to use SQL Server authentication in your virtual machine. 另外,还可以设置网络安全组规则,控制到 VM 的公共流量。In addition, set up your network security group rules to control public traffic to the VM. 有关详细信息,请参阅允许通过 Azure 门户对 VM 进行外部访问For more information, see Allow external access to your VM using the Azure portal.

    2. 通过 Azure 虚拟专用网 (VPN) 隧道,在本地和 Azure 之间建立连接。Establish a connection between on-premises and Azure via Azure Virtual Private network (VPN) tunnel. 这种方法允许将域策略缩放到 Azure 中的虚拟机。This method allows you to extend domain policies to a virtual machine in Azure. 此外,可以设置防火墙规则,并在虚拟机中使用 Windows 身份验证。In addition, you can set up firewall rules and use Windows authentication in your virtual machine. 当前,Azure 支持安全的站点到站点 VPN 和点到站点 VPN 连接:Currently, Azure supports secure site-to-site VPN and point-to-site VPN connections:

      • 使用安全的站点到站点连接,可在本地网络和 Azure 中的虚拟网络之间建立网络连接。With secure site-to-site connection, you can establish network connectivity between your on-premises network and your virtual network in Azure. 建议将本地数据中心环境连接到 Azure。It is recommended for connecting your on-premises data center environment to Azure.
      • 使用安全的点到站点连接,可在 Azure 中的虚拟网络和在任何地点运行的各个计算机之间建立网络连接。With secure point-to-site connection, you can establish network connectivity between your virtual network in Azure and your individual computers running anywhere. 建议将它主要用于开发和测试。It is mostly recommended for development and test purposes.

      有关如何连接到 Azure 中的 SQL Server 的信息,请参阅连接到 Azure 上的 SQL Server 虚拟机For information on how to connect to SQL Server in Azure, see Connect to a SQL Server Virtual Machine on Azure.

  4. 设置计划的作业和警报,将本地数据备份到 Azure 中的虚拟机磁盘上。Set up scheduled jobs and alerts that back up on-premises data in a virtual machine disk in Azure. 有关详细信息,请参阅使用 Azure Blob 存储服务进行 SQL Server 备份和还原Azure 虚拟机中 SQL Server 的备份和还原For more information, see SQL Server Backup and Restore with Azure Blob Storage Service and Backup and Restore for SQL Server in Azure Virtual Machines.

  5. 根据应用程序的需要,可以实现以下三个常见方案之一:Depending on your application's needs, you can implement one of the following three common scenarios:

    1. 可将 Web 服务器、应用程序服务器和非敏感数据保留在 Azure 中的数据库服务器中,而将敏感数据保留在本地。You can keep your web server, application server, and insensitive data in a database server in Azure whereas you keep the sensitive data on-premises.
    2. 可将 Web 服务器和应用程序服务器保留在本地,而将数据库服务器保留在 Azure 的虚拟机中。You can keep your web server and application server on-premises whereas the database server in a virtual machine in Azure.
    3. 可将数据库服务器、Web 服务器和应用程序服务器保留在本地,而将数据库副本保留在 Azure 的虚拟机中。You can keep your database server, web server, and application server on-premises whereas you keep the database replicas in virtual machines in Azure. 这种设置允许本地 Web 服务器或报告应用程序访问 Azure 中的数据库副本。This setting allows the on-premises web servers or reporting applications to access the database replicas in Azure. 因此,可以成功地降低本地数据库中的工作负荷。Therefore, you can achieve to lower the workload in an on-premises database. 我们建议在具有很高读取工作负荷的情况下实施此方案,也可将其用于开发目的。We recommend that you implement this scenario for heavy read workloads and developmental purposes. 有关在 Azure 中创建数据库副本的信息,请参阅 Azure 虚拟机中 SQL Server 的高可用性和灾难恢复中的“AlwaysOn 可用性组”。For information on creating database replicas in Azure, see AlwaysOn Availability Groups at High Availability and Disaster Recovery for SQL Server in Azure Virtual Machines.

比较 Azure 中的 Web 开发策略Comparing web development strategies in Azure

若要在 Azure 中实现和部署基于 SQL Server 的多层应用程序,可以使用下述两种编程方法之一:To implement and deploy a multi-tier SQL Server-based application in Azure, you can use one of the following two programming methods:

  • 在 Azure 中设置传统 Web 服务器 (IIS - Internet Information Services),并访问 Azure 虚拟机的 SQL Server 中的数据库。Set up a traditional web server (IIS - Internet Information Services) in Azure and access databases in SQL Server in Azure Virtual Machines.
  • 实现云服务并将其部署到 Azure。Implement and deploy a cloud service to Azure. 然后,确保此云服务可以访问 Azure 虚拟机的 SQL Server 中的数据库。Then, make sure that this cloud service can access databases in SQL Server in Azure Virtual machines. 一个云服务可以包含多个 Web 角色和辅助角色。A cloud service can include multiple web and worker roles.

下表提供了在 Azure 虚拟机中的 SQL Server 方面,传统 Web 开发与 Azure 云服务和 Azure Web 应用之间的比较。The following table provides a comparison of traditional web development with Azure Cloud Services and Azure Web Apps with respect to SQL Server in Azure Virtual Machines. 该表包括 Azure Web 应用,因为我们可以通过公共虚拟 IP 地址或 DNS 名称,使用 Azure VM 中的 SQL Server 作为 Azure Web 应用的数据源。The table includes Azure Web Apps as it is possible to use SQL Server in Azure VM as a data source for Azure Web Apps via its public virtual IP address or DNS name.

Azure 虚拟机中的传统 Web 开发Traditional web development in Azure Virtual Machines Azure 中的云服务Cloud Services in Azure Azure Web 应用的 Web 托管功能Web Hosting with Azure Web Apps
从本地进行的应用程序迁移Application Migration from on-premises 保持现有应用程序的原样。Existing applications as-is. 应用程序需要 Web 角色和辅助角色。Applications need web and worker roles. 在保持现有应用程序原样的同时,针对需要快速缩放的自包含 Web 应用程序和 Web 服务进行了调整。Existing applications as-is but suited for self-contained web applications and web services that require quick scalability.
开发和部署Development and Deployment Visual Studio、WebMatrix、Visual Web Developer、WebDeploy、FTP、TFS、IIS Manager、PowerShell。Visual Studio, WebMatrix, Visual Web Developer, WebDeploy, FTP, TFS, IIS Manager, PowerShell. Visual Studio、Azure SDK、TFS、PowerShell。Visual Studio, Azure SDK, TFS, PowerShell. 每个云服务具有两个环境,可将服务包和配置部署到这两个环境:过渡和生产。Each cloud service has two environments to which you can deploy your service package and configuration: staging and production. 在将云服务升级到生产环境之前,可以将其部署到过渡环境以对其进行测试。You can deploy a cloud service to the staging environment to test it before you promote it to production. Visual Studio、WebMatrix、Visual Web Developer、FTP、GIT、BitBucket、CodePlex、DropBox、GitHub、Mercurial、TFS、Web Deploy、PowerShell。Visual Studio, WebMatrix, Visual Web Developer, FTP, GIT, BitBucket, CodePlex, DropBox, GitHub, Mercurial, TFS, Web Deploy, PowerShell.
管理和设置Administration and Setup 用户负责应用程序、数据、防火墙规则、虚拟网络和操作系统的管理任务。You are responsible for administrative tasks on the application, data, firewall rules, virtual network, and operating system. 用户负责应用程序、数据、防火墙规则和虚拟网络的管理任务。You are responsible for administrative tasks on the application, data, firewall rules, and virtual network. 用户只负责应用程序和数据的管理任务。You are responsible for administrative tasks on the application and data only.
高可用性和灾难恢复 (HADR)High Availability and Disaster Recovery (HADR) 建议将虚拟机置于同一可用性集和同一云服务中。We recommend that you place virtual machines in the same availability set and in the same cloud service. 将 VM 保留在同一可用性集中,可以让 Azure 将高可用性节点放置在单独的容错域和升级域中。Keeping your VMs in the same availability set allows Azure to place the high availability nodes into separate fault domains and upgrade domains. 同样,将 VM 保留在同一云服务中可以实现负载均衡,VM 能够通过 Azure 数据中心内的本地网络直接相互通信。Similarly, keeping your VMs in the same cloud service enables load balancing and VMs can communicate directly with one another over the local network within an Azure data center.

用户负责为 Azure 虚拟机中的 SQL Server 实现高可用性和灾难恢复解决方案,避免任何停机。You are responsible for implementing a high availability and disaster recovery solution for SQL Server in Azure Virtual Machines to avoid any downtime. 有关受支持的 HADR 技术,请参阅 Azure 虚拟机中 SQL Server 的高可用性和灾难恢复For supported HADR technologies, see High Availability and Disaster Recovery for SQL Server in Azure Virtual Machines.

用户负责备份自己的数据和应用程序。You are responsible for backing up your own data and application.

如果由于硬件问题,数据中心的主机发生故障,Azure 可以移动虚拟机。Azure can move your virtual machines if the host machine in the data center fails due to hardware issues. 此外,在出于安全目的对主机进行更新或进行软件更新时,VM 可能会出现计划内停机。In addition, there could be planned downtime of your VM when the host machine is updated for security or software updates. 因此,建议在每个应用层保持至少两个 VM,确保持续可用性。Therefore, we recommend that you maintain at least two VMs in each application tier to ensure the continuous availability. Azure 不提供针对单个虚拟机的 SLA。Azure does not provide SLA for a single virtual machine.
Azure 可管理底层硬件或操作系统软件导致的故障。Azure manages the failures resulting from the underlying hardware or operating system software. 我们建议实现 Web 角色或辅助角色的多个实例,以确保应用程序的高可用性。We recommend that you implement multiple instances of a web or worker role to ensure the high availability of your application. 有关详细信息,请参阅云服务、虚拟机和虚拟网络服务级别协议For information, see Cloud Services, Virtual Machines, and Virtual Network Service Level Agreement.

用户负责备份自己的数据和应用程序。You are responsible for backing up your own data and application.

对于 Azure VM 的 SQL Server 数据库中驻留的数据库,用户需负责实现高可用性和灾难恢复解决方案,避免任何停机。For databases residing in a SQL Server database in an Azure VM, you are responsible for implementing a high availability and disaster recovery solution to avoid any downtime. 有关受支持的 HDAR 技术,请参阅“Azure 虚拟机中 SQL Server 的高可用性和灾难恢复”。For supported HDAR technologies, see High Availability and Disaster Recovery for SQL Server in Azure Virtual Machines.

SQL Server 数据库镜像:与 Azure 云服务(Web/辅助角色)配合使用。SQL Server Database Mirroring: Use with Azure Cloud Services (web/worker roles). SQL Server VM 和云服务项目可以位于同一 Azure 虚拟网络中。SQL Server VMs and a cloud service project can be in the same Azure Virtual Network. 如果 SQL Server VM 不在同一虚拟网络中,需要创建一个 SQL Server 别名,将通信路由到 SQL Server 实例。If SQL Server VM is not in the same Virtual Network, you need to create a SQL Server Alias to route communication to the instance of SQL Server. 此外,该别名必须与 SQL Server 名称匹配。In addition, the alias name must match the SQL Server name.
从 Azure 辅助角色、Azure Blob 存储和 Azure SQL 数据库继承高可用性。High Availability is inherited from Azure worker roles, Azure blob storage, and Azure SQL Database. 例如,Azure 存储保存所有 Blob、表和队列数据的 3 个副本。For example, Azure Storage maintains three replicas of all blob, table, and queue data. 在任何时候,Azure SQL 数据库都始终会运行数据的三个副本 — 一个主要副本和两个次要副本。At any one time, Azure SQL Database keeps three replicas of data running—one primary replica and two secondary replicas. 有关详细信息,请参阅 Azure 存储Azure SQL 数据库For more information, see Azure Storage and Azure SQL Database.

使用 Azure VM 中的 SQL Server 作为 Azure Web 应用的数据源时,需谨记 Azure Web 应用不支持 Azure 虚拟网络。When using SQL Server in Azure VM as a data source for Azure Web Apps, keep in mind that Azure Web Apps does not support Azure Virtual Network. 换言之,Azure 中所有从 Azure Web 应用到 SQL Server VM 的连接都必须经过虚拟机的公共终结点。In other words, all connections from Azure Web Apps to SQL Server VMs in Azure must go through public end points of virtual machines. 这可能会导致一些对高可用性和灾难恢复方案的受限。This might cause some limitations for high availability and disaster recovery scenarios. 例如,如果 Azure Web 应用连接到带有数据库镜像功能的 SQL Server VM,那么其上的客户端应用程序将无法连接到新的主服务器,因为数据库镜像要求设置 Azure 中 SQL Server 主机 VM 之间的 Azure 虚拟网络。For example, the client application on Azure Web Apps connecting to SQL Server VM with database mirroring would not be able to connect to the new primary server as database mirroring requires that you set up Azure Virtual Network between SQL Server host VMs in Azure. 因此,当前不支持将 SQL Server 数据库镜像用于 Azure Web 应用。Therefore, using SQL Server Database Mirroring with Azure Web Apps is not supported currently.

SQL Server AlwaysOn 可用性组:在 Azure 中将 Azure Web 应用与 SQL Server VM 配合使用时,可以设置 AlwaysOn 可用性组。SQL Server AlwaysOn Availability Groups: You can set up AlwaysOn Availability Groups when using Azure Web Apps with SQL Server VMs in Azure. 但是,需对 AlwaysOn 可用性组侦听器进行配置,通过公共负载均衡终结点将通信路由到主副本。But you need to configure AlwaysOn Availability Group Listener to route the communication to the primary replica via public load-balanced endpoints.
跨界连接cross-premises Connectivity 可以使用 Azure 虚拟网络连接到本地。You can use Azure Virtual Network to connect to on-premises. 可以使用 Azure 虚拟网络连接到本地。You can use Azure Virtual Network to connect to on-premises. 支持 Azure 虚拟网络。Azure Virtual Network is supported. 有关详细信息,请参阅 Web 应用虚拟网络集成For more information, see Web Apps Virtual Network Integration.
可伸缩性Scalability 增加虚拟机大小或添加更多磁盘即可扩大。Scale-up is available by increasing the virtual machine sizes or adding more disks. 有关虚拟机大小的详细信息,请参见 Azure 的虚拟机大小For more information about virtual machine sizes, see Virtual Machine Sizes for Azure.

对于数据库服务器:通过数据库分区技术或 SQL Server AlwaysOn 可用性组即可横向扩展。For Database Server: Scale-out is available via database partitioning techniques and SQL Server AlwaysOn Availability groups.

对于很高的读取工作负荷,可在多个辅助节点上使用 AlwaysOn Availability Groups(AlwaysOn 可用性组),还可使用 SQL Server 复制。For heavy read workloads, you can use AlwaysOn Availability Groups on multiple secondary nodes as well as SQL Server Replication.

对于很高的写入工作负荷,可在多个物理服务器上实施水平分区数据,以便进行应用程序扩展。For heavy write workloads, you can implement horizontal partitioning data across multiple physical servers to provide application scale-out.

此外,还可以使用 SQL Server with Data Dependent Routing(具有数据依赖型路由的 SQL Server)实现扩展。In addition, you can implement a scale-out by using SQL Server with Data Dependent Routing. 使用数据依赖型路由 (DDR) 时,需要在客户端应用程序中实施分区机制(通常是在业务层中),将数据库请求路由到多个 SQL Server 节点。With Data Dependent Routing (DDR), you need to implement the partitioning mechanism in the client application, typically in the business tier layer, to route the database requests to multiple SQL Server nodes. 业务层包含有关如何对数据进行分区和哪些节点包含数据的映射。The business tier contains mappings to how the data is partitioned and which node contains the data.

可以缩放运行虚拟机的应用程序。You can scale applications that are running virtual machines. 有关详细信息,请参阅 如何缩放应用程序For more information, see How to Scale an Application.

重要说明:Azure 中的“自动缩放”功能可以自动增加或减少应用程序使用的虚拟机。Important Note: The AutoScale feature in Azure allows you to automatically increase or decrease the Virtual Machines that are used by your application. 此功能可以保证在高峰期间不会对最终用户体验产生负面影响,并且在需求较低时可以关闭 VM。This feature guarantees that the end-user experience is not affected negatively during peak periods, and VMs are shut down when the demand is low. 如果云服务包括 SQL Server VM,建议不要为其设置“自动缩放”选项。It's recommended that you do not set the AutoScale option for your cloud service if it includes SQL Server VMs. 因为自动缩放功能允许 Azure 在该 VM 中的 CPU 使用率高于某个阈值时打开一个虚拟机,并且在 CPU 使用率低于该阈值时关闭一个虚拟机。The reason is that the AutoScale feature lets Azure to turn on a virtual machine when the CPU usage in that VM is higher than some threshold, and to turn off a virtual machine when the CPU usage goes lower than it. 自动缩放功能对于无状态应用程序(例如 Web 服务器)非常有用,在这种应用程序中,VM 可以在不参考以前状态的情况下管理工作负荷。The AutoScale feature is useful for stateless applications, such as web servers, where any VM can manage the workload without any references to any previous state. 不过,自动缩放功能对于有状态应用程序(例如 SQL Server)没有用处,在这种应用程序中,只有一个实例允许写入到数据库。However, the AutoScale feature is not useful for stateful applications, such as SQL Server, where only one instance allows writing to the database.
可以使用多个 Web 角色和辅助角色进行扩展。Scale-up is available by using multiple web and worker roles. 若要深入了解 Web 角色和辅助角色的虚拟机大小,请参阅配置云服务大小For more information about virtual machine sizes for web roles and worker roles, see Configure Sizes for Cloud Services.

使用云服务时,可以定义多个角色,以便进行分布式处理以及实现灵活缩放。When using Cloud Services, you can define multiple roles to distribute processing and also achieve flexible scaling of your application. 每个云服务包括一个或多个 Web 角色和/或辅助角色,每个角色具有自身的应用程序文件和配置。Each cloud service includes one or more web roles and/or worker roles, each with its own application files and configuration. 可以通过增加为角色部署的角色实例(虚拟机)数量,增加云服务,或者通过减少角色实例数量,减少云服务。You can scale-up a cloud service by increasing the number of role instances (virtual machines) deployed for a role and scale-down a cloud service by decreasing the number of role instances. 有关详细信息,请参阅 Azure 执行模型For detailed information, see Azure Execution Models.

可利用云服务、虚拟机以及虚拟网络服务级别协议和负载均衡器通过内置的 Azure 高可用性进行扩展。Scale-out is available via built-in Azure high availability support through Cloud Services, Virtual Machines, and Virtual Network Service Level Agreement and Load Balancer.

对于多层应用程序,建议通过 Azure 虚拟网络,将 Web 角色/辅助角色应用程序连接到数据库服务器 VM。For a multi-tier application, we recommend that you connect web/worker roles application to database server VMs via Azure Virtual Network. 此外,Azure 为同一云服务中的 VM 提供负载均衡,将用户请求分散到这些 VM。In addition, Azure provides load balancing for VMs in the same cloud service, spreading user requests across them. 以这种方式连接的虚拟机可以通过 Azure 数据中心内的本地网络直接相互通信。Virtual machines connected in this way can communicate directly with one another over the local network within an Azure data center.

可在 Azure 门户上设置自动缩放,还可设置计划时间。You can set up AutoScale on the Azure portal as well as the schedule times. 有关详细信息,请参阅如何在门户中为云服务配置自动缩放For more information, see How to configure auto scaling for a Cloud Service in the portal.
可在门户上设置自动缩放,还可设置计划时间。You can set up AutoScale on the portal as well as the schedule times. 有关详细信息,请参阅如何缩放 Web 应用For more information, see How to Scale Web Apps.

有关如何在这些编辑方法之间进行选择的详细信息,请参阅 Azure Web 应用、云服务和 VM:何时使用何种产品For more information on choosing between these programming methods, see Azure Web Apps, Cloud Services, and VMs: When to use which.

后续步骤Next Steps

若要深入了解如何在 Azure 虚拟机中运行 SQL Server,请参阅 Azure 虚拟机中的 SQL Server 概述For more information on running SQL Server in Azure Virtual machines, see SQL Server on Azure Virtual Machines Overview.