Application Delivery Management

这篇文章已经过机器翻译.放弃

用于创建基本负载平衡配置的样书

在前面的示例中,您构建了一个基本样书来创建负载平衡虚拟服务器。可以用不同的名称保存此样书,然后对其更新以包含用于基本负载平衡配置的其他参数和组件。将此样书文件保存为 basic-lb-config.yaml

在本节中,将设计一个新样本,用于创建由负载平衡虚拟服务器、服务组和一组服务组成的负载平衡配置。它还将服务绑定至服务组,并将服务组绑定至虚拟服务器。

标题

要构建此样本,必须先更新标头部分。此部分与为负载平衡虚拟服务器样本创建的标头部分类似。在标头部分中,将 name 值更改为 basic-lb-config。此外,更新 descriptiondisplay-name 以适当说明此样书。不必更改 namespaceversion 值。因为已更改了名称,所以 name、namespace 和 version 组合构成了此样书在系统中的唯一标识符。

name: basic-lb-config description: This StyleBook defines a simple load balancing configuration. display-name: Load Balancing Configuration namespace: com.example.stylebooks schema-version: "1.0" version: "0.1"

导入样书

import-stylebooks 部分保持不变。它引用 netscaler.nitro.config 命名空间以使用 Nitro 配置对象。

import-stylebooks: - namespace: netscaler.nitro.config prefix: ns version: "10.5"

参数

必须更新 parameters 部分以添加两个其他参数来定义一组服务或服务器以及服务侦听的端口。前三个参数 name、ip 和 lb-alg 保持不变。

parameters: - name: name type: string label: Application Name description: Name of the application configuration required: true - name: ip type: ipaddress label: Application Virtual IP (VIP) description: Application VIP that the clients access required: true - name: lb-alg type: string label: LoadBalancing Algorithm description: Choose the load balancing algorithm used for load balancing client requests between the application servers. allowed-values: - ROUNDROBIN - LEASTCONNECTION default: ROUNDROBIN - name: svc-servers type: ipaddress[] label: Application Server IPs description: The IP addresses of all the servers of this application required: true - name: svc-port type: tcp-port label: Server Port description: The TCP port open on the application servers to receive requests. default: 80

在此示例中,添加了参数 svc-servers 以接受代表应用程序后端服务器的服务 IP 地址列表。这是必需参数,由 required: true 指明。第二个参数 svc-port 表示服务器侦听的端口号。如果用户未指定,svc-port 参数的默认端口号是 80。

组件

必须还要更新 components 部分以定义其他组件,以便它们可以使用两个新参数并构建完整的负载平衡配置。

例如,必须按如下所示编写 components 部分:

components: - name: lbvserver-comp type: ns::lbvserver properties: name: $parameters.name + "-lb" servicetype: HTTP ipv46: $parameters.ip port: 80 lbmethod: $parameters.lb-alg components: - name: svcg-comp type: ns::servicegroup properties: name: $parameters.name + "-svcgrp" servicetype: HTTP components: - name: lbvserver-svg-binding-comp type: ns::lbvserver_servicegroup_binding properties: name: $parent.parent.properties.name servicegroupname: $parent.properties.name - name: members-svcg-comp type: ns::servicegroup_servicegroupmember_binding repeat: $parameters.svc-servers repeat-item: srv properties: ip: $srv port: str($parameters.svc-port) servicegroupname: $parent.properties.name

在此示例中,原始组件 lbvserver-comp (来自前面的示例)现在有一个名为 svcg-comp的子组件。而且, svcg-comp 组件中有两个子组件。通过在一个组件里面嵌套另一个组件,嵌套的组件可以通过引用父组件中的属性来创建配置对象。嵌套的组件可以为父组件中创建的每个对象创建一个或多个对象。

svcg-comp 组件用于通过使用为资源“servicegroup”的属性提供的值在 NetScaler 实例上创建服务组。在此示例中,为 servicetype 指定静态值,而 name 从输入参数获取其值。通过使用 $parameters.name + “-svcgrp” 表示法来引用在参数部分中定义的参数名称,其中 -svcgrp 附加(连接)到用户定义的名称。

组件 svcg-comp 有两个子组件, lbvserver-svg-binding-compmembers-svcg-comp

第一个子组件 lbvserver-svg-binding-comp用于在其父组件创建的服务组与父组件创建的负载平衡虚拟服务器 (lbvserver) 之间绑定配置对象。$parent 表示法(也称为父引用)用于引用父组件中的实体。例如,servicegroupname: $parent.properties.name 指由父组件 svcg-comp 创建的服务组,name: $parent.parent.properties.name 指由父组件 lbvserver-comp 创建的虚拟服务器。

成员 svcg 组件用于将服务列表之间的配置对象绑定到父组件创建的服务组。创建多个绑定配置对象是通过使用样书的重复构造迭代参数 svc-servers 中指定的一组服务器来完成。在迭代期间,这个样书组件为服务组中的每项服务(在重复项结构中称为 srv)创建 servicegroup_servicegroupmember_binding 类型的 Nitro 配置对象,并将每个 Nitro 配置对象中的 ip属性设置为相应服务器的 IP 地址。

通常,您可以在组件中使用 重复项和重复构造来使该组件生成多个相同类型的配置对象。您可以将变量名分配给重复项构造(例如 srv),以指定迭代中的当前值。这个变量名在同一个组件的属性或子组件中被引用为$\<varname\ >,例如 $srv。

在上述示例中,使用了在组件中相互嵌套组件来轻松构造此配置。在此特殊情况下,嵌套组件不是唯一的配置构建方式。您本可以在不嵌套的情况下获得同样的结果,如下所示:

