Azure 中的多租户应用程序Multitenant Applications in Azure

多租户应用程序是一种共享资源,它允许单独的用户或“租户”像使用他们自己的应用程序一样查看该应用程序。A multitenant application is a shared resource that allows separate users, or "tenants," to view the application as though it was their own. 适合实施多租户应用程序的典型情况是,应用程序的所有用户都可能希望定制用户体验,但在其他方面具有相同的基本业务要求。A typical scenario that lends itself to a multitenant application is one in which all users of the application may wish to customize the user experience but otherwise have the same basic business requirements. 大型多租户应用程序的示例包括 Office 365、Outlook.com 和 visualstudio.com。Examples of large multitenant applications are Office 365, Outlook.com, and visualstudio.com.

从应用程序提供商的角度来看,多租户技术的优势大多涉及运营和成本效益。From an application provider's perspective, the benefits of multitenancy mostly relate to operational and cost efficiencies. 应用程序的一个版本可以满足许多租户/客户的需求,从而使你能够整合系统管理任务,例如监视、性能优化、软件维护和数据备份。One version of your application can meet the needs of many tenants/customers, allowing consolidation of system administration tasks such as monitoring, performance tuning, software maintenance, and data backups.

下面提供了一系列从提供商的角度来看最重要的目标和要求。The following provides a list of the most significant goals and requirements from a provider's perspective.

  • 预配:必须能够为应用程序配置新租户。Provisioning: You must be able to provision new tenants for the application. 对于具有大量租户的多租户应用程序,通常必须通过启用自助服务配置来自动化此过程。For multitenant applications with a large number of tenants, it is usually necessary to automate this process by enabling self-service provisioning.
  • 可维护性:必须能够升级应用程序,并在多个租户使用该应用程序时执行其他维护任务。Maintainability: You must be able to upgrade the application and perform other maintenance tasks while multiple tenants are using it.
  • 监视:必须能够随时监视应用程序以确定和解决任何问题。Monitoring: You must be able to monitor the application at all times to identify any problems and to troubleshoot them. 其中包括监视每个租户如何使用应用程序。This includes monitoring how each tenant is using the application.

实施得当的多租户应用程序可为用户提供以下好处:A properly implemented multitenant application provides the following benefits to users.

  • 隔离:各个租户的活动不会影响其他租户使用应用程序。Isolation: The activities of individual tenants do not affect the use of the application by other tenants. 租户无法访问彼此的数据。Tenants cannot access eatch others data. 看上去租户好像拥有应用程序的专用权。It appear to the tennant as though they have exclusive use of the application.
  • 可用性:各个租户希望应用程序始终可用,并可能在 SLA 中明确保证。Availability: Individual tenants want the application to be constantly available, perhaps with guarantees defined in an SLA. 同样,其他租户的活动不应影响应用程序的可用性。Again, the activities of other tenants should not affect the availability of the application.
  • 可伸缩性:应用程序可进行缩放以满足各个租户的需求。Scalability: The application scales to meet the demand of individual tenants. 其他租户的状态和操作不应影响应用程序的性能。The presence and actions of other tenants should not affect the performance of the application.
  • 成本:成本低于运行单租户专用应用程序,因为多租户技术支持资源共享。Costs: Costs are lower than running a dedicated, single-tenant application because multi-tenancy enables the sharing of resources.
  • 可定制性Customizability. 能够通过多种方式(例如添加或删除功能、更改颜色和徽标,或者甚至添加自己的代码或脚本)为单个租户定制应用程序。The ability to customize the application for an individual tenant in various ways such as adding or removing features, changing colors and logos, or even adding their own code or script.

