您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

想要了解 Service Fabric 吗?So you want to learn about Service Fabric?

Azure Service Fabric 是一种分布式系统平台,适用于打包、部署和管理可缩放的可靠微服务。Azure Service Fabric is a distributed systems platform that makes it easy to package, deploy, and manage scalable and reliable microservices. 不过,Service Fabric 的外围应用领域广泛,有很多东西需要学习。Service Fabric has a large surface area, however, and there's a lot to learn. 本文简要说明了 Service Fabric,并介绍了核心概念、编程模型、应用程序生命周期、测试、群集和运行状况监视。This article provides a synopsis of Service Fabric and describes the core concepts, programming models, application lifecycle, testing, clusters, and health monitoring. 请参阅概述什么是微服务?,概览相关信息,并了解如何使用 Service Fabric 创建微服务。Read the Overview and What are microservices? for an introduction and how Service Fabric can be used to create microservices. 本文包含的内容列表虽不完整,但确实提供了 Service Fabric 每个应用领域的概述和入门文章链接。This article does not contain a comprehensive content list, but does link to overview and getting started articles for every area of Service Fabric.

核心概念Core concepts

此处介绍基础知识,有关详细概念和介绍,可参阅 Service Fabric 术语应用程序模型支持的编程模型Service Fabric terminology, Application model, and Supported programming models provide more concepts and descriptions, but here are the basics.

设计时: 服务类型、 服务包和清单、 应用程序类型、 应用程序包和清单Design time: service type, service package and manifest, application type, application package and manifest

服务类型是分配给服务的代码包、数据包、配置包的名称/版本。A service type is the name/version assigned to a service's code packages, data packages, and configuration packages. 这在 ServiceManifest.xml 文件中定义。This is defined in a ServiceManifest.xml file. 服务类型组成的可执行代码和服务配置设置,在运行时加载,并供该服务的静态数据。The service type is composed of executable code and service configuration settings, which are loaded at run time, and static data that is consumed by the service.

服务包是一个磁盘目录,其中包含服务类型的 ServiceManifest.xml 文件,该文件引用服务类型的代码、静态数据和配置包。A service package is a disk directory containing the service type's ServiceManifest.xml file, which references the code, static data, and configuration packages for the service type. 例如,服务包可能引用构成数据库服务的代码、静态数据和配置包。For example, a service package could refer to the code, static data, and configuration packages that make up a database service.

应用程序类型是分配给服务类型集合的名称/版本。An application type is the name/version assigned to a collection of service types. 这在 ApplicationManifest.xml 文件中定义。This is defined in an ApplicationManifest.xml file.

Service Fabric 应用程序类型和服务类型

应用程序包是一个磁盘目录,其中包含应用程序类型的 ApplicationManifest.xml 文件引用构成应用程序类型的每个服务类型的服务包。The application package is a disk directory which contains the application type's ApplicationManifest.xml file, which references the service packages for each service type that makes up the application type. 例如,电子邮件应用程序类型的应用程序包可能包含对队列服务包、前端服务包和数据库服务包的引用。For example, an application package for an email application type could contain references to a queue service package, a frontend service package, and a database service package.

应用程序包目录中的文件将复制到 Service Fabric 群集的映像存储。The files in the application package directory are copied to the Service Fabric cluster's image store. 然后,可基于此应用程序类型,创建在群集内运行的命名应用程序。You can then create a named application from this application type, which then runs within the cluster. 创建命名的程序后,可以从一个应用程序类型的服务类型创建命名的服务。After creating a named application, you can create a named service from one of the application type's service types.

运行时:群集和节点、命名的应用程序、命名的服务、分区和副本Run time: clusters and nodes, named applications, named services, partitions, and replicas

Service Fabric 群集是一组通过网络连接在一起的虚拟机或物理计算机,微服务会在其中部署和管理。A Service Fabric cluster is a network-connected set of virtual or physical machines into which your microservices are deployed and managed. 群集可以扩展到成千上万台计算机。Clusters can scale to thousands of machines.

属于群集一部分的计算机或 VM 称为节点。A machine or VM that is part of a cluster is called a node. 需为每个节点分配节点名称(字符串)。Each node is assigned a node name (a string). 节点具有各种特征,如放置属性。Nodes have characteristics such as placement properties. 每个计算机或 VM 都有一个自动启动 Windows 服务 FabricHost.exe,此服务在引导时开始运行,然后启动两个可执行文件:Fabric.exeFabricGateway.exeEach machine or VM has an auto-start Windows service, FabricHost.exe, which starts running upon boot and then starts two executables: Fabric.exe and FabricGateway.exe. 这两个可执行文件构成了节点。These two executables make up the node. 在开发或测试方案中,可以通过运行 Fabric.exeFabricGateway.exe 的多个实例,在单台计算机或 VM 上托管多个节点。For development or testing scenarios, you can host multiple nodes on a single machine or VM by running multiple instances of Fabric.exe and FabricGateway.exe.

