이 페이지에서
예: 이중 라우팅 엔진 구성
디바이스에 이중화( 이중 라우팅 엔진이라고도 함)가 있는 경우 Junos OS 구성이 복잡해질 수 있습니다. 이 예는 커밋 스크립트를 사용하여 이중 라우팅 엔진 플랫폼 구성을 단순화하고 제어하는 방법을 보여줍니다.
요구 사항
이 예에서는 이중 라우팅 엔진으로 Junos OS 실행하는 디바이스를 사용합니다.
개요 및 커밋 스크립트
Junos OS 두 개의 특별한 구성 그룹인 re0
및 을 re1
지원합니다. 이러한 그룹이 문을 사용하여 apply-groups [ re0 re1 ]
적용되면 라우팅 엔진 이름이 그룹 이름과 일치하는 경우 적용됩니다. 계층 수준에 포함된 [edit groups re0]
문은 RE0이라는 이름의 라우팅 엔진만 상속되며, 계층 수준에 포함된 [edit groups re1]
문은 RE1이라는 이름의 라우팅 엔진만 상속됩니다.
이 예에는 두 개의 커밋 스크립트가 포함됩니다. 첫 번째 스크립트 인 dual-re.xsl은 문, IP 버전 4(IPv4) 인터페이스 주소 또는 fxp0 인터페이스 구성이 구성 그룹이 아닌 대상 구성에 구성된 경우 system host-name
경고를 생성합니다.
두 번째 스크립트인 dual-re2.xsl은 먼저 호스트 이름 구성이 구성되었는지 확인한 다음 구성 그룹에서 구성되었는지 확인합니다. otherwise
호스트 이름이 전혀 구성되지 않은 경우 구조는 오류 메시지를 생성합니다. 첫 번째 when
구조는 호스트 이름이 구성 그룹에서 이미 구성된 경우 스크립트가 아무 것도 하지 않도록 허용합니다. 두 번째 when
구조는 대상 구성에서 호스트 이름이 구성되면 효력을 발생합니다. 이 경우 스크립트는 호스트 이름 구성을 및 구성 re0
그룹에 배치하고re1
, 구성된 호스트 이름을 해당 그룹에 복사하고, 각 그룹 호스트 이름을 및 와(과) 으로 -RE0
구성하고-RE1
, 대상 구성에서 호스트 이름을 비활성화하여 구성 그룹 호스트 이름을 상속할 수 있는 임시 변경을 생성합니다.
예제 스크립트는 XSLT 및 SLAX 구문 모두에 표시됩니다.
XSLT 구문: dual-re.xsl 스크립트
<?xml version="1.0" standalone="yes"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:junos="http://xml.juniper.net/junos/*/junos" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm" xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0"> <xsl:import href="../import/junos.xsl"/> <xsl:template match="configuration"> <xsl:for-each select="system/host-name | interfaces/interface/unit/family/inet/address | interfaces/interface[name = 'fxp0']"> <xsl:if test="not(@junos:group) or not(starts-with(@junos:group, 're'))"> <xnm:warning> <xsl:call-template name="jcs:edit-path"> <xsl:with-param name="dot" select=".."/> </xsl:call-template> <xsl:call-template name="jcs:statement"/> <message> <xsl:text>statement should not be in target</xsl:text> <xsl:text> configuration on dual RE system</xsl:text> </message> </xnm:warning> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet>
XSLT 구문: dual-re2.xsl 스크립트
<?xml version="1.0" standalone="yes"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:junos="http://xml.juniper.net/junos/*/junos" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm" xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0"> <xsl:import href="../import/junos.xsl"/> <xsl:template match="configuration"> <xsl:variable name="hn" select="system/host-name"/> <xsl:choose> <xsl:when test="$hn/@junos:group"/> <xsl:when test="$hn"> <transient-change> <groups> <name>re0</name> <system> <host-name> <xsl:value-of select="concat($hn, '-RE0')"/> </host-name> </system> </groups> <groups> <name>re1</name> <system> <host-name> <xsl:value-of select="concat($hn, '-RE1')"/> </host-name> </system> </groups> <system> <host-name inactive="inactive"/> </system> </transient-change> </xsl:when> <xsl:otherwise> <xnm:error> <message>Missing [system host-name]</message> </xnm:error> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
SLAX 구문: dual-re.xsl 스크립트
version 1.0; ns junos = "http://xml.juniper.net/junos/*/junos"; ns xnm = "http://xml.juniper.net/xnm/1.1/xnm"; ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0"; import "../import/junos.xsl"; match configuration { for-each (system/host-name | interfaces/interface/unit/family/inet/address | interfaces/interface[name = 'fxp0']) { if (not(@junos:group) or not(starts-with(@junos:group, 're'))) { <xnm:warning> { call jcs:edit-path($dot = ..); call jcs:statement(); <message> { expr "statement should not be in target"; expr " configuration on dual RE system"; } } } } }
SLAX 구문: dual-re2.xsl 스크립트
version 1.0; ns junos = "http://xml.juniper.net/junos/*/junos"; ns xnm = "http://xml.juniper.net/xnm/1.1/xnm"; ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0"; import "../import/junos.xsl"; match configuration { var $hn = system/host-name; if ($hn/@junos:group) { } else if ($hn) { <transient-change> { <groups> { <name> "re0"; <system> { <host-name> $hn _ '-RE0'; } } <groups> { <name> "re1"; <system> { <host-name> $hn _ '-RE1'; } } <system> { <host-name inactive="inactive">; } } else { <xnm:error> { <message> "Missing [system host-name]"; } } } }
구성
절차
단계별 절차
스크립트를 다운로드, 활성화 및 실행하려면 다음 단계를 따르십시오.
스크립트를 두 개의 텍스트 파일로 복사하고, 필요에 따라 dual-re.xsl 및 dual-re2.xsl 또는 dual-re.slax 및 dual-re2.slax 의 이름을 지정하고 디바이스의 /var/db/scripts/commit/ directory로 복사합니다.
다음 테스트 구성 stanzas를 선택하고 Ctrl+c를 눌러 클립보드로 복사합니다.
스크립트의 SLAX 버전을 사용하는 경우, 계층 수준에서 파일 이름을
[edit system scripts commit file]
dual-re.slax 및 dual-re2.slax로 변경합니다.groups { re0 { interfaces { fxp0 { unit 0 { family inet { address 10.0.0.1/24; } } } } } } apply-groups re0; system { host-name router1; scripts { commit { file dual-re.xsl; file dual-re2.xsl; } } } interfaces { fe-0/0/0 { unit 0 { family inet { address 192.168.220.1/30; } } } }
구성 모드에서 명령을 실행
load merge terminal
하여 스탠자를 디바이스 구성에 병합합니다.[edit] user@host# load merge terminal [Type ^D at a new line to end input] ... Paste the contents of the clipboard here ...
프롬프트에서 마우스와 붙여넣기 아이콘을 사용하여 클립보드의 내용을 붙여 넣습니다.
Enter.
Ctrl+d를 누릅니다.
구성을 커밋합니다.
user@host# commit
확인
커밋 스크립트 변경 확인
목적
스크립트가 예상대로 작동하는지 확인합니다.
작업
명령의 출력을 검토합니다 commit
. 커밋 작업이 완료되면 디바이스 호스트 이름이 router1-RE0으로 변경됩니다.
[edit] user@host# commit [edit system] 'host-name router1;' warning: statement should not be in target configuration on dual RE system [edit interfaces interface fe-0/0/0 unit 0 family inet] 'address 192.168.220.1/30;' warning: statement should not be in target configuration on dual RE system commit complete