总之,虽然提供高度可扩展的服务必须考虑很多事项,但对于许多多租户应用程序,也有一些共同的目标和要求。In short, while there are many considerations that you must take into account to provide a highly scalable service, there are also a number of the goals and requirements that are common to many multitenant applications. 有些要求在特定情况下可能并不相关,并且各个目标和要求的重要性在各种情况下也会有所不同。Some may not be relevant in specific scenarios, and the importance of individual goals and requirements will differ in each scenario. 作为多租户应用程序的提供商,你的目标和要求还有:满足租户的目标和要求、盈利能力、计费、多个服务级别、配置、可维护性监视以及自动化。As a provider of the multitenant application, you will also have goals and requirements such as, meeting the tenants' goals and requirements, profitability, billing, multiple service levels, provisioning, maintainability monitoring, and automation.

有关多租户应用程序的其他设计注意事项的详细信息,请参阅在 Azure 中托管多租户应用程序For more information on additional design considerations of a multitenant application, see Hosting a Multi-Tenant Application on Azure.

Azure 提供了许多功能,使你能够解决在设计多租户系统时遇到的关键问题。Azure provides many features that allow you to address the key problems encountered when designing a multitenant system.

隔离Isolation

  • 按使用或不使用 SSL 通信的主机头对网站租户进行分段Segment Website Tenants by Host Headers with or without SSL communication
  • 按查询参数对网站租户进行分段Segment Website Tenants by Query Parameters
  • 辅助角色中的 Web 服务Web Services in Worker Roles
    • 辅助角色通常在应用程序后端处理数据。Worker Roles that typically process data on the backend of an application.
    • 通常充当应用程序前端的 Web 角色。Web Roles that typically act as the frontend for applications.

存储Storage

数据管理(如 Azure SQL 数据库)或 Azure 存储服务(例如可存储大量非结构化数据的表服务,以及可存储视频、音频和图像等大量非结构化文本或二进制数据的 Blob 服务)。Data management such as Azure SQL Database or Azure Storage services such as the Table service which provides services for storage of large amounts of unstructured data and the Blob service which provides services to store large amounts of unstructured text or binary data such as video, audio and images.

  • 针对每个租户的 SQL Server 登录名,保护 SQL 数据库中的多租户数据。Securing Multitenant Data in SQL Database appropriate per-tenant SQL Server logins.
  • 对应用程序资源使用 Azure 表 - 通过指定容器级别的访问策略,可以调整权限,且无需为使用共享访问签名加以保护的资源发布新 URL。Using Azure Tables for Application Resources By specifying a container level access policy, you can the ability to adjust permissions without having to issue new URL's for the resources protected with shared access signatures.
  • 对应用程序资源使用 Azure 队列 - Azure 队列通常用于代表租户驱动处理过程,但也可以将其用于分发配置或管理所需的工作。Azure Queues for Application Resources Azure queues are commonly used to drive processing on behalf of tenants, but may also be used to distribute work required for provisioning or management.
  • 对应用程序资源使用服务总线队列 - 对于将工作推送到共享服务的租户特定应用程序功能,可以使用单个队列,该队列中的每个租户发送方只有推送到该队列的权限(派生自 ACS 发布的声明),同时只有服务接收方有权从该队列中提取来自多个租户的数据。Service Bus Queues for Application Resources that pushes work to a shared a service, you can use a single queue where each tenant sender only has permissions (as derived from claims issued from ACS) to push to that queue, while only the receivers from the service have permission to pull from the queue the data coming from multiple tenants.

连接和安全服务Connection and Security Services

  • Azure 服务总线是位于两个应用程序之间的消息传送基础结构,允许应用程序以松散耦合的方式交换消息,从而改进扩展性并提高恢复能力。Azure Service Bus, a messaging infrastructure that sits between applications allowing them to exchange messages in a loosely coupled way for improved scale and resiliency.

网络服务Networking Services