命名应用程序是执行一个或多个特定功能的命名服务的集合。A named application is a collection of named services that performs a certain function or functions. 服务执行完整且独立的功能(它们可以独立于其他服务启动和运行),并由代码、配置和数据组成。A service performs a complete and standalone function (it can start and run independently of other services) and is composed of code, configuration, and data. 将应用程序包复制到映像存储后,可以通过指定应用程序包的应用程序类型(使用其名称/版本)在群集内创建应用程序的实例。After an application package is copied to the image store, you create an instance of the application within the cluster by specifying the application package's application type (using its name/version). 将为每个应用程序类型实例分配一个如下所示的 URI 名称:fabric:/MyNamedAppEach application type instance is assigned a URI name that looks like fabric:/MyNamedApp. 在群集中,可以从单个应用程序类型创建多个命名应用程序。Within a cluster, you can create multiple named applications from a single application type. 还可以从不同的应用程序类型创建命名应用程序。You can also create named applications from different application types. 可单独管理每个命名应用程序并设置其版本。Each named application is managed and versioned independently.

创建命名应用程序后,可以通过指定服务类型(使用其名称/版本),在群集中创建应用程序服务类型(命名服务)之一的实例。After creating a named application, you can create an instance of one of its service types (a named service) within the cluster by specifying the service type (using its name/version). 需为每个服务类型实例分配一个 URI 名称,该名称归并到实例的命名应用程序的 URI 之下。Each service type instance is assigned a URI name scoped under its named application's URI. 例如,如果在命名应用程序“MyNamedApp”中创建命名服务“MyDatabase”,则 URI 将类似于:fabric:/MyNamedApp/MyDatabaseFor example, if you create a "MyDatabase" named service within a "MyNamedApp" named application, the URI looks like: fabric:/MyNamedApp/MyDatabase. 在一个命名应用程序中可以创建一个或多个命名服务。Within a named application, you can create one or more named services. 每个命名服务可以有自身的分区方案和实例/副本计数。Each named service can have its own partition scheme and instance/replica counts.

有两种服务类型:无状态服务和有状态服务。There are two types of services: stateless and stateful. 无状态服务不在服务中存储状态。Stateless services do not store state within the service. 无状态服务根本没有持久性存储,或者将持久性状态存储在外部存储服务中,例如,存储在 Azure 存储、Azure SQL 数据库或 Azure Cosmos DB 中。Stateless services have no persistent storage at all or store persistent state in an external storage service such as Azure Storage, Azure SQL Database, or Azure Cosmos DB. 有状态服务将状态存储在服务内,并使用 Reliable Collections 或 Reliable Actors 编程模型来管理状态。A stateful service stores state within the service and uses Reliable Collections or Reliable Actors programming models to manage state.

创建命名服务时,需要指定一个分区方案。When creating a named service, you specify a partition scheme. 包含大量状态的服务将跨分区拆分数据。Services with large amounts of state split the data across partitions. 每个分区负责服务完整状态的一部分(分布在群集的节点上)。Each partition is responsible for a portion of the complete state of the service, which is spread across the cluster's nodes.

下图显示应用程序和服务实例、分区与副本之间的关系。The following diagram shows the relationship between applications and service instances, partitions, and replicas.

服务中的分区和副本

分区、缩放和可用性Partitioning, scaling, and availability

分区并不是 Service Fabric 所独有的。Partitioning is not unique to Service Fabric. 一种众所周知的分区形式是数据分区,也称为分片。A well known form of partitioning is data partitioning, or sharding. 包含大量状态的有状态服务跨分区拆分数据。Stateful services with large amounts of state split the data across partitions. 每个分区负责服务完整状态的一部分。Each partition is responsible for a portion of the complete state of the service.

每个分区的副本分布在群集的节点上,以便命名服务状态进行缩放The replicas of each partition are spread across the cluster's nodes, which allows your named service's state to scale. 随着数据需求的增长,分区也会增长,Service Fabric 会在节点间重新平衡分区,以高效利用硬件资源。As the data needs grow, partitions grow, and Service Fabric rebalances partitions across nodes to make efficient use of hardware resources. 如果向群集添加新节点,Service Fabric 会在新增加的节点间重新平衡分区副本。If you add new nodes to the cluster, Service Fabric will rebalance the partition replicas across the increased number of nodes. 应用程序总体性能提高,访问内存的争用减少。Overall application performance improves and contention for access to memory decreases. 如果没有高效使用群集中的节点,可以减少群集中节点的数量。If the nodes in the cluster are not being used efficiently, you can decrease the number of nodes in the cluster. Service Fabric 会再次在减少的节点间重新平衡分区副本以更加充分使用每个节点上的硬件。Service Fabric again rebalances the partition replicas across the decreased number of nodes to make better use of the hardware on each node.

