今天在群里聊天有人问道如何清理监听日志,因为监听日志有些大,所以希望问有没有办法清理,腾出空间,下面笔者尝试了如下方法进行清理监听日志文件,实验对敏感信息进行了修改:
一:使用lsnrctl工具关闭写日志:
---首先查看监听状态
oracle@oracle /home/oracle$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 19-NOV-2015 10:39:40
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 27-OCT-2015 11:17:28
Uptime 22 days 23 hr. 22 min. 11 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/product/11.2.0/db_64/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/111/listener/alert/log.xml
在11g中监听文件有两份:一份是xml后缀的,一份是log后缀的,对于xml这个可读性不好,所以我们可以查看/opt/oracle/diag/tnslsnr/111/listener/trace 下的listener.log文件。
下面我们使用lsnrctl工具来关闭写日志:
oracle@oracle /home/oracle$ rlwrap lsnrctl
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 19-NOV-2015 11:41:38
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL> show log_status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=1521)))
LISTENER parameter "log_status" set to ON
The command completed successfully
LSNRCTL> set log_status off
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx)(PORT=1521)))
LISTENER parameter "log_status" set to OFF
The command completed successfully
LSNRCTL> show log_status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx)(PORT=1521)))
LISTENER parameter "log_status" set to OFF
The command completed successfully
保存修改log_status配置:
LSNRCTL> save_config
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxx)(PORT=1521)))
Saved LISTENER configuration parameters.
Listener Parameter File /opt/oracle/product/11.2.0/db_64/network/admin/listener.ora
Old Parameter File /opt/oracle/product/11.2.0/db_64/network/admin/listener.bak
The command completed successfully
Use the SAVE_CONFIG command to compare the current configuration state of the listener, including trace level, trace file, trace directory, and logging to the listener.ora file. Any changes are stored in listener.ora, preserving formatting, comments, and case as much as possible. Prior to modification of the listener.ora file, a backup of the file, called listener.bak, is created.
通过SAVE_CONFIG命令来保存修改的配置使其生效,在保存后你会发现在listener.ora文件尾部被新添加了一行LOGGING_LISTENER = OFF:
#----ADDED BY TNSLSNR 19-NOV-2015 11:44:23---
LOGGING_LISTENER = OFF
#--------------------------------------------
笔者通过pl/sql客户端登陆测试发现在listener.log中并没有产生登陆日志。
注意:通过这种方式禁用监听写日志,在出现故障的时候会导致无日志可查,所以需要自己评估好。
二:使用RM删掉监听日志文件方法:
首先把监听进程记录日志关闭
oracle@oracle /home/oracle$ rlwrap lsnrctl
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 19-NOV-2015 14:03:33
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL> set log_status off;
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx)(PORT=1521)))
LISTENER parameter "log_status" set to OFF
The command completed successfully
然后使用mv或cp 修改日志文件名,这里我使用mv的方式进行操作:
oracle@oracle /opt/oracle/diag/tnslsnr/111/listener/trace$ ls
listener.log
oracle@oracle /opt/oracle/diag/tnslsnr/111/listener/trace$ mv listener.log listener.log.11
最后启动监听服务进程,启动之后会自动生成listener.log文件
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
查看下/opt/oracle/diag/tnslsnr/111/listener/trace目录下是否已生成listener.log文件
oracle@oracle /opt/oracle/diag/tnslsnr/111/listener/trace$ ll -lth
total 8.2M
-rw-r-----. 1 oracle oinstall 63 Nov 19 14:08 listener.log
启动之后我们就可以通过rm -rf 删除listener.log.11文件了,或者将这个文件保留到其他目录,以便以后好查询。
三:通过使用crontab来定时清理:
使用定时器来清理监听日志文件其实和上面操作类似,脚本如下:
#!/bin/bash
data_name=`date +'%d%m'`
cd /opt/oracle/diag/tnslsnr/111/listener/trace
lsnrctl set log_status off
mv listener.log /tmp/listener.log.$data_name
lsnrctl set log_status on
制定crontab任务:
00 1 * * * /home/oracle/listener_log.sh > /home/oracle/listener_log.log 2>&1
执行时间和保留策略都是可以自己制定的,通过crontab可以摆脱手工操作,通过系统自动去执行维护操作。
阅读(8165) | 评论(0) | 转发(0) |