18.1. 啟用本地路由器日志
提問 實現路由器自身保存日志記錄,而不僅僅是顯示在終端上
回答
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#logging buffered informational
Router(config)#end
Router#
注釋 缺省日志記錄為debugging級別,例子中為informational忽略掉了debug消息。禁用使用下面命令
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#no logging buffered
Router(config)#end
Router#
18.2. 設定日志記錄大小
提問 改變路由器保存日志記錄的大小
回答
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#logging buffered 16000
Router(config)#end
Router#
注釋 要注重的是改變了大小后,原有的日志記錄會被清除。
18.3. 清除路由器日志記錄
提問 清除路由器日志記錄
回答
Router#clear logging
Clear logging buffer [confirm]<enter>
Router#
注釋 無
18.4. 發送日志到屏幕顯示
提問 在終端屏幕實時顯示日志記錄
回答
啟用
Router#terminal monitor
Router#
禁用
Router#terminal no monitor
Router#
注釋 缺省情況下日志記錄只會在console端顯示,要在VTY會話顯示就必須使用上述命令
18.5. 使用遠端日志服務器
提問 發送日志記錄到遠端日志服務器
回答
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#logging 172.25.1.1
Router(config)#end
Router#
12.2(15)T后也可以使用下面命令格式
Router2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router2(config)#logging host 172.25.1.1
Router2(config)#end
Router2#
注釋 在12.2(15)T后增加了一個特性可以使發送的記錄中包含了主機名,下面這是原始的日志記錄
Jul 15 20:35:07 172.25.1.100: Jul 15 20:35:07.499 EDT: %SYS-5-CONFIG_I: Configured from console by ijbrown on vty0 (172.25.1.1)
下面這個是使用特性后的記錄
Jul 15 20:37:05 172.25.1.100: Router2: Jul 15 20:37:05.173 EDT: %SYS-5-CONFIG_I: Configured from console by ijbrown on vty0 (172.25.1.1)
配置方法:Router2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router2(config)#logging origin-id hostname
Router2(config)#end
Router2#
18.6. Unix服務器上啟用Syslog服務
提問 配置Unix服務器接收syslog記錄
回答
一般只需要在/etc/syslog.conf
local7.info /var/log/rtrlog
注釋 缺省情況路由器使用local7 logging facility
18.7. 修改缺省Log Facility
提問 修改缺省Log Facility
回答
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#logging host 172.25.1.1
Router(config)#logging facility local6
Router(config)#end
Router#
注釋 無
18.8. 限制特定日志記錄發送至服務器
提問 限制特定等級的日志記錄發送至服務器
回答
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#logging host 172.25.1.1
Router(config)#logging trap notifications
Router(config)#end
Router#
注釋 無
18.9. 設定Syslog消息的源地址
提問 路由器Syslog消息的源地址使用特定地址
回答
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#logging host 172.25.1.1
Router(config)#logging source-interface Loopback0
Router(config)#end
Router#
注釋 這樣假如在日志服務器上設置了地址翻譯就可以實現下述的效果
APR 2 20:27:01 172.25.2.6 94: %SYS-5-CONFIG_I: Configured from on vty0
Apr 2 20:27:48 Boston 95: %SYS-5-CONFIG_I: Configured from on vty0
18.10. 記錄路由器日志記錄到不同的文件
注釋 略
18.11. 維護服務器上的日志記錄
注釋 使用腳本實現日志記錄的自動存檔等功能 略
18.12. 測試日志服務器的配置
注釋 使用腳本來測試日志服務器的配置是否正確 略
18.13. 避免常見的消息被記錄
提問 在日志記錄中禁止一些常見的端口狀態等消息
回答
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface Serial0/0
Router(config-if)#no logging event link-status
Router(config-if)#no logging event dlci-status-change
Router(config-if)#no logging event subif-link-status
Router(config-if)#exit
Router(config)#end
Router#
注釋 略
18.14. 日志記錄的流量控制
提問 限制發送到服務器的日志流量
回答
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#logging host 172.25.1.1
Router(config)#logging rate-limit 30 except warnings
Router(config)#end
Router#
對控制臺口的日志記錄數目控制
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#logging rate-limit console 25 except warnings
Router(config)#end
Router#
注釋 無
18.15. 啟用日志統計
提問 統計路由器日志的類型和數目
回答
Router2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router2(config)#logging count
Router2(config)#end
Router2#
注釋
Router2#show logging count
Facility Message Name Sev Occur Last Time
==================================================================================
NTP PEERREACH 6 3 Jul 13 20:31:34.441
NTP PEERSYNC 5 1 Jul 13 20:23:03.571
NTP PEERUNREACH 4 3 Jul 13 20:22:00.435
NTP RESTART 6 1 Jan 31 14:13:33.769
------------- ------------------------------- ----------------------------------
NTP TOTAL 8
18.16. 生成xml格式的日志記錄
提問 以XML格式來發送日志
回答
Router2# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router2(config)#logging console xml
Router2(config)#logging monitor xml
Router2(config)#logging buffered xml
Router2(config)#logging host 172.25.1.1 xml
Router2(config)#end
Router2#
注釋 12.2(15)T引入此特性,方便后處理
<!--[if !supportLists]-->18.17. <!--[endif]-->修改日志記錄
提問 希望修改系統日志記錄的一些屬性
回答
首先要寫特定的TCL腳本(delcounters.tcl 腳本用于過濾掉包含counters的日志)
# delcounters.tcl This script deletes all log messages that
# have the mnemonic "COUNTERS".
if { [string compare -nocase COUNTERS $::mnemonic ] == 0 } {
return ""
} else {
return $::orig_msg
}
然后引用此腳本
Router2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router2(config)#logging filter tFTP://172.25.1.1/delcounters.tcl
Router2(config)#logging host 172.25.1.1 filtered
Router2(config)#end
Router2#
注釋 Embedded Syslog Manager (ESM) 引自12.3(2)T,提供一個程序化的接口可以對日志進行過濾,修改等全面控制,主要是使用TCL腳本來進行控制。
新聞熱點
疑難解答