最近在公司搭建一套OEM12c监控环境,监控操作系统Linux、windows、存储、数据库(oracle、SqlServer)等,感觉OEM12c蛮强大的,监控的范围很广,对客户来讲蛮实用的。由于在Linux下安装完oracle后,每次reboot系统后,都系要手工去开启oracle服务,为了方便起见,写了下启动脚本,简单三步走,内容如下:
1、首先修改/etc/oratab 参数,让系统启动时自动加载数据库
oem12c:/u01/app/oracle/product/11.2.0/db_1:N ——----->oem12c:/u01/app/oracle/product/11.2.0/db_1:Y
2、其次修改$ORACLE_HOME/bin/dbstart 和 $ORACLE_HOME/bin/dbshut脚本文件
以dbstart为例:
ORACLE_HOME_LISTNER=$1,修改为 ORACLE_HOME_LISTNER=$ORACLE_HOME
dbshut脚本参考上图
3、最后一步有二种实现方式,我们先介绍最简单的一种:
1)修改/etc/rc.d/rc.local内容
添加以下二行:
su oracle -lc "/u01/app/oracle/product/11.2.0/db_1/bin/lsnrctl start"
su oracle -lc "/u01/app/oracle/product/11.2.0/db_1/bin/dbstart"
重启系统即可,随后你就可以看到oracle进程:
2)创建脚本,设置成开机自动启动服务
oracle脚本内容如下:
# !/bin/bash
# whoami
# root
# chkconfig: 345 51 49
# description: starts the oracle dabase deamons
#
#ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
ORACLE_OWNER=oracle
ORACLE_DESC="Oracle 11g"
ORACLE_LOCK=/var/lock/subsys/oracle11g
case "$1" in
'start')
echo -n "Starting ${ORACLE_DESC}:" >> /var/log/oracle
echo "-------------------------------------------" >> /var/log/oracle
echo `date +%T%a%D` ":Start Oracle Database as part of system up" >> /var/log/oracle
echo -n "-------------------------------------------" >> /var/log/oracle
runuser - $ORACLE_OWNER -c '$ORACLE_HOME/bin/lsnrctl start' >> /var/log/oracle
# echo "Done"
echo "-------------------------------------------" >> /var/log/oracle
echo -n
runuser - $ORACLE_OWNER -c '$ORACLE_HOME/bin/dbstart' >> /var/log/oracle
#runuser - $ORACLE_OWNER -c '$ORACLE_HOME/bin/emctl start dbconsole' >> /var/log/oracle
touch ${ORACLE_LOCK}
echo
;;
'stop')
echo -n "shutting down ${ORACLE_DESC}:" >> /var/log/oracle
echo "-------------------------------------------" >> /var/log/oracle
echo `date +%T%a%D` ":Start Oracle Database as part of system down" >> /var/log/oracle
echo "Shutting Down Oracle Listeners:" >> /var/log/oracle
echo -n "-------------------------------------------" >> /var/log/oracle
runuser - $ORACLE_OWNER -c '$ORACLE_HOME/bin/lsnrctl stop' >> /var/log/oracle
echo "-------------------------------------------" >> /var/log/oracle
runuser - $ORACLE_OWNER -c '$ORACLE_HOME/bin/dbshut' >> /var/log/oracle
echo
rm -f ${ORACLE_LOCK}
echo
;;
'restart')
echo -n "restarting ${ORACLE_DESC}:" >> /var/log/oracle
$0 stop
$0 start
echo
;;
*)
echo "usage: $0 { start | stop | restart }"
exit 1
esac
exit 0
注:runuser - $ORACLE_OWNER -c 也可以改写成 su oracle -lc
建立软连接:
ln -s /etc/init.d/oracle /etc/rc1.d/K61oracle
ln -s /etc/init.d/oracle /etc/rc3.d/S61oracle
设置服务运行级别:
chkconfig --level 345 oracle on
chkconfig --add oracle