Cisco IOS Cookbook 中文精簡版 18-23 日誌

 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]
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引入此特性,方便後處理
18.17.       修改日誌記錄
提問 希望修改系統日誌記錄的一些屬性
回答
首先要寫特定的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 $:rig_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腳本來進行控制。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章