使用配置组快速配置设备
使用配置组来设置和应用在同一配置中重复使用的常用元素。
配置组概述
本主题概述了 Junos OS CLI 中的配置组和继承模型。
配置组的工作原理
通过配置组,您可以创建包含配置语句的组,并在配置的其余部分中定向继承该组的语句。同一组可以应用于配置的不同部分。一个组的配置语句的不同部分可以在配置中的不同位置继承。
通过配置组,您可以创建更小的、逻辑结构更强的配置文件,从而更轻松地配置和维护瞻博网络设备。例如,您可以对在配置中的许多位置重复的语句进行分组,例如在配置接口时。通过对语句进行分组,您可以将配置更新限制为仅该组。
您还可以在配置组中使用通配符。与通配符表达式匹配的任何对象都将继承组配置数据。
配置组机制与配置中其他位置使用的分组机制(如 BGP 组)是分开的。配置组提供了一种通用机制,可在整个配置中使用,但只有 CLI 知道该机制。执行配置指示的操作的各个软件进程接收配置的扩展形式;他们不知道配置组。
继承模型
配置组使用真正的继承,这涉及配置数据的源与该数据的目标之间的动态、持续的关系。目标会自动继承您在配置组中更改的数据值。目标不需要包含继承的信息。但是,可以在目标中覆盖继承的值,而不会影响继承它们的源。
此继承模型使您能够仅查看特定于实例的信息,而不查看继承的详细信息。配置模式下的命令管道使您能够显示继承的数据。
配置配置组
对于要继承配置语句的配置区域,必须先将语句放入配置组中。然后,将该组应用到配置层次结构中需要语句的级别。
对于要继承配置语句的配置区域:
-
将语句配置到配置组中。要配置配置组和继承,可以在层次结构级别包含 groups 语句:
[edit] groups {group-name{configuration-data; } } -
将步骤 1 中的配置组应用到配置层次结构中需要语句的级别。
将该
apply-groups [ group-names ]语句包含在配置中需要配置组中包含的配置语句的任何位置。
创建配置组
您可以通过 Junos OS CLI 创建包含配置语句的可重用组。您可以将这些组应用于配置的不同部分,在这些部分,相同的配置语句会重复多次。
在配置的不同部分应用组时,该配置部分将继承组中配置的语句。配置组遵循继承规则,其中在配置数据的源和该数据的目标之间设置动态、持续的关系。如果更改配置组中的数据值,则继承的目标会自动反映更改。
如果需要,您可以覆盖目标配置中的值,这不会影响组中的源。
此继承模型使您能够仅查看特定于实例的信息,而不查看继承的详细信息。配置模式下的命令管道使您能够显示继承的数据。例如,您可能希望将所有 ge-0/0/1 接口的 MTU 值配置为 1500。
要将所有 ge-0/0/1 接口的 MTU 值配置为 1500,请执行以下操作:
-
创建 MTU 值为 1500 的组:
[edit groups group-1] lab@vSRX3-05# show interfaces { ge-0/0/1 { unit 0 { family inet { mtu 1500; } } } } -
接下来,在接口配置中应用该组。
[edit interfaces ge-0/0/1] lab@vSRX3-05# set apply-groups group-1
-
查看继承的配置。
[edit] lab@vSRX3-05# show interfaces ge-0/0/1 | display inheritance unit 0 { family inet { ## ## '1500' was inherited from group 'group-1' ## mtu 1500; address 5.0.0.254/24; } }
如果要在配置的不同部分为接口 ge-0/0/1 配置 MTU 值,可以使用该 apply-groups 选项应用 group 语句。如果手动执行此操作,稍后想要增加 MTU,则可能必须手动更改每个接口。如果使用配置组,则可以更改组配置,从而自动更新所有关联的接口。
您还可以在配置组中使用通配符,以允许与通配符表达式匹配的任何对象继承配置数据。例如:
[edit groups group-1]
lab@vSRX3-05# show
interfaces {
ge-* {
unit 0 {
family inet {
mtu 1500;
}
}
}
}
如何应用配置组
如果您希望瞻博网络设备配置继承来自配置组的语句,请在配置中包含该 apply-groups 语句。
apply-groups [ group-names ];
如果指定多个组名称,则必须按继承优先级顺序列出名称。第一组中的配置数据优先于后续组中的数据。
对于支持多个路由引擎的设备,您可以指定 re0 和 re1 分组名称。仅当当前路由引擎位于插槽 0 中时,才会应用组 re0 中指定的配置。同样,仅当当前路由引擎位于插槽 1 中时,才会应用组 re1 中指定的配置。因此,两个路由引擎都可以使用相同的配置文件,每个引擎都只能使用适用于它的配置语句。每个 re0 或 re1 组至少包含主机名和管理接口 ()fxp0 的配置。如果每个路由引擎使用不同的管理接口,则该组还应包含备份路由器和静态路由的配置。
您只能在配置层次结构的每个特定级别包含一个 apply-groups 语句。 apply-groups 特定层级的语句会列出要添加到包含语句的配置组列表中的配置组。
在特定层级指定的值将覆盖从配置组继承的值。
嵌套 apply-groups 语句中列出的组优先于外部语句中的组。在以下示例中,BGP 邻接方 10.0.0.1 首先从组 one 继承配置数据。然后,它从组 two 和组 three继承配置数据。组 one 中的配置数据将覆盖任何其他组中的数据。仅当语句不包含在任何其他组中时,才使用来自组 ten 的数据。
apply-groups [ eight nine ten ];
protocols {
apply-groups seven;
bgp {
apply-groups [ five six ];
group some-bgp-group {
apply-groups four;
neighbor 10.0.0.1 {
apply-groups [ one two three ];
}
}
}
}
根级别是默认逻辑系统。配置为根级别定义的组时,无法将该组成功应用于层次结构级别下的 [edit logical-systems logical-system-name] 非默认逻辑系统。虽然如果应用组,设备会接受提交,但配置组不会对非默认逻辑系统生效。相反,您可以在根级别创建附加配置组,并将其应用到逻辑系统中。或者,您可以修改原始组,使其包括默认和非默认逻辑系统层次结构级别的配置。
在 Junos Evolved 中,不支持特定于路由引擎的组 re0 以及 re1 用于选择性地将配置应用到路由引擎插槽 0 和插槽 1 的组。
示例:创建和应用配置组
此示例说明了配置组的创建和应用。在此示例中,SNMP 配置在组 basic 和正常配置层次结构之间划分。
通过将特定于系统的配置(SNMP 联系人)放入配置组中,从而将其与正常配置层次结构分开,可获得多种优势:
-
您可以使用命令
load replace替换任一部分,而不丢弃另一个部分的数据。 -
您可以为特定框设置联系人,因为组数据被特定于设备的数据隐藏。
[edit] groups { basic { # User-defined group name snmp { # This group contains some SNMP data contact "My Engineering Group"; community BasicAccess { authorization read-only; } } } } apply-groups basic; # Enable inheritance from group "basic" snmp { # Some normal (non-group) configuration location "West of Nowhere"; }
此配置等同于以下内容:
[edit]
snmp {
location "West of Nowhere";
contact "My Engineering Group";
community BasicAccess {
authorization read-only;
}
}
示例:禁用配置组的继承
您可以在层次结构顶层除外的任何级别禁用配置组的继承。要禁用继承,请在配置中包含以下 apply-groups-except 语句:
apply-groups-except [ group-names ];
当您在特定层级使用该 apply-group 语句,但又想覆盖从特定参数的配置组继承的值时,此语句非常有用。
示例:在接口 so-1/1/0 上禁用继承
在以下示例中,该 apply-groups 语句在接口级别全局应用。该 apply-groups-except 语句也会应用于接口 so-1/1/0 ,以便使用 and hold-time link-mode 语句的默认值。
[edit]
groups { # "groups" is a top-level statement
global { # User-defined group name
interfaces {
<*> {
hold-time down 640;
link-mode full-duplex;
}
}
}
}
apply-groups global;
interfaces {
so-1/1/0 {
apply-groups-except global; # Disables inheritance from group "global"
# so-1/1/0 uses default value for “hold-time”
# and "link-mode"
}
}
配置组可能会对设备使用的实际值产生一些混淆,因为设备可以从配置组继承配置数据。要查看设备使用的实际值,请在命令中的show竖线 ( | ) 后使用display inheritance命令。此命令在继承的级别和继承语句的组上显示它们:
[edit]
user@host# show | display inheritance
snmp {
location "West of Nowhere";
##
## 'My Engineering Group' was inherited from group 'basic'
##
contact "My Engineering Group";
##
## 'BasicAccess' was inherited from group 'basic'
##
community BasicAccess {
##
## 'read-only' was inherited from group 'basic'
##
authorization read-only;
}
}
要显示扩展的配置(配置,包括继承的语句),而不带 ## 行,请在命令中的show竖线后使用except命令:
[edit]
user@host# show | display inheritance | except ##
snmp {
location "West of Nowhere";
contact "My Engineering Group";
community BasicAccess {
authorization read-only;
}
}
使用该 display inheritance | except ## 选项会删除所有带有 ##的行。因此,您可能无法查看有关密码或其他重要数据 ## 的信息。要查看包含所有信息的完整配置详细信息(而不仅仅是标记为 ##的注释),请将该 no-comments 选项与以下命令一起使用 display inheritance :
[edit]
user@host# show | display inheritance no-comments
snmp {
location "West of Nowhere";
contact "My Engineering Group";
community BasicAccess {
authorization read-only;
}
}
示例:使用 junos-defaults 配置组
Junos OS 提供了一个隐藏且不可变的配置组,称为 junos-defaults 该组,会自动应用于设备的配置。该 junos-defaults 组包含预配置的语句,这些语句包含常见应用程序的预定义值。某些语句必须引用才能生效,例如应用程序的定义(例如,FTP 或 telnet 设置)。其他语句将自动应用,如终端设置。
配置组中包含的 junos-defaults 许多标识符都以名称 junos-开头。由于以名称 junos- 开头的标识符保留供瞻博网络使用,因此您不能使用此名称定义任何配置对象。
您不能在语句中作为配置组名称包含在 junos-defaults 内 apply-groups 。
要查看组中 junos-defaults 可用的全套预设语句,请在配置的顶层发出 show groups junos-defaults 配置模式命令。以下示例显示 Junos 默认组的部分列表:
user@host# show groups junos-defaults
# Make vt100 the default for the console port
system {
ports {
console type vt100;
}
}
applications {
# File Transfer Protocol
application junos-ftp {
application-protocol ftp;
protocol tcp;
destination-port 21;
}
# Trivial File Transfer Protocol
application junos-tftp {
application-protocol tftp;
protocol udp;
destination-port 69;
}
# RPC port mapper on TCP
application junos-rpc-portmap-tcp {
application-protocol rpc-portmap;
protocol tcp;
destination-port 111;
}
# RPC port mapper on UDP
}
要引用组中junos-defaults 提供的语句,请在适用的层级中包括所选junos-default-name语句。
要查看组中的 junos-defaults 应用程序列表,请发出 show configuration groups junos-defaults applications。默认情况下,以 开 junos- 头的应用由瞻博网络配置。以下示例显示 Junos 默认组应用程序的部分列表。
user@host>show configuration groups junos-defaults applications
## protect: groups junos-defaults
##
#
# File Transfer Protocol
#
application junos-ftp {
application-protocol ftp;
protocol tcp;
destination-port 21;
}
#
# Trivial File Transfer Protocol
#
application junos-ftp-data {
application-protocol ftp-data;
protocol tcp;
destination-port 20;
}
application junos-tftp {
application-protocol tftp;
protocol udp;
destination-port 69;
}
#
# Two-Way Active Measurement Protocol
#
application junos-twamp {
application-protocol twamp;
protocol tcp;
destination-port 862;
}
#
# Real Time Streaming Protocol
#
application junos-rtsp {
application-protocol rtsp;
protocol tcp;
destination-port 554;
}
#
# Network Basic Input Output System - networking protocol used on
# Windows networks session service port
#
application junos-netbios-session {
protocol tcp;
destination-port 139;
}
application junos-smb-session {
protocol tcp;
destination-port 445;
}
application junos-ssh {
protocol tcp;
destination-port 22;
}
application junos-telnet {
protocol tcp;
destination-port 23;
}
示例:将通配符与配置组配合使用
您可以使用通配符来标识名称,并允许一个语句为各种语句提供数据。
在正常配置数据中使用通配符的样式与传统 UNIX shell 通配符使用的样式一致。在此样式中,您可以使用以下元字符:
-
星号 (
*) - 匹配任何字符串。 -
问号 (
?) - 匹配任何单个字符。 -
空括号 (
[) - 引入字符类。 -
右括号 (
]) - 指示字符类的结束。如果缺少右括号,则左括号将匹配空括号[,而不是引入字符类。 -
字符类匹配方括号内的任何字符。在配置组中,必须用引号括住包含字符类的接口名称。
-
连字符 (
-) - 指定字符范围。 -
感叹号 (
!) - 可以通过将感叹号设为字符类的第一个字符来补充字符类。要在字符类中包含右括号 (]),请将其设为列出的第一个字符(!如果有的话,则在 之后)。要包含减号,请将其设为列出的第一个或最后一个字符。
如果在层次结构中使用 groups 标识符,请以 以外的标识符 <名称开头。但是,如果要定义通配符语句,则可以使用 < 因为通配符语句必须具有结束 >。
在配置组中使用通配符的规则与正常配置使用通配符的规则相同。但是, < 在 > 层次结构下 groups 使用时具有特殊含义。在层次结构中 groups ,您必须使用通配符模式 <pattern> 用尖括号括住任何术语,以将其与配置文件中的其他通配符区分开来。
[edit]
groups {
sonet-default {
interfaces {
<so-*> {
sonet-options {
payload-scrambler;
rfc-2615;
}
}
}
}
}
通配符表达式匹配(并为其提供配置数据)配置中仅与其表达式匹配的现有语句。在前面的示例中,表达式 <so-*> 将其语句传递 sonet-options 给与表达式 so-*匹配的任何接口。
以下示例说明如何指定接口范围:
[edit]
groups {
gigabit-ethernet-interfaces {
interfaces {
"<ge-1/2/[5-8]>" {
description "These interfaces reserved for Customer ABC";
}
}
}
}
尖括号使您能够在不修改的情况下传递普通通配符。在配置中的任何匹配中,无论是否使用通配符,都将使用配置中遇到的第一个匹配项。在以下示例中,通配符 BGP 组中的数据将按组的列出顺序继承。
- 的
<*a*>首选项值将覆盖中的首选项<*b*>。 - from
<*c*>值p覆盖 from 的值<*d*>
这些组中的任何一个中的数据值都会覆盖以下数据值 abcd:
[edit] user@host#showgroups { one { protocols { bgp { group <*a*> { preference 1; } group <*b*> { preference 2; } group <*c*> { out-delay 3; } group <*d*> { out-delay 4; } group abcd { preference 10; hold-time 10; out-delay 10; } } } } } protocols { bgp { group abcd { apply-groups one; } } } [edit] user@host#show | display inheritanceprotocols { bgp { group abcd { ## ## ’1’ was inherited from group ’one’ ## preference 1; ## ## ’10’ was inherited from group ’one’ ## hold-time 10; ## ## ’3’ was inherited from group ’one’ ## out-delay 3; } } }
如何使用配置组时缩短提交时间
您可以使用配置组跨其他层次结构应用配置,而无需重新输入配置数据。您可以在配置组中指定每个配置详细信息。您还可以在配置组中使用通配符来配置数据范围,而无需详细说明每行配置行。使用配置组的另一种方法是创建一个继承路径,其中包括要应用的一长串配置。
提交使用配置组的配置时,提交过程将展开该组的所有配置数据并将其读入内存中,以便按预期应用配置。如果应用了许多配置组,特别是当配置组广泛使用通配符时,提交性能可能会受到负面影响。
如果您的系统使用许多使用通配符的配置组,则可以在层次结构级别配置[edit system commit]该persist-groups-inheritance语句,以提高提交时间性能。
使用此选项使系统能够在数据库内(而不是在进程内存中)为每个配置组构建继承路径。此更改可以改善提交时间性能。但是,它也会增加数据库大小。
示例:使用配置组的语句集
当配置组中存在语句集时,将继承所有值。例如:
[edit] user@host#showgroups { basic { snmp { interface so-1/1/1.0; } } } apply-groups basic; snmp { interface so-0/0/0.0; } [edit] user@host#show | display inheritancesnmp { ## ## ’so-1/1/1.0’ was inherited from group ’basic’ ## interface [ so-0/0/0.0 so-1/1/1.0 ]; }
对于未显示在括号内的集合,也将继承所有值。例如:
[edit] user@host#showgroups { worldwide { system { name-server { 10.0.0.100; 10.0.0.200; } } } } apply-groups worldwide; system { name-server { 10.0.0.1; 10.0.0.2; } } [edit] user@host#show | display inheritancesystem { name-server { ## ## ’10.0.0.100’ was inherited from group ’worldwide’ ## 10.0.0.100; ## ## ’10.0.0.200’ was inherited from group ’worldwide’ ## 10.0.0.200; 10.0.0.1; 10.0.0.2; } }
示例:使用配置组配置接口
您可以使用配置组将通用接口介质参数与特定于接口的寻址信息分隔开来。以下示例将 ATM 接口的配置数据放入名为 atm-options的组中。
[edit] user@host#showgroups { atm-options { interfaces { <at-*> { atm-options { vpi 0 maximum-vcs 1024; } unit <*> { encapsulation atm-snap; point-to-point; family iso; } } } } } apply-groups atm-options; interfaces { at-0/0/0 { unit 100 { vci 0.100; family inet { address 10.0.0.100/30; } } unit 200 { vci 0.200; family inet { address 10.0.0.200/30; } } } } [edit] user@host#show | display inheritanceinterfaces { at-0/0/0 { ## ## "atm-options" was inherited from group "atm-options" ## atm-options { ## ## "1024" was inherited from group "atm-options" ## vpi 0 maximum-vcs 1024; } unit 100 { ## ## "atm-snap" was inherited from group "atm-options" ## encapsulation atm-snap; ## ## "point-to-point" was inherited from group "atm-options" ## point-to-point; vci 0.100; family inet { address 10.0.0.100/30; } ## ## "iso" was inherited from group "atm-options" ## family iso; } unit 200 { ## ## "atm-snap" was inherited from group "atm-options" ## encapsulation atm-snap; ## ## "point-to-point" was inherited from group "atm-options" ## point-to-point; vci 0.200; family inet { address 10.0.0.200/30; } ## ## "iso" was inherited from group "atm-options" ## family iso; } } } [edit] user@host#show | display inheritance | except ##interfaces { at-0/0/0 { atm-options { vpi 0 maximum-vcs 1024; } unit 100 { encapsulation atm-snap; point-to-point; vci 0.100; family inet { address 10.0.0.100/30; } family iso; } unit 200 { encapsulation atm-snap; point-to-point; vci 0.200; family inet { address 10.0.0.200/30; } family iso; } } }
也可以看看
示例:使用配置组为管理接口配置一致的 IP 地址
在具有多个路由引擎的设备上,每个路由引擎都为管理接口配置了单独的 IP 地址。要访问主路由引擎,您必须知道哪个路由引擎处于活动状态并使用相应的 IP 地址。
要实现对主路由引擎的一致访问,还可以配置附加 IP 地址。然后,无论哪个路由引擎处于活动状态,您都可以将此地址用于管理接口。此附加 IP 地址仅在主路由引擎的管理接口上处于活动状态。在切换期间,地址将移动到新的主路由引擎。
此示例为两个路由引擎配置地址10.17.40.131,并包含一个master-only语句。使用此配置,地址10.17.40.131仅在主路由引擎上处于活动状态。无论哪个路由引擎处于活动状态,地址都保持一致。地址10.17.40.132被分配给 global interfaces re0:mgmt-0fxp0 on ,并10.17.40.133被分配给 fxp0 on global interfaces re1:mgmt-0。
[edit groups global interfaces re0:mgmt-0 interfaces fxp0]
unit 0 {
family inet {
address 10.17.40.131/25 {
master-only;
}
address 10.17.40.132/25;
}
}
[edit groups global interfaces re1:mgmt-0 interfaces fxp0]
unit 0 {
family inet {
address 10.17.40.131/25 {
master-only;
}
address 10.17.40.133/25;
}
}
此功能适用于所有包含双路由引擎的路由器。在由 TX Matrix 路由器组成的路由矩阵上,此功能仅适用于交换卡机箱 (SCC)。同样,在由 TX Matrix Plus 路由器组成的路由矩阵上,此功能仅适用于交换机结构机箱 (SFC)。
-
您必须为在专用接口和公共接口上具有重复地址的两个接口分配唯一的 IP 地址。启用平滑路由引擎切换 (GRES) 后,如果 CLI 发现相同的地址,将显示相应的提交错误消息。如果为管理接口或内部接口(例如)和外部物理接口(如
fxp0ge-0/0/1)配置相同的 IP 地址,则会出现此错误。 -
em0管理以太网接口用于 TX Matrix Plus 路由器、路由矩阵中的 T1600 路由器和 PTX 系列数据包传输路由器。Junos OS 会自动创建设备的管理以太网接口em0。
示例:使用配置组配置对等实体
此示例创建一个组 some-isp ,其中包含与另一个 ISP 相关的配置数据。然后,它会 apply-group 在各个点插入语句,以允许配置层次结构中的这些位置继承此数据。
[edit] user@host#showgroups { some-isp { interfaces { <xe-*> { gigether-options { flow-control; } } } protocols { bgp { group <*> { neighbor <*> { remove-private; } } } pim { interface <*> { version 1; } } } } } interfaces { xe-0/0/0 { apply-groups some-isp; unit 0 { family inet { address 10.0.0.1/24; } } } } protocols { bgp { group main { neighbor 10.254.0.1 { apply-groups some-isp; } } } pim { interface xe-0/0/0.0 { apply-groups some-isp; } } } [edit] user@host#show | display inheritanceinterfaces { xe-0/0/0 { ## ## "gigether-options" was inherited from group "some-isp" ## gigether-options { ## ## "flow-control" was inherited from group "some-isp" ## flow-control; } unit 0 { family inet { address 10.0.0.1/24; } } } } protocols { bgp { group main { neighbor 10.254.0.1 { ## ## "remove-private" was inherited from group "some-isp" ## remove-private; } } } pim { interface xe-0/0/0.0 { ## ## "1" was inherited from group "some-isp" ## version 1; } } }
示例:使用配置组建立区域配置
此示例使用整个公司标准的配置数据填充一个组,而另一个组包含与此标准的区域差异:
[edit] user@host#showgroups { standard { interfaces { <t3-*> { t3-options { compatibility-mode larscom subrate 10; idle-cycle-flag ones; } } } } northwest { interfaces { <t3-*> { t3-options { long-buildout; compatibility-mode kentrox; } } } } } apply-groups standard; interfaces { t3-0/0/0 { apply-groups northwest; } } [edit] user@host#show | display inheritanceinterfaces { t3-0/0/0 { ## ## "t3-options" was inherited from group "northwest" ## t3-options { ## ## "long-buildout" was inherited from group "northwest" ## long-buildout; ## ## "kentrox" was inherited from group "northwest" ## compatibility-mode kentrox; ## ## "ones" was inherited from group "standard" ## idle-cycle-flag ones; } } }
示例:配置通配符配置组名称
通配符是一种配置组名称,使用特殊字符创建可应用于多个语句的模式。通配符可用于将一组配置选项复制到许多不同的配置组。您必须正确设置通配符名称,以确保将通配符配置选项复制到相应的配置组。
此示例为语句下的 label-switched-path 和 <*-minor> 通配符组配置不同的值<*-major>。星号 (*) 字符表示通配符名称的一部分,可以匹配任何字符串。例如,下面的label-switched-path <*-major>配置选项将传递到label-switched-path metro-major及其名称中包含的任何其他label-switched-path配置组-major。
[edit] user@host#showgroups { mpls-conf { protocols { mpls { label-switched-path <*-major> { retry-timer 5; bandwidth 155m; optimize-timer 60; } label-switched-path <*-minor> { retry-timer 15; bandwidth 64k; optimize-timer 120; } } } } } apply-groups mpls-conf; protocols { mpls { label-switched-path metro-major { to 10.0.0.10; } label-switched-path remote-minor { to 10.0.0.20; } } } [edit] user@host#show | display inheritanceprotocols { mpls { label-switched-path metro-major { to 10.0.0.10; ## ## "5" was inherited from group "mpls-conf" ## retry-timer 5; ## "155m" was inherited from group "mpls-conf" ## bandwidth 155m; ## ## "60" was inherited from group "mpls-conf" ## optimize-timer 60; } label-switched-path remote-minor { to 10.0.0.20; ## ## "15" was inherited from group "mpls-conf" ## retry-timer 15; ## ## "64k" was inherited from group "mpls-conf" ## bandwidth 64k; ## ## "120" was inherited from group "mpls-conf" ## optimize-timer 120; } } }
示例:引用默认组中的预设语句
以下示例是 defaults 组中的预设语句,可用于有状态防火墙中的 FTP:
[edit]
groups {
junos-defaults {
applications {
application junos-ftp {# Use FTP default configuration
application-protocol ftp;
protocol tcp;
destination-port 21;
}
}
}
要引用 defaults 组中的预设 default 语句,请在适用的层级包含该 junos-default-name 语句。例如,要在有状态防火墙中引用 FTP 的 default 语句,请在层次结构级别包含该 junos-ftp 语句 [edit services stateful-firewall rule my-rule term my-term from applications] :
[edit]
services {
stateful-firewall {
rule my-rule {
term my-term {
from {
applications junos-ftp; #Reference predefined statement, junos-ftp
}
}
}
}
}
示例:查看已应用于配置的默认语句
要查看已应用于设备配置的默认值,请发出 show | display inheritance defaults 命令。此示例在层次结构级别显示 [edit system ports] 继承的默认值:
user@host# show system ports | display inheritance defaults
## ## 'console' was inherited from group 'junos-defaults'
## 'vt100' was inherited from group 'junos-defaults'
## console type vt100;
如果您选择不使用现有的默认语句,则可以手动创建自己的配置组。
要查看完整配置信息并省略任何标记为 ##的注释,请将该 no-comments 选项与命令配合使用 display inheritance 。
设置路由引擎配置组
在具有两个路由引擎的设备中,两个路由引擎应共享一个配置。此设置可确保两个路由引擎配置相同。在此配置中,创建两个路由引擎组,每个路由引擎一个。在这些组中,您可以指定特定于路由引擎的参数。
有关冗余路由引擎系统和 re0 组的初始配置的更多信息,请参阅 Junos OS 高可用性用户指南。
要设置路由引擎配置组:
如何使用条件应用配置组
您可以在层次结构级别使用[edit groups group-name]该when语句来定义应用配置组的条件。
您可以配置一个组,以根据一天或日期的开始和可选结束时间进行应用。
例如,您可以使用该 when 语句创建一个通用配置组,该组仅根据计划的开始和结束时间在特定时间窗口内应用。
示例:配置应用配置组的条件
此示例说明如何配置应用指定配置组的条件。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
您可以在层次结构级别配置 [edit groups group-name] 组配置数据。然后,您可以使用该 when 语句根据以下条件应用组配置:机箱类型、型号、路由引擎、虚拟机箱成员、群集节点以及一天或日期中的开始和可选结束时间。
如果在单个配置组中指定多个条件,则必须满足所有条件才能应用该配置组。
您可以指定要应用的配置组的开始时间或持续时间。如果仅指定开始时间,则在指定时间应用配置组,并且在更改时间之前一直有效。如果指定了结束时间,则在每天的指定时间启动和停止应用的配置组。
此示例在配置组中设置条件, test1以便仅当满足以下所有条件时才应用此组: 路由器是 MX240 型路由器,机箱类型为 LCC0,路由引擎作为 RE0 运行,是节点 0 上虚拟机箱的成员 0,并且配置组仅在每天上午 9:00 至下午 5:00 期间生效。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层次结构级别的 [edit] CLI 中。
set groups test1 when model mx240set groups test1 when chassis lcc0set groups test1 when routing-engine re0set groups test1 when member member0set groups test1 when node node0set groups test1 when time 9 to 5
过程
分步程序
要配置配置组 test1的条件:
设置用于识别型号 MX240 路由器的条件。
[edit groups test1 when] user@host#
set model mx240将将机箱类型标识为 LCC0 的条件设置为 LCC0。
[edit groups test1 when] user@host#
set chassis lcc0设置将运行的路由引擎
RE0标识为 的条件。[edit groups test1 when] user@host#
set routing-engine re0设置标识虚拟机箱
member0的条件。[edit groups test1 when] user@host#
set member member0设置标识群集
node0的条件。[edit groups test1 when] user@host#
set node node0设置仅在每天上午 9:00 至下午 5:00 之间应用组的条件。
[edit groups test1 when] user@host#
set time 9 to 5注意:指定时间的语法为:
time <start-time> [to <end-time>]使用时间格式 yyyy-mm-dd.hh:mm、hh:mm 或 hh。提交配置。
user@host#
commit
结果
在配置模式下,输入 show groups test1 命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
user@host# show groups test1
when {
time 9 to 5;
chassis lcc0;
model mx240;
routing-engine re0;
member member0;
node node0;
}
验证
使用条件数据检查组继承
目的
验证应用时是否继承了配置组中的条件数据。
行动
使用数据发出show | display inheritancewhen操作命令以显示条件继承。使用此示例,您可以发出以下命令之一来确定条件数据是否已继承:
user@host>show | display inheritance when model mx240user@host>show | display inheritance when chassis lcc0user@host>show | display inheritance when routing-engine re0user@host>show | display inheritance when member member0user@host>show | display inheritance when node node0user@host>show | display inheritance when time 9 to 5