在分区中,无状态命名服务具有实例,而有状态命名服务具有副本。Within a partition, stateless named services have instances while stateful named services have replicas. 通常,无状态命名服务只有一个分区,因为它们没有内部状态。Usually, stateless named services only ever have one partition since they have no internal state. 分区实例提供可用性The partition instances provide for availability. 如果一个实例失败,其他实例可继续正常运行,然后 Service Fabric 会创建新的实例。If one instance fails, other instances continue to operate normally and then Service Fabric creates a new instance. 有状态命名服务在副本中保持其状态,每个分区都有自己的副本集。Stateful named services maintain their state within replicas and each partition has its own replica set. 在一个副本(以下称为“主副本”)上执行读取和写入操作。Read and write operations are performed at one replica (called the Primary). 因写入操作发生的状态更改将复制到其他多个副本(以下称为活动辅助副本)。Changes to state from write operations are replicated to multiple other replicas (called Active Secondaries). 如果某个副本失败,Service Fabric 将从现有副本创建新副本。Should a replica fail, Service Fabric builds a new replica from the existing replicas.

无状态和有状态 Service Fabric 微服务Stateless and stateful microservices for Service Fabric

使用 Service Fabric,可以生成包含微服务或容器的应用程序。Service Fabric enables you to build applications that consist of microservices or containers. 无状态微服务(例如网关、Web 代理)不维护除请求及其来自服务的响应之外任何可变状态。Stateless microservices (such as protocol gateways and web proxies) do not maintain a mutable state outside a request and its response from the service. Azure 云服务辅助角色是无状态服务的一个示例。Azure Cloud Services worker roles are an example of a stateless service. 有状态微服务(例如,用户帐户、数据库、设备、购物车、队列)维护除请求及其响应之外的可变、授权状态。Stateful microservices (such as user accounts, databases, devices, shopping carts, and queues) maintain a mutable, authoritative state beyond the request and its response. 当今的 Internet 规模应用程序包含无状态和有状态微服务的组合。Today's Internet-scale applications consist of a combination of stateless and stateful microservices.

Service Fabric 的关键区别在于,大力注重使用内置编程模型或容器化有状态服务生成有状态服务。A key differentiation with Service Fabric is its strong focus on building stateful services, either with the built in programming models or with containerized stateful services. 应用程序方案介绍了可使用有状态服务的方案。The application scenarios describe the scenarios where stateful services are used.

为何要将有状态和无状态的微服务一同使用?Why have stateful microservices along with stateless ones? 有以下两个主要原因:The two main reasons are:

  • 在同一台计算机上禁用代码和数据,可以生成高吞吐量、低延迟、容错联机事务处理 (OLTP) 服务。You can build high-throughput, low-latency, failure-tolerant online transaction processing (OLTP) services by keeping code and data close on the same machine. 一些示例包括互动商店、搜索、物联网 (IoT) 系统、交易系统、信用卡处理和欺诈检测系统,以及个人档案管理。Some examples are interactive storefronts, search, Internet of Things (IoT) systems, trading systems, credit card processing and fraud detection systems, and personal record management.
  • 可以简化应用程序设计。You can simplify application design. 有状态微服务删除了传统上需要用来处理纯无状态应用程序的可用性和延迟需求的附加队列和缓存。Stateful microservices remove the need for additional queues and caches, which are traditionally required to address the availability and latency requirements of a purely stateless application. 有状态服务原本就具有高可用性和低延迟,减少了在应用程序中要作为一个整体进行管理的移动部件的数量。Stateful services are naturally high-availability and low-latency, which reduces the number of moving parts to manage in your application as a whole.

支持的编程模型Supported programming models

Service Fabric 提供了多种方法来编写和管理服务。Service Fabric offers multiple ways to write and manage your services. 服务可以使用 Service Fabric API 来充分利用平台的功能和应用程序框架。Services can use the Service Fabric APIs to take full advantage of the platform's features and application frameworks. 服务还可以是采用任何语言编写的任意编译可执行程序,并在 Service Fabric 群集上托管。Services can also be any compiled executable program written in any language and hosted on a Service Fabric cluster. 有关详细信息,请参阅支持的编程模型For more information, see Supported programming models.

容器Containers

