- 论坛徽章:
- 0
|
请大家帮忙看看是哪里的问题,多谢!!
monitor监控脚本内容:
#!/usr/bin/ksh
# *****************************************************************************
# ********** Note: This file MUST be edited before it can be used. ************
# *****************************************************************************
# *****************************************************************************
# ************************ START OF EDITABLE SECTION **************************
# *****************************************************************************
SERVICE_IP=10.71.111.183
ORACLE_SID=ibmora
ORACLE_HOME=/opt/oracle/product/9.2
ORACLE_LISTENER_NAME=
LOG_FILE=/tmp/monitor.out
HACMPCLUTL=/usr/sbin/cluster/utilities
SH=/usr/bin/ksh
MONITOR_INTERVAL=5
PFILE=$ORACLE_HOME/dbs/init${ORACLE_SID}.ora
ORACLE_VERSION=9.2.0.5
# *****************************************************************************
# ********************** START OF NON-EDITABLE SECTION ************************
# *****************************************************************************
set -A MONITOR_PROCESSES ora_pmon_${ORACLE_SID} ora_dbw0_${ORACLE_SID} ora_ckpt_${ORACLE_SID} ora_smon_${ORACLE_SID} ora_lgwr_${ORACLE_SID} ora_reco_${ORACLE_SID}
HOST=`hostname`
PATH=${ORACLE_HOME}/bin:/sbin:/usr/bin:/usr/sbin:/etc:/bin
export ORACLE_SID
export ORACLE_HOME
# *****************************************************************************
# return code
# 0 - primary
# 1 - standby
# *****************************************************************************
function is_cluster_primary
{
ifconfig -a | grep ${SERVICE_IP} > /dev/null
return $?
}
# *****************************************************************************
# return code
# 0 - succeed
# 1 - fail
# *****************************************************************************
function monitor_listener
{
su - oracle -c "${ORACLE_HOME}/bin/lsnrctl status ${ORACLE_LISTENER_NAME}" > /dev/null
if [ $? = 0 ]
then
MONITOR_LISTENER_PID=`ps -fu oracle | grep tnslsnr | awk '{ print $2 }'`
# print "Monitored process = tnslsnr, pid = ${MONITOR_LISTENER_PID}" >> ${LOG_FILE}
return 0
fi
su - oracle -c "${ORACLE_HOME}/bin/lsnrctl start ${ORACLE_LISTENER_NAME}" > /dev/null
if [ $? = 0 ]
then
MONITOR_LISTENER_PID=`ps -fu oracle | grep tnslsnr | awk '{ print $2 }'`
print "Monitored process = tnslsnr, pid = ${MONITOR_LISTENER_PID}" >> ${LOG_FILE}
print "\n *** listener has restarted. ***" >> ${LOG_FILE}
return 0
fi
print "\n *** listener has failed. Aborting Oracle. ***" >> ${LOG_FILE}
return 1
}
# *****************************************************************************
# return code
# 0 - succeed
# 1 - fail
# *****************************************************************************
function monitor_processes
{
typeset -i n=0
DATE=`date`
# print "${HOST} - ${DATE}" >> ${LOG_FILE}
for i in ${MONITOR_PROCESSES[@]}
do
MONITOR_PROCESSES_PID[$n]=`ps -fu oracle | grep ${i} | awk '{ print $2 }'`
# print "Monitored process = ${i}, pid = ${MONITOR_PROCESSES_PID[$n]}" >> ${LOG_FILE}
if [[ ${MONITOR_PROCESSES_PID[$n]} = "" ]]
then
print "\n\n" >> ${LOG_FILE}
ps -ef >> ${LOG_FILE}
print "\n *** ${i} has failed. Aborting Oracle. ***" >> ${LOG_FILE}
print "\n" >> ${LOG_FILE}
return 1
fi
(( n = n + 1 ))
done
monitor_listener
if [ $? = 1 ]
then
return 1
fi
print "\n" >> ${LOG_FILE}
return 0
}
# *****************************************************************************
# main code
# *****************************************************************************
if [ ${LOGIN} != root ]
then
print "Please run $0 as super user root. script exits now."
exit 1
fi
case $1 in
start)
su - oracle -c "${ORACLE_HOME}/bin/lsnrctl start" >> ${LOG_FILE}
#is_cluster_primary
# if [ $? = 1 ]
# then
# exit 0
# fi
#ps -ef|grep HWIVASMON|grep -v grep > /dev/null
# if [ $? = 0 ]
# then
# exit 0
# fi
if [ ${ORACLE_VERSION} = 8.1.X ]
then
su - oracle -c "${ORACLE_HOME}/bin/sqlplus /nolog<<EOF
connect / as sysdba
startup pfile=${PFILE}
exit
EOF
" >> ${LOG_FILE}
else
print "oracle 9205" >> ${LOG_FILE}
su - oracle -c "${ORACLE_HOME}/bin/sqlplus /nolog<<EOF
connect / as sysdba
startup
exit
EOF
" >> ${LOG_FILE}
fi
print "shell is $0"
${SH} "$0 monitor HWIVASMON" &
exit 0
;;
stop)
ps -ef | grep HWIVASMON | grep -v grep | awk '{print "kill", $2}' | ${SH}
su - oracle -c "${ORACLE_HOME}/bin/lsnrctl stop" >> ${LOG_FILE}
ps -ef|grep oracle${ORACLE_SID}|grep -v grep|awk '{print $2}'|xargs kill -9
su - oracle -c "${ORACLE_HOME}/bin/sqlplus /nolog<<EOF
connect / as sysdba
shutdown immediate
exit
EOF
" >> ${LOG_FILE}
exit 0
;;
monitor)
while true
do
sleep ${MONITOR_INTERVAL}
is_cluster_primary
if [ $? = 0 ]
then
monitor_processes
if [ $? = 1 ]
then
${HACMPCLUTL}/clstop -y '-N' '-gr' # stop and takeover
exit 1
fi
fi
done
exit 0
;;
*)
print "Usage: $0 [start | stop | monitor]"
exit 0
;;
esac |
|