Azure 提供了一些联网服务,它们支持身份验证且提高了托管应用程序的可管理性。Azure provides several networking services that support authentication, and improve manageability of your hosted applications. 这些服务包括:These services include the following:

  • 利用 Azure 虚拟网络,可以预配和管理 Azure 中的虚拟专用网 (VPN),并将其与本地 IT 基础结构安全链接。Azure Virtual Network lets you provision and manage virtual private networks (VPNs) in Azure as well as securely link these with on-premises IT infrastructure.
  • 利用虚拟网络流量管理器,可以跨多项 Azure 托管服务对传入流量进行负载均衡,无论这些服务运行在同一数据中心内,还是运行在全球的不同数据中心内。Virtual Network Traffic Manager allows you to load balance incoming traffic across multiple hosted Azure services whether they're running in the same datacenter or across different datacenters around the world.
  • Azure Active Directory (Azure AD) 是一项基于 REST 的新型服务,它可为云应用程序提供标识管理和访问控制功能。Azure Active Directory (Azure AD) is a modern, REST-based service that provides identity management and access control capabilities for your cloud applications. 可对应用程序资源使用 Azure AD - Azure AD 不仅允许将身份验证和授权功能从代码中分离出来,而且还提供对用户进行身份验证和授权以获取对网站和服务的访问权限的简便方法。Using Azure AD for Application Resources Azure AD to provides an easy way of authenticating and authorizing users to gain access to your web sites and services while allowing the features of authentication and authorization to be factored out of your code.
  • Azure 服务总线为分布式应用程序和混合应用程序提供了安全消息传送和数据流功能,例如在 Azure 托管的应用程序与本地应用程序和服务之间进行通信,而不需要复杂的防火墙和安全基础结构。Azure Service Bus provides a secure messaging and data flow capability for distributed and hybrid applications, such as communication between Azure hosted applications and on-premises applications and services, without requiring complex firewall and security infrastructures. 可对应用程序资源使用服务总线中继 - 公开为终结点的服务可能属于租户(例如托管在系统之外的服务,如本地服务),也可能是专门为租户配置的服务(因为特定于租户的敏感数据通过这些服务传输)。Using Service Bus Relay for Application Resources to The services that are exposed as endpoints may belong to the tenant (for example, hosted outside of the system, such as on-premise), or they may be services provisioned specifically for the tenant (because sensitive, tenant-specific data travels across them).

预配资源Provisioning Resources

Azure 提供许多方法来为应用程序预配新租户。Azure provides a number of ways provision new tenants for the application. 对于具有大量租户的多租户应用程序,通常必须通过启用自助服务配置来自动化此过程。For multitenant applications with a large number of tenants, it is usually necessary to automate this process by enabling self-service provisioning.

  • 辅助角色使你能够预配和取消预配每租户资源(例如当新租户注册或取消时),收集度量值以供计量使用,以及根据特定计划或在达到关键性能指标阈值时作为响应来管理缩放。Worker roles allow you to provision and de-provision per tenant resources (such as when a new tenant signs-up or cancels), collect metrics for metering use, and manage scale following a certain schedule or in response to the crossing of thresholds of key performance indicators. 同一角色也可用于推出解决方案的更新和升级。This same role may also be used to push out updates and upgrades to the solution.

  • Azure Blob 可用于为新租户预配计算资源或预先初始化的存储资源,同时可提供容器级别访问策略来保护计算服务包、VHD 映像和其他资源。Azure Blobs can be used to provision compute or pre-initialized storage resources for new tenants while providing container level access policies to protect the compute service Packages, VHD images and other resources.

  • 为租户预配 SQL 数据库资源的方式包括:Options for provisioning SQL Database resources for a tenant include:

    • 在脚本中使用 DDL 或将其作为资源嵌入程序集DDL in scripts or embedded as resources within assemblies
    • 使用以编程方式部署的 SQL Server 2008 R2 DAC 包。SQL Server 2008 R2 DAC Packages deployed programmatically.
    • 从主引用数据库进行复制Copying from a master reference database
    • 使用数据库“导入”和“导出”从文件中预配新数据库。Using database Import and Export to provision new databases from a file.