默认情况下,Service Fabric 以进程形式部署和激活这些服务。By default, Service Fabric deploys and activates services as processes. Service Fabric 还可以在容器中部署服务。Service Fabric can also deploy services in containers. 重要的是,可以在同一应用程序中混合进程中的服务和容器中的服务。Importantly, you can mix services in processes and services in containers in the same application. Service Fabric 支持在 Windows Server 2016 上部署 Linux 容器 和 Windows 容器。Service Fabric supports deployment of Linux containers and Windows containers on Windows Server 2016. 可以在容器中部署现有应用程序、无状态服务或有状态服务。You can deploy existing applications, stateless services, or stateful services in containers.

Reliable ServicesReliable Services

Reliable Services 是一个用于编写服务的轻型框架,这些服务与 Service Fabric 平台集成并且受益于完整的平台功能集。Reliable Services is a lightweight framework for writing services that integrate with the Service Fabric platform and benefit from the full set of platform features. Reliable Services 可以是无状态的(与大多数服务平台类似,例如 Web 服务器或 Azure 云服务中的辅助角色),此时状态保存在外部解决方案中,例如 Azure DB 或 Azure 表存储。Reliable Services can be stateless (similar to most service platforms, such as web servers or Worker Roles in Azure Cloud Services), where state is persisted in an external solution, such as Azure DB or Azure Table Storage. Reliable Services 也可以是有状态的,此时状态使用 Reliable Collections 直接保存在服务中。Reliable Services can also be stateful, where state is persisted directly in the service itself using Reliable Collections. 通过复制使状态具有高可用性,以及通过分区来分布状态,所有状态由 Service Fabric 自动管理。State is made highly available through replication and distributed through partitioning, all managed automatically by Service Fabric.

Reliable ActorsReliable Actors

Reliable Actor 框架在 Reliable Services 的基础上构建,是根据执行组件设计模式实现虚拟执行组件模式的应用程序框架。Built on top of Reliable Services, the Reliable Actor framework is an application framework that implements the Virtual Actor pattern, based on the actor design pattern. Reliable Actor 框架使用称为执行组件的单线程执行的独立的计算单元和状态。The Reliable Actor framework uses independent units of compute and state with single-threaded execution called actors. Reliable Actor 框架为执行组件提供内置通信,以及提供预设的状态暂留和扩展配置。The Reliable Actor framework provides built in communication for actors and pre-set state persistence and scale-out configurations.

ASP.NET CoreASP.NET Core

Service Fabric 与 ASP.NET Core 集成,作为用于生成 Web 和 API 应用程序的第一类编程模型。Service Fabric integrates with ASP.NET Core as a first class programming model for building web and API applications. 在 Service Fabric 中可通过两种不同方法使用 ASP.NET Core:ASP.NET Core can be used in two different ways in Service Fabric:

  • 作为来宾可执行文件托管。Hosted as a guest executable. 这主要用于在 Service Fabric 上运行现有 ASP.NET Core 应用程序,无需更改代码。This is primarily used to run existing ASP.NET Core applications on Service Fabric with no code changes.
  • 在 Reliable Service 内部运行。Run inside a Reliable Service. 这可改善与 Service Fabric 运行时的集成,实现有状态的 ASP.NET Core 服务。This allows better integration with the Service Fabric runtime and allows stateful ASP.NET Core services.

来宾可执行文件Guest executables

来宾可执行文件是(采用任何语言编写的)任意现有可执行文件,并在 Service Fabric 群集及其他服务上托管。A guest executable is an existing, arbitrary executable (written in any language) hosted on a Service Fabric cluster alongside other services. 来宾可执行文件不直接与 Service Fabric API 集成。Guest executables do not integrate directly with Service Fabric APIs. 不过,它们仍受益于平台提供的功能,如自定义运行状况和负载报表以及服务可发现性(通过调用 REST API)。However they still benefit from features the platform offers, such as custom health and load reporting and service discoverability by calling REST APIs. 它们还具有完整的应用程序生命周期支持。They also have full application lifecycle support.

应用程序生命周期Application lifecycle

与其他平台一样,Service Fabric 上的应用程序通常会经历以下几个阶段:设计、开发、测试、部署、升级、维护和删除。As with other platforms, an application on Service Fabric usually goes through the following phases: design, development, testing, deployment, upgrade, maintenance, and removal. Service Fabric 为云应用程序的整个应用程序生命周期提供一流的支持:从开发到部署、到日常管理和维护,再到最终解除授权。Service Fabric provides first-class support for the full application lifecycle of cloud applications, from development through deployment, daily management, and maintenance to eventual decommissioning. 服务模型使多个不同角色可以独立参与到应用程序生命周期中。The service model enables several different roles to participate independently in the application lifecycle. Service Fabric 应用程序生命周期一文提供了有关 API 的概述,以及在 Service Fabric 应用程序生命周期的各个阶段,它们是如何被不同角色所使用的。Service Fabric application lifecycle provides an overview of the APIs and how they are used by the different roles throughout the phases of the Service Fabric application lifecycle.

