示例:跟踪 NETCONF 和 Junos XML 协议会话操作
此示例演示如何为 NETCONF 和 Junos XML 协议会话配置追踪操作。
从 Junos OS 版本 16.1 开始,在层次结构上启用追踪操作时,Junos OS 对 [edit system services netconf traceoptions]
NETCONF 和 Junos XML 协议会话启用追踪操作,并将 和标记添加到日志文件条目中以区分会话类型。 [NETCONF]
[JUNOScript]
在版本 16.1 Junos OS之前,仅记录 NETCONF 会话数据,并且 [NETCONF]
省略了标记。
要求
需要运行 16.1 Junos OS更高版本的路由、交换或安全设备。
概述
此示例配置了 NETCONF 和 Junos XML 协议会话的基本跟踪操作。该示例配置追踪文件 netconf-ops.log, 并为每个文件设置最多 20 个追踪文件数和最大 3 MB 大小。该 flag all
语句配置所有传入和即将推出的 NETCONF 或 Junos XML 协议数据的跟踪。 world-readable
该选项允许无限制访问追踪文件。
配置
CLI快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以匹配网络配置,然后将命令复制并粘贴到 层次结构级别的 CLI 中 [edit]
。
set system services netconf ssh set system services netconf traceoptions file netconf-ops.log set system services netconf traceoptions file size 3m set system services netconf traceoptions file files 20 set system services netconf traceoptions file world-readable set system services netconf traceoptions flag all
配置 NETCONF 和 Junos XML 协议追踪操作
逐步过程
要配置 NETCONF 和 Junos XML 协议追踪操作:
对于 NETCONF 会话,在 SSH 上启用 NETCONF。
[edit] user@R1# set system services netconf ssh
配置跟踪选项标志,以指定要捕获的会话数据。
您可以指定传入、传出或所有数据。此示例配置所有会话数据的跟踪。
[edit] user@R1# set system services netconf traceoptions flag all
(可选)配置追踪文件的文件名。
以下语句配置 trace 文件 netconf-ops.log,该日志存储在 /var/log 目录中。如果不指定文件名,NETCONF 和 Junos XML 协议会话数据将存储在 /var/log/netconf 中。
[edit] user@R1# set system services netconf traceoptions file netconf-ops.log
(可选)配置追踪文件的最大数量和每个文件的最大大小。
以下语句配置最多 20 个追踪文件,每个文件的最大大小为 3 MB。
[edit] user@R1# set system services netconf traceoptions file files 20 user@R1# set system services netconf traceoptions file size 3m
(可选)将跟踪输出限制为仅包含与特定正则表达式匹配的行。
此示例中未使用的以下配置匹配并仅记录包含"错误消息"的会话数据。
[edit] user@R1# set system services netconf traceoptions file match error-message
(可选)配置按需追踪,以通过 NETCONF 或 Junos XML 协议会话控制追踪操作。
未在此例中使用的以下配置支持按需追踪。
[edit] user@R1# set system services netconf traceoptions on-demand
(可选)通过指定该文件是 或 来配置跟踪文件
world-readable
的权限no-world-readable
。此示例允许无限制访问追踪文件。
[edit] user@R1# set system services netconf traceoptions file world-readable
提交配置。
[edit] user@R1# commit
结果
[edit] system { services { netconf { ssh; traceoptions { file netconf-ops.log size 3m files 20 world-readable; flag all; } } } }
验证
验证 NETCONF 和 Junos XML 协议追踪操作
目的
验证设备是否正在将 NETCONF 和 Junos XML 协议会话数据写入配置的追踪文件。此示例记录传入和传出 NETCONF 及Junos XML 协议数据。在示例 NETCONF 会话(此处未详述)中,用户修改 R1 上的候选配置以包括 bgp-troubleshoot.slax op 脚本,然后提交配置。
行动
发出操作模式命令,显示配置的 trace 文件 /var/log/netconf-ops.log 的 show log 跟踪输出。
user@R1 show log netconf-ops.log Apr 3 13:09:04 [NETCONF] Started tracing session: 3694 Apr 3 13:09:29 [NETCONF] - [3694] Incoming: <rpc> Apr 3 13:09:29 [NETCONF] - [3694] Outgoing: <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/16.1R1/junos"> Apr 3 13:09:39 [NETCONF] - [3694] Incoming: <edit-config> Apr 3 13:09:43 [NETCONF] - [3694] Incoming: <target> Apr 3 13:09:47 [NETCONF] - [3694] Incoming: <candidate/> Apr 3 13:09:53 [NETCONF] - [3694] Incoming: </target> Apr 3 13:10:07 [NETCONF] - [3694] Incoming: <default-operation>merge</default-operation> Apr 3 13:10:10 [NETCONF] - [3694] Incoming: <config> Apr 3 13:10:13 [NETCONF] - [3694] Incoming: <configuration> Apr 3 13:10:16 [NETCONF] - [3694] Incoming: <system> Apr 3 13:10:19 [NETCONF] - [3694] Incoming: <scripts> Apr 3 13:10:23 [NETCONF] - [3694] Incoming: <op> Apr 3 13:10:26 [NETCONF] - [3694] Incoming: <file> Apr 3 13:10:44 [NETCONF] - [3694] Incoming: <name>bgp-troubleshoot.slax</name> Apr 3 13:10:46 [NETCONF] - [3694] Incoming: </file> Apr 3 13:10:48 [NETCONF] - [3694] Incoming: </op> Apr 3 13:10:52 [NETCONF] - [3694] Incoming: </scripts> Apr 3 13:10:56 [NETCONF] - [3694] Incoming: </system> Apr 3 13:11:00 [NETCONF] - [3694] Incoming: </configuration> Apr 3 13:11:00 [NETCONF] - [3694] Outgoing: <ok/> Apr 3 13:11:12 [NETCONF] - [3694] Incoming: </config> Apr 3 13:11:18 [NETCONF] - [3694] Incoming: </edit-config> Apr 3 13:11:26 [NETCONF] - [3694] Incoming: </rpc> Apr 3 13:11:26 [NETCONF] - [3694] Outgoing: </rpc-reply> Apr 3 13:11:26 [NETCONF] - [3694] Outgoing: ]]>]]> Apr 3 13:11:31 [NETCONF] - [3694] Incoming: ]]>]]> Apr 3 13:14:20 [NETCONF] - [3694] Incoming: <rpc> Apr 3 13:14:20 [NETCONF] - [3694] Outgoing: <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/16.1R1/junos"> Apr 3 13:14:26 [NETCONF] - [3694] Incoming: <commit/> Apr 3 13:14:35 [NETCONF] - [3694] Outgoing: <ok/> Apr 3 13:14:35 [NETCONF] - [3694] Incoming: </rpc> Apr 3 13:14:35 [NETCONF] - [3694] Outgoing: </rpc-reply> Apr 3 13:14:35 [NETCONF] - [3694] Outgoing: ]]>]]> Apr 3 13:14:40 [NETCONF] - [3694] Incoming: ]]>]]> Apr 3 13:30:48 [NETCONF] - [3694] Outgoing: <!-- session end at 2016-12-03 13:30:48 PDT -->
意义
此示例配置了 该语句,因此 trace 文件将显示所有传入和传出 flag all
NETCONF 或 Junos XML 协议会话操作。每个操作都包括日期和时间。日志文件通过分别包含 或 标记来指示会话类型(NETCONF 或 Junos XML [NETCONF]
[JUNOScript]
协议)。多个 NETCONF 和 Junos XML 协议会话通过会话编号来区分。此示例中,只有一个使用会话标识符 3694 的 NETCONF 会话处于活动状态。