components: - name: members-svcg-comp type: ns::servicegroup_servicegroupmember_binding repeat: $parameters.svc-servers repeat-item: srv properties: ip: $srv port: str($parameters.svc-port) servicegroupname: $components.svcg-comp.properties.name - name: lbvserver-svg-binding-comp type: ns::lbvserver_servicegroup_binding properties: name: $components.lbvserver-comp.properties.name servicegroupname: $components.svcg-comp.properties.name - name: lbvserver-comp type: ns::lbvserver properties: name: $parameters.name + "-lb" servicetype: HTTP ipv46: $parameters.ip port: 80 lbmethod: $parameters.lb-alg - name: svcg-comp type: ns::servicegroup properties: name: $parameters.name + "-svcgrp" servicetype: HTTP

此处,所有组件位于相同级别(即,它们未嵌套),但得到的结果(生成的 NetScaler 配置)与前面使用的嵌套组件相同。此外,样书中组件的声明顺序不影响配置对象的创建顺序。在此示例中,尽管最后声明了组件 svcg-complbvserver-comp,但必须在构建第二个组件 lbvserver-svg-binding-comp 之前构建,因为第二个组件中有对这些组件的前向引用。

注意

按约定,样书的名称、参数、替代项、组件和输出采用小写。如果它们包含多个词语,词语以“-”字符分隔。例如“lb-bindings”、“app-name”、“rewrite-config”等。另一个约定是为组件名称添加后缀“-comp”字符串。

输出

可以添加到新样本的最后一个部分是 outputs 部分,在其中指定在此样本用于创建配置后,此样本向其用户呈现的内容(或在其他样本中)。例如,可以在输出部分指定要呈现将由此样书创建的 lbvserver 和 servicegroup 配置对象。

outputs: - name: lbvserver-comp value: $components.lbvserver-comp description: The component that builds the Nitro lbvserver configuration object - name: servicegroup-comp value: $components.svcg-comp description: The component that builds the Nitro servicegroup configuration object

样书的输出部分是可选的。样书不必返回输出。但是,如果将一些内部组件作为输出返回,导入此样书的任何样书就可以有更大的灵活性,这在创建复合样书时可以看到。

注意

最好在 outputs 部分呈现样书的整个组件,而不仅仅是组件的单个属性(例如,呈现整个 $components.lbvserver-comp,而不仅仅是名称 $components.lbvserver-comp.properties.name)。另外在输出中添加说明,解释特定输出表示的内容。

构建您的样书

现在已定义了此样书的所有必要部分,将它们全部汇聚在一起即可构建您的第二个样书。已将此样书文件保存为 basic-lb-config.yaml。Citrix 建议您使用样书页面中的内置 YAML 验证器来验证和导入 YAML 内容。

basic-lb-config.yaml 文件的完整内容再现如下:

name: basic-lb-config namespace: com.example.stylebooks version: "0.1" display-name: Load Balancing Configuration description: This StyleBook defines a simple load balancing configuration. schema-version: "1.0" import-stylebooks: - namespace: netscaler.nitro.config version: "10.5" prefix: ns parameters: - name: name type: string label: Application Name description: Give a name to the application configuration. required: true - name: ip type: ipaddress label: Application Virtual IP (VIP) description: The Application VIP that clients access required: true - name: lb-alg type: string label: LoadBalancing Algorithm description: Choose the loadbalancing algorithm (method) used for loadbalancing client requests between the application servers. allowed-values: - ROUNDROBIN - LEASTCONNECTION default: ROUNDROBIN - name: svc-servers type: ipaddress[] label: Application Server IPs description: The IP addresses of all the servers of this application required: true components: - name: lbvserver-comp type: ns::lbvserver properties: name: $parameters.name + "-lb" servicetype: HTTP ipv46: $parameters.ip port: 80 lbmethod: $parameters.lb-alg - name: svcg-comp type: ns::servicegroup properties: servicegroupname: $parameters.name + "-svcgrp" servicetype: HTTP - name: lbvserver-svg-binding-comp type: ns::lbvserver_servicegroup_binding properties: name: $components.lbvserver-comp.properties.name servicegroupname: $components.svcg-comp.properties.servicegroupname - name: members-svcg-comp type: ns::servicegroup_servicegroupmember_binding repeat: $parameters.svc-servers repeat-item: srv properties: ip: $srv port: 80 servicegroupname: $components.svcg-comp.properties.servicegroupname outputs: - name: lbvserver-comp value: $components.lbvserver-comp description: The component that builds the Nitro lbvserver configuration object - name: servicegroup-comp value: $components.svcg-comp description: The component that builds the Nitro servicegroup configuration object

要开始使用样本创建配置,您必须将其导入 NetScaler ADM,然后使用它。有关详细信息,请参阅如何使用用户定义的样书

还可以将此样书导入其他样书并使用其属性,如下一节中所述。

本内容的正式版本为英文版。部分 Cloud Software Group 文档内容采用了机器翻译,仅供您参考。Cloud Software Group 无法控制机器翻译的内容,这些内容可能包含错误、不准确或不合适的语言。对于从英文原文翻译成任何其他语言的内容的准确性、可靠性、适用性或正确性,或者您的 Cloud Software Group 产品或服务沿用了任何机器翻译的内容,我们均不作任何明示或暗示的保证,并且适用的最终用户许可协议或服务条款或者与 Cloud Software Group 签订的任何其他协议(产品或服务与已进行机器翻译的任何文档保持一致)下的任何保证均不适用。对于因使用机器翻译的内容而引起的任何损害或问题,Cloud Software Group 不承担任何责任。
用于创建基本负载平衡配置的样书