可以使用 PowerShell cmdletCLI 命令C# APIJava APIREST API 管理整个应用生命周期。The entire app lifecycle can be managed using PowerShell cmdlets, CLI commands, C# APIs, Java APIs, and REST APIs. 还可以使用 Azure PipelinesJenkins 等工具来设置持续集成/持续部署管道。You can also set up continuous integration/continuous deployment pipelines using tools such as Azure Pipelines or Jenkins.

测试应用程序和服务Test applications and services

若要创建真正的云规模服务,请务必确保应用程序和服务能够经受住现实中发生的故障。To create truly cloud-scale services, it is critical to verify that your applications and services can withstand real-world failures. 故障分析服务是在 Service Fabric 基础上专为测试服务构建的。The Fault Analysis Service is designed for testing services that are built on Service Fabric. 借助故障分析服务,可以引入有意义的故障,并对应用程序运行完整的测试方案。With the Fault Analysis Service, you can induce meaningful faults and run complete test scenarios against your applications. 这些故障和方案将执行并验证服务在整个生命周期内要经历的大量状态和转换,所有一切都以受控、安全且一致的方式进行。These faults and scenarios exercise and validate the numerous states and transitions that a service will experience throughout its lifetime, all in a controlled, safe, and consistent manner.

操作使用单独故障针对某个服务进行测试。Actions target a service for testing using individual faults. 服务开发人员可将这些操作用作构造块来编写复杂的方案。A service developer can use these as building blocks to write complicated scenarios. 模拟故障的示例包括:Examples of simulated faults are:

  • 重新启动一个节点以模拟任意数量的重新启动计算机或 VM 的情形。Restart a node to simulate any number of situations where a machine or VM is rebooted.
  • 移动有状态服务的一个副本以模拟负载均衡、故障转移或应用程序升级。Move a replica of your stateful service to simulate load balancing, failover, or application upgrade.
  • 在一个有状态服务上调用仲裁丢失以创建一种因为没有“足够”的“备份”或“辅助”副本来接收新的数据而无法继续写操作的情形。Invoke quorum loss on a stateful service to create a situation where write operations can't proceed because there aren't enough "back-up" or "secondary" replicas to accept new data.
  • 在一个有状态服务上调用数据丢失以创建一种所有内存中的状态都被完全清除的情形。Invoke data loss on a stateful service to create a situation where all in-memory state is completely wiped out.

方案是由一个或多个操作组成的复杂操作。Scenarios are complex operations composed of one or more actions. 故障分析服务提供两种内置的完整方案:The Fault Analysis Service provides two built-in complete scenarios:

  • 混沌方案 - 在整个群集模拟连续交叉出现的故障(包括常规故障和非常规故障),时间跨度很长。Chaos scenario- simulates continuous, interleaved faults (both graceful and ungraceful) throughout the cluster over extended periods of time.
  • 故障转移方案 - 混沌测试方案针对特定服务分区的一个版本,同时不影响其他服务。Failover scenario- a version of the chaos test scenario that targets a specific service partition while leaving other services unaffected.

群集Clusters

Service Fabric 群集是一组通过网络连接在一起的虚拟机或物理计算机,你的微服务将在其中部署和管理。A Service Fabric cluster is a network-connected set of virtual or physical machines into which your microservices are deployed and managed. 群集可以扩展到成千上万台计算机。Clusters can scale to thousands of machines. 群集中的计算机或 VM 称为群集节点。A machine or VM that is part of a cluster is called a cluster node. 需为每个节点分配节点名称(字符串)。Each node is assigned a node name (a string). 节点具有各种特征,如放置属性。Nodes have characteristics such as placement properties. 每个计算机或 VM 都有一个自动启动服务 FabricHost.exe,此服务在引导时开始运行,并启动两个可执行文件:Fabric.exe 和 FabricGateway.exe。Each machine or VM has an auto-start service, FabricHost.exe, which starts running upon boot and then starts two executables: Fabric.exe and FabricGateway.exe. 这两个可执行文件构成了节点。These two executables make up the node. 在测试方案中,可以通过运行 Fabric.exeFabricGateway.exe 的多个实例,在单台计算机或 VM 上托管多个节点。For testing scenarios, you can host multiple nodes on a single machine or VM by running multiple instances of Fabric.exe and FabricGateway.exe.

