Azure 云服务定义架构(.csdef 文件)Azure Cloud Services Definition Schema (.csdef File)

服务定义文件定义应用程序的服务模型。The service definition file defines the service model for an application. 该文件包含可供云服务使用的角色的定义,指定服务终结点,并建立服务的配置设置。The file contains the definitions for the roles that are available to a cloud service, specifies the service endpoints, and establishes configuration settings for the service. 配置设置值是在服务配置文件中设置的,如云服务(经典)配置架构所述。Configuration setting values are set in the service configuration file, as described by the Cloud Service (classic) Configuration Schema.

默认情况下,Azure 诊断配置架构文件将安装到 C:\Program Files\Microsoft SDKs\Azure\.NET SDK\<version>\schemas 目录。By default, the Azure Diagnostics configuration schema file is installed to the C:\Program Files\Microsoft SDKs\Azure\.NET SDK\<version>\schemas directory. <version> 替换为 Azure SDK 的已安装版本。Replace <version> with the installed version of the Azure SDK.

服务定义文件的默认扩展名为 .csdef。The default extension for the service definition file is .csdef.

基本服务定义架构Basic service definition schema

服务定义文件必须包含一个 ServiceDefinition 元素。The service definition file must contain one ServiceDefinition element. 服务定义必须包含至少一个角色(WebRoleWorkerRole)元素。The service definition must contain at least one role (WebRole or WorkerRole) element. 它可以包含在单个定义中定义的最多 25 个角色,并且可以混合使用角色类型。It can contain up to 25 roles defined in a single definition and you can mix role types. 服务定义还包含可选的 NetworkTrafficRules 元素,该元素限制哪些角色可以与指定的内部终结点进行通信。The service definition also contains the optional NetworkTrafficRules element which restricts which roles can communicate to specified internal endpoints. 服务定义还包含可选的 LoadBalancerProbes 元素,该元素包含客户为终结点定义的运行状况探测。The service definition also contains the optional LoadBalancerProbes element which contains customer defined health probes of endpoints.

服务定义文件的基本格式如下所示。The basic format of the service definition file is as follows.

<ServiceDefinition name="<service-name>" topologyChangeDiscovery="<change-type>" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" upgradeDomainCount="<number-of-upgrade-domains>" schemaVersion="<version>">
  
  <LoadBalancerProbes>
         …
  </LoadBalancerProbes>
  
  <WebRole …>
         …
  </WebRole>
  
  <WorkerRole …>
         …
  </WorkerRole>
  
  <NetworkTrafficRules>
         …
  </NetworkTrafficRules>

</ServiceDefinition>

架构定义Schema definitions

以下主题对架构进行了介绍:The following topics describe the schema:

ServiceDefinition 元素ServiceDefinition Element

ServiceDefinition 元素是服务定义文件的顶层元素。The ServiceDefinition element is the top-level element of the service definition file.

下表介绍了 ServiceDefinition 元素的属性。The following table describes the attributes of the ServiceDefinition element.

属性Attribute 说明Description
namename 必需。Required. 服务的名称。The name of the service. 该名称在服务帐户中必须是唯一的。The name must be unique within the service account.
topologyChangeDiscoverytopologyChangeDiscovery 可选。Optional. 指定拓扑更改通知的类型。Specifies the type of topology change notification. 可能的值包括:Possible values are:

- Blast - 将更新尽早发送到所有角色实例。- Blast - Sends the update as soon as possible to all role instances. 如果选择此选项,则角色应该能够在不重启的情况下处理拓扑更新。If you choose option, the role should be able to handle the topology update without being restarted.
- UpgradeDomainWalk - 在前一个实例成功接受更新后,按顺序将更新发送到每个角色实例。- UpgradeDomainWalk - Sends the update to each role instance in a sequential manner after the previous instance has successfully accepted the update.
schemaVersionschemaVersion 可选。Optional. 指定服务定义架构的版本。Specifies the version of the service definition schema. 如果并行安装多个版本的 SDK,架构版本允许 Visual Studio 选择正确的 SDK 工具用于架构验证。The schema version allows Visual Studio to select the correct SDK tools to use for schema validation if more than one version of the SDK is installed side-by-side.
upgradeDomainCountupgradeDomainCount 可选。Optional. 指定在其中分配了此服务中的角色的升级域的数目。Specifies the number of upgrade domains across which roles in this service are allocated. 在部署服务时会将角色实例分配到升级域。Role instances are allocated to an upgrade domain when the service is deployed. 有关详细信息,请参阅更新云服务角色或部署管理虚拟机的可用性什么是云服务模型For more information, see Update a cloud service role or deployment, Manage the availability of virtual machines and What is a Cloud Service Model.

最多可以指定 20 个升级域。You can specify up to 20 upgrade domains. 如果未指定,则升级域的默认数目为 5 个。If not specified, the default number of upgrade domains is 5.