Linux定时清理Oracle12cRAClistener监听⽇志
⽬录
1.背景
已知⽣产环境有⼀套两节点Oracle 12cR2 RAC,长期运⾏后监听⽇志⽂件过多,占⽤⼤量磁盘,需要配置定时任务,⾃动截断、备份、清理监听⽇志。
1.1Oracle 12cR2 RAC监听有哪些
在两个节点上,查看监听进程:ps -ef | grep tnslsnr| grep -v grep。
可以看到两个节点上都有"LISTENER"本地监听、"ASMNET1LSNR_ASM"监听(Cluster ASM listener),节点1上还
有"LISTENER_SCAN1"(SCAN监听),节点2上还有"MGMTLSNR"(管理资料库监听)。
[grid@ora12cnode1 ~]$ ps -ef | grep tnslsnr| grep -v grep
grid 21591 1 0 2018 ? 1-03:15:00 /u01/app/12.2.0/grid/bin/tnslsnr LISTENER_SCAN1 -no_cr
suspend
s_notify -inherit
grid 50594 1 0 2018 ? 05:51:15 /u01/app/12.2.0/grid/bin/tnslsnr ASMNET1LSNR_ASM -no_crs_notify -inherit
grid 50732 1 0 2018 ? 2-00:02:26 /u01/app/12.2.0/grid/bin/tnslsnr LISTENER -no_crs_notify -inherit
[grid@ora12cnode2 ~]$ ps -ef | grep tnslsnr| grep -v grep
grid 41881 1 0 2018 ? 05:48:36 /u01/app/12.2.0/grid/bin/tnslsnr ASMNET1LSNR_ASM -no_crs_notify -inherit
grid 42662 1 0 2018 ? 17:12:22 /u01/app/12.2.0/grid/bin/tnslsnr LISTENER -no_crs_notify -inherit
grid 42689 1 0 2018 ? 00:25:35 /u01/app/12.2.0/grid/bin/tnslsnr MGMTLSNR -no_crs_notify -inherit
1.2Oracle 12cR2 RAC监听⽇志⽂件有哪些qq英语名
监听alert⽇志⽂件:$ORACLE_BASE/diag/tnslsnr/$HOSTNAME/listener_name/alert⽬录下的*.xml⽂件
监听trace⽇志⽂件:$ORACLE_BASE/diag/tnslsnr/$HOSTNAME/listener_name/trace⽬录下的listener_name.log
本⽂重点是对监听trace⽂件listener_name.log进⾏截断、备份、清理。关于监听alert⽇志⽂件.xml,请参考:。
2.脚本⽂件through
/home/grid/adminShellScripts/purge_listener_logs.sh
#!/bin/bash
# Author: longfeiwlf
海阔凭鱼跃天高任鸟飞的意思# Description: purge Oracle 12c RAC running listeners' trace log file
# Date: 2020-5-21
# Version: 1.1
#source ur grid's environment
breathless是什么意思
source /home/grid/.bash_profile
today=$(date +%Y%-m-%d-%H:%M:%S)
echo "========================================$today========================================="
#查找所有正在运⾏的监听
listeners=$(ps -ef| grep tnslsnr | grep -v grep | awk '{print $9}')
echo "Listeners running on this host: $listeners"
#t log_status to "OFF" or "ON"。调⽤⽅法:t_log_status listener_name "ON"/"OFF"
#"lsnrctl<<-EOF"连起来写,中间没有任何空格。开始的EOF前加上减号"-",就可以在结束的EOF前使⽤tab(注意不是空格)来缩进function t_log_status(){nerve>2011年北京高考分数线
echo ""
echo "--------------------------t $1 log_status $2-----------------"
lsnrctl<<-EOF
t current_listener $1
show log_status
t log_status $2
show log_status
EOF
echo ""
}
#backup listener trace log and purge log files 180 days ago。备份,清空,清理
#调⽤⽅法:purge_log listener_name
function purge_log(){
echo "--------------------------purge $1-----------------------------"
time_now=$(date +%Y%m%d%H%M%S)
lsnr_trace_dir=$ORACLE_BASE/diag/tnslsnr/$HOSTNAME/${1,,}/trace
cd ${lsnr_trace_dir}
cp ${1,,}.log ${1,,}.log.${time_now}
cat /dev/null > ${1,,}.log
ls -lrth
find ${lsnr_trace_dir} -type f -mtime +180 -name "*.log.*"| xargs -t -I {} rm -f {}
}roundtrip
#purge all running listener's logs
for lsnr in $listeners
congratulationdo
echo "Purge listener $lsnr trace "
t_log_status $lsnr "off"
purge_log $lsnr
t_log_status $lsnr "on"
done
echo "Purge listener trace logs done."出生日期英文
3.添加crontab任务计划
在Oracle RAC节点1、节点2的grid⽤户下,添加crontab任务计划,每⽉1⽇02:00执⾏。
00 02 1 * * /home/grid/adminShellScripts/purge_listener_logs.sh
>>/home/grid/adminShellScripts/purge_listener_logs.log 2>&1 &