可在运行 Windows Server 或 Linux 的虚拟机或物理计算机上创建 Service Fabric 群集。Service Fabric clusters can be created on virtual or physical machines running Windows Server or Linux. 可在包含一组互连 Windows Server 或 Linux 计算机(本地计算机、Microsoft Azure 计算机或任何云提供商的计算机)的任何环境中部署和运行 Service Fabric 应用程序。You are able to deploy and run Service Fabric applications in any environment where you have a set of Windows Server or Linux computers that are interconnected: on-premises, on Microsoft Azure, or on any cloud provider.

Azure 上的群集Clusters on Azure

在 Azure 上运行 Service Fabric 群集可提供与其他 Azure 功能和服务的集成,这样可使群集的操作和管理更容易且更可靠。Running Service Fabric clusters on Azure provides integration with other Azure features and services, which makes operations and management of the cluster easier and more reliable. 群集是 Azure 资源管理器资源,因此可以像 Azure 中的其他资源一样对群集进行建模。A cluster is an Azure Resource Manager resource, so you can model clusters like any other resources in Azure. Resource Manager 还可以轻松管理群集作为单个单元使用的所有资源。Resource Manager also provides easy management of all resources used by the cluster as a single unit. Azure 上的群集已集成了 Azure 诊断和 Azure Monitor 日志。Clusters on Azure are integrated with Azure diagnostics and Azure Monitor logs. 群集节点类型是虚拟机规模集,因此自动缩放功能是内置的。Cluster node types are virtual machine scale sets, so autoscaling functionality is built in.

可以通过 Azure 门户模板Visual Studio 在 Azure 上创建群集。You can create a cluster on Azure through the Azure portal, from a template, or from Visual Studio.

如同在 Windows 上一样,可以使用 Linux 上的 Service Fabric 在 Linux 上构建、部署和管理高可用性、高度可缩放的应用程序。Service Fabric on Linux enables you to build, deploy, and manage highly available, highly scalable applications on Linux just as you would on Windows. Service Fabric 框架(Reliable Services 和 Reliable Actors)除了可在 C# (.NET Core) 中使用以外,也能在 Java on Linux 中使用。The Service Fabric frameworks (Reliable Services and Reliable Actors) are available in Java on Linux, in addition to C# (.NET Core). 还可以使用任何语言或框架来构建来宾可执行的服务You can also build guest executable services with any language or framework. 还支持协调 Docker 容器。Orchestrating Docker containers is also supported. Docker 容器可以运行使用 Service Fabric 框架的来宾可执行文件或本机 Service Fabric 服务。Docker containers can run guest executables or native Service Fabric services, which use the Service Fabric frameworks. 有关详细信息,请参阅 Linux 上的 Service FabricFor more information, read about Service Fabric on Linux.

某些在 Windows 上受支持的功能,在 Linux 上不受支持。There are some features that are supported on Windows, but not on Linux. 若要了解详细信息,请参阅 Linux 上的 Service Fabric 与 Windows 上的 Service Fabric 之间的差异To learn more, read Differences between Service Fabric on Linux and Windows.

独立群集Standalone clusters

Service Fabric 提供一个安装包,用于在本地或者任何云提供程序上创建独立的 Service Fabric 群集。Service Fabric provides an installation package for you to create standalone Service Fabric clusters on-premises or on any cloud provider. 使用独立群集可随时随地托管群集。Standalone clusters give you the freedom to host a cluster wherever you want. 如果数据受符合性或法规约束,或者需要将数据保留在本地,可以托管自己的群集和应用程序。If your data is subject to compliance or regulatory constraints, or you want to keep your data local, you can host your own cluster and applications. Service Fabric 应用程序可在多个托管环境中运行,而不发生任何变化。因此,在应用程序生成方面的知识在各个托管环境中都适用。Service Fabric applications can run in multiple hosting environments with no changes, so your knowledge of building applications carries over from one hosting environment to another.

创建第一个独立的 Service Fabric 群集Create your first Service Fabric standalone cluster

尚不支持 Linux 独立群集。Linux standalone clusters are not yet supported.

群集安全性Cluster security

必须保护群集以防止未经授权的用户连接到群集,特别是群集上正在运行生产工作负荷时。Clusters must be secured to prevent unauthorized users from connecting to your cluster, especially when it has production workloads running on it. 虽然可以创建不安全的群集,但这样做会导致在向公共 Internet 公开管理终结点时,匿名用户可与它建立连接。Although it is possible to create an unsecured cluster, doing so allows anonymous users to connect to it if management endpoints are exposed to the public internet. 无法以后在不安全的群集上启用安全性:群集安全性在群集创建时启用。It is not possible to later enable security on an unsecured cluster: cluster security is enabled at cluster creation time.

群集安全方案包括:The cluster security scenarios are:

  • 节点到节点安全性Node-to-node security
  • 客户端到节点安全性Client-to-node security
  • 基于角色的访问控制 (RBAC)Role-based access control (RBAC)

