您好,登錄后才能下訂單哦!
oracle 11g的監(jiān)聽日志和警告日志都是在/opt/oracle/app/diag/tnslsnr/機(jī)器名/listener目錄
其中警告日志在alert目錄下,監(jiān)聽日志在trace目錄下。listener目錄下產(chǎn)生的日志文件比較大,是主要清理的對(duì)象。在listener目錄下監(jiān)聽日志是一個(gè)名為listener.log的文件,而警告日志log.xml,這個(gè)日志每到11M左右就會(huì)分割成一個(gè)log_XXXX.xml的日志,逐漸累加。
是否不需要對(duì)監(jiān)聽日志文件進(jìn)行截?cái)嗑S護(hù)呢? 答案是否定的。當(dāng)然要對(duì)監(jiān)聽日志文件(listener.log)進(jìn)行定期清理,如果不定期清理,會(huì)遇到下面一些麻煩:
1、監(jiān)聽日志文件(listener.log)變得越來越大,占用額外的存儲(chǔ)空間。(當(dāng)然現(xiàn)在存儲(chǔ)白菜價(jià),不差那幾G的空間。但是我們還是要本著工匠情懷,精益求精)。
2、監(jiān)聽日志文件(listener.log)變得太大會(huì)帶來一些問題:LISTENER.LOG日志大小不能超過2GB,超過會(huì)導(dǎo)致LISTENER監(jiān)聽器無法處理新的連接。
3、監(jiān)聽日志文件(listener.log)變得太大,給寫入、查看帶來的一些性能問題、麻煩。
一、單機(jī)實(shí)例:
$ find $ORACLE_BASE -name listener.log
/opt/oracle/app/diag/tnslsnr/testdb/listener/trace/listener.log
LSNRCTL> show
The following operations are available after show
An asterisk (*) denotes a modifier or extended command:
rawmode displaymode
rules trc_file
trc_directory trc_level
log_file log_directory
log_status current_listener
inbound_connect_timeout startup_waittime
snmp_visible save_config_on_stop
dynamic_registration enable_global_dynamic_endpoint
oracle_home pid
LSNRCTL> show log_file
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxx)(PORT=1521)))
LISTENER parameter "log_file" set to /opt/oracle/app/diag/tnslsnr/testdb/listener/alert/log.xml
The command completed successfully
show log_status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxx)(PORT=1521)))
LISTENER parameter "log_status" set to ON
The command completed successfully
show log_directory
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxx)(PORT=1521)))
LISTENER parameter "log_directory" set to /opt/oracle/app/diag/tnslsnr/testdb/listener/alert
The command completed successfully
監(jiān)聽目前處于正常狀態(tài),日志功能也打開,后來一想,原來是日志文件大小已滿
處理:
1:首先 停止日志
LSNRCTL> set log_status off
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxx)(PORT=1521)))
LISTENER parameter "log_status" set to OFF
The command completed successfully
LSNRCTL> exit
2、到目錄/opt/oracle/app/diag/tnslsnr/wskjdb/listener/trace
mv listener.log listener.log.bak
3、開啟日志
LSNRCTL> set log_status on
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxx)(PORT=1521)))
LISTENER parameter "log_status" set to ON
The command completed successfully
4、重新加載監(jiān)聽器
LSNRCTL> reload
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxx)(PORT=1521)))
The command completed successfully
LSNRCTL> exit
LSNRCTL> show log_status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxx)(PORT=1521)))
LISTENER parameter "log_status" set to ON
The command completed successfully
5、目錄下重新生成新的日志,壓縮保存$tar czvf listener.log.bak.gz listener.log.bak
6、刪除原有的日志:rm -rf listener.log.bak
二、在RAC環(huán)境中,需要切換到grid用戶來查詢監(jiān)聽日志
#su - grid
lsnrctl命令行模式
set current_listener listener_scan1
set log_status off
cat /dev/null > listener_scan1.log
set log_status on
cat listener_scan1.log
三、通過使用crontab來定時(shí)清理:
使用定時(shí)器來清理監(jiān)聽日志文件其實(shí)和上面操作類似,腳本如下:
$listener_log.sh
#!/bin/bash
data_name=`date +'%d%m'`
cd /opt/oracle/app/diag/tnslsnr/wskjdb/listener/trace
lsnrctl set log_status off
mv listener.log /tmp/listener.log.$data_name
lsnrctl set log_status on
lsnrctl reload
制定crontab任務(wù):0 1 * * * /home/oracle/listener_log.sh > /home/oracle/listener_log.log 2>&1
執(zhí)行時(shí)間和保留策略都是可以自己制定的,通過crontab可以擺脫手工操作,通過系統(tǒng)自動(dòng)去執(zhí)行維護(hù)操作。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。