有关详细信息,请阅读保护群集For more information, read Secure a cluster.

缩放Scaling

如果向群集添加新节点,Service Fabric 会在新增加的节点间重新平衡分区副本和实例。If you add new nodes to the cluster, Service Fabric rebalances the partition replicas and instances across the increased number of nodes. 应用程序总体性能提高,访问内存的争用减少。Overall application performance improves and contention for access to memory decreases. 如果没有高效使用群集中的节点,可以减少群集中节点的数量。If the nodes in the cluster are not being used efficiently, you can decrease the number of nodes in the cluster. Service Fabric 会再次在减少的节点间重新平衡分区副本和实例以更加充分利用每个节点上的硬件。Service Fabric again rebalances the partition replicas and instances across the decreased number of nodes to make better use of the hardware on each node. 可以在 Azure 上手动以编程方式扩展群集。You can scale clusters on Azure either manually or programmatically. 可以手动扩展独立群集。Standalone clusters can be scaled manually.

群集升级Cluster upgrades

我们会定期发布新版本的 Service Fabric 运行时。Periodically, new versions of the Service Fabric runtime are released. 在群集上执行运行时或结构升级,以便始终运行受支持的版本Perform runtime, or fabric, upgrades on your cluster so that you are always running a supported version. 除了结构升级,还可以更新群集配置(例如证书或应用程序端口)。In addition to fabric upgrades, you can also update cluster configuration such as certificates or application ports.

Service Fabric 群集是你拥有的,但部分由 Microsoft 管理的资源。A Service Fabric cluster is a resource that you own, but is partly managed by Microsoft. Microsoft 负责修补基础 OS 并在群集上执行结构升级。Microsoft is responsible for patching the underlying OS and performing fabric upgrades on your cluster. 当 Microsoft 发布新版本时,可以将群集设置为接收自动结构升级,或选择所需的受支持结构版本。You can set your cluster to receive automatic fabric upgrades, when Microsoft releases a new version, or choose to select a supported fabric version that you want. 可通过 Azure 门户或 Resource Manager 设置结构和配置升级。Fabric and configuration upgrades can be set through the Azure portal or through Resource Manager. 有关详细信息,请参阅升级 Service Fabric 群集For more information, read Upgrade a Service Fabric cluster.

独立群集是你完全拥有的资源。A standalone cluster is a resource that you entirely own. 负责修补基础 OS 和启动结构升级。You are responsible for patching the underlying OS and initiating fabric upgrades. 如果群集可以连接到 https://www.microsoft.com/download,可以将群集设置为自动下载并预配新的 Service Fabric 运行时包。If your cluster can connect to https://www.microsoft.com/download, you can set your cluster to automatically download and provision the new Service Fabric runtime package. 然后会启动升级。You would then initiate the upgrade. 如果群集无法访问 https://www.microsoft.com/download,可以从连接 Internet 的计算机手动下载新的运行时包,并启动升级。If your cluster can't access https://www.microsoft.com/download, you can manually download the new runtime package from an internet connected machine and then initiate the upgrade. 有关详细信息,请参阅升级独立 Service Fabric 群集For more information, read Upgrade a standalone Service Fabric cluster.

运行状况监视Health monitoring

Service Fabric 引入了运行状况模型,用于在特定实体上标记不正常的群集和应用程序状态(例如群集节点和服务副本)。Service Fabric introduces a health model designed to flag unhealthy cluster and application conditions on specific entities (such as cluster nodes and service replicas). 运行状况模型使用运行状况报告器(系统组件和监视器)。The health model uses health reporters (system components and watchdogs). 其目标是实现轻松快捷的诊断和修复。The goal is easy and fast diagnosis and repair. 服务写入程序需要预先考虑运行状况和如何设计运行状况报告Service writers need to think upfront about health and how to design health reporting. 应报告任何可能会影响运行状况的条件,尤其是如果它有助于标记出接近根源的问题。Any condition that can impact health should be reported on, especially if it can help flag problems close to the root. 在生产中大规模启动并运行服务后,运行状况信息可以减少调试和调查工作所需的时间和精力。The health information can save time and effort on debugging and investigation once the service is up and running at scale in production.

Service Fabric 报告器可监视感兴趣的已标识条件。The Service Fabric reporters monitor identified conditions of interest. 它们会根据其本地视图报告这些条件。They report on those conditions based on their local view. 运行状况存储可汇总所有报告器发送的运行状况数据,从而确定实体的全局运行状况是否正常。The health store aggregates health data sent by all reporters to determine whether entities are globally healthy. 该模型应具有功能丰富、灵活且易于使用的特点。The model is intended to be rich, flexible, and easy to use. 运行状况报告的质量决定了群集运行状况视图的准确度。The quality of the health reports determines the accuracy of the health view of the cluster. 错误显示不正常问题的误报会对升级或其他使用运行状况数据的服务产生负面影响。False positives that wrongly show unhealthy issues can negatively impact upgrades or other services that use health data. 修复服务和警报机制就是此类服务的例子。Examples of such services are repair services and alerting mechanisms. 因此,提供报表时需多加考量,才能让其以尽可能最佳的方式捕获感兴趣的条件。Therefore, some thought is needed to provide reports that capture conditions of interest in the best possible way.

可以基于以下内容完成报告:Reporting can be done from:

  • 受监视的 Service Fabric 服务副本或实例。The monitored Service Fabric service replica or instance.
  • 内部监视器部署为 Service Fabric 服务(例如,可监视状态和问题报告的 Service Fabric 无状态服务)。Internal watchdogs deployed as a Service Fabric service (for example, a Service Fabric stateless service that monitors conditions and issues reports). 可以在所有节点上部署监视器,也可以将监视器与受监视的服务关联。The watchdogs can be deployed on all nodes or can be affinitized to the monitored service.
  • 在 Service Fabric 节点上运行,但未以 Service Fabric 服务形式实现的内部监视器。Internal watchdogs that run on the Service Fabric nodes but are not implemented as Service Fabric services.
  • 从 Service Fabric 群集外探测资源的外部监视器(例如,诸如 Gomez 之类的监视服务)。External watchdogs that probe the resource from outside the Service Fabric cluster (for example, monitoring service like Gomez).

Service Fabric 组件报告包含群集中所有实体的运行状况。Out of the box, Service Fabric components report health on all entities in the cluster. 系统运行状况报告提供有关群集和应用程序功能的可见性,并且通过运行状况标记问题。System health reports provide visibility into cluster and application functionality and flag issues through health. 对于应用程序和服务,系统运行状况报告从 Service Fabric 运行时的角度验证实体得到实现并且正常运行。For applications and services, system health reports verify that entities are implemented and are behaving correctly from the perspective of the Service Fabric runtime. 报告不对服务的业务逻辑进行任何运行状况监视,也不检测已停止响应的进程。The reports do not provide any health monitoring of the business logic of the service or detect processes that have stopped responding. 若要添加特定于服务逻辑的运行状况信息,请在服务中执行自定义运行状况报告To add health information specific to your service's logic, implement custom health reporting in your services.

Service Fabric 提供了多种方式查看在运行状况存储中聚合的运行状况报告Service Fabric provides multiple ways to view health reports aggregated in the health store:

监视和诊断Monitoring and diagnostics

监视和诊断对任何环境中的开发、测试和部署应用程序和服务都至关重要。Monitoring and diagnostics are critical to developing, testing, and deploying applications and services in any environment. 监视和诊断有助于确保应用程序和服务在本地开发环境或生产环境中按预期运行,计划和实现监视和诊断时,Service Fabric 解决方案效果最佳。Service Fabric solutions work best when you plan and implement monitoring and diagnostics that help ensure applications and services are working as expected in a local development environment or in production.

监视和诊断的主要目标是:The main goals of monitoring and diagnostics are to:

  • 检测和诊断硬件和基础结构问题Detect and diagnose hardware and infrastructure issues
  • 检测软件和应用问题,减少服务停机时间Detect software and app issues, reduce service downtime
  • 了解资源消耗情况,帮助推动运营决策Understand resource consumption and help drive operations decisions
  • 优化应用程序、服务和基础结构性能Optimize application, service, and infrastructure performance
  • 生成业务见解并确定改进区域Generate business insights and identify areas of improvement

监视和诊断的整体工作流程分为三个步骤:The overall workflow of monitoring and diagnostics consists of three steps:

  1. 事件生成:这包括基础结构(群集)级、平台级、应用程序/服务级事件(日志、跟踪、自定义事件)Event generation: this includes events (logs, traces, custom events) at the infrastructure (cluster), platform, and application / service level
  2. 事件聚合:需要先收集和聚合生成的事件才能显示这些事件Event aggregation: generated events need to be collected and aggregated before they can be displayed
  3. 分析:需直观显示事件并能够以某种格式访问事件,以便按需进行分析和显示Analysis: events need to be visualized and accessible in some format, to allow for analysis and display as needed

多个产品可用于以上三个方面,你也可以为每个方面选择不同的技术。Multiple products are available that cover these three areas, and you are free to choose different technologies for each. 有关详细信息,请阅读 Azure Service Fabric 的监视和诊断功能For more information, read Monitoring and diagnostics for Azure Service Fabric.

后续步骤Next steps