日期:2014-05-16  浏览次数:20752 次

linux中配置oracle11g R2与tomcat先后启动

参考自(亲自试验,并稍作修改):

http://www.oracle-base.com/articles/linux/automating-database-startup-and-shutdown-on-linux.php

support.filecatalyst.com/index.php?/Knowledgebase/Article/View/210/0/starting-tomcat-as-a-linux-service

tomcat加入服务并设置自启动在另一篇:http://blog.csdn.net/zxnlmj/article/details/22933477

oracle数据库安装见:http://blog.csdn.net/zxnlmj/article/details/22826149

1、编辑/etc/oradb文件,将每个数据库实例的重启标志由N都设置为Y:

su root
gedit /etc/oratab

修改后如下:

# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
sunlight:/home/oracle/product/11.2/db_1:Y

2、新建/etc/init.d/oracle文件,并添加如下配置:


su root:
gedit /etc/init.d/oracle                

添加如下内容:

#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database software.
# ORA_OWNER为在linux中安装oracle数据库时建立的属于dba组的用户名oracle,而非登陆oracle数据库时的用户名
ORA_OWNER=oracle

case "$1" in
    'start')
        # Start the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        # Remove "&" if you don't want startup as a background process.
        su $ORA_OWNER -c "/home/oracle/scripts/startup.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1" &

        touch /var/lock/subsys/dbora
        ;;
    'stop')
        # Stop the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su $ORA_OWNER -c "/home/oracle/scripts/shutdown.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1"
        rm -f /var/lock/subsys/dbora
        ;;
esac

3、修改2中oracle文件的权限:
su root
[root@JTWF Desktop]# chmod 750 /etc/init.d/oracle

4、设置oracle服务的运行级别,及设置自启动:


[root@JTWF Desktop]# chkconfig --add oracle
[root@JTWF Desktop]#

5、创建startup.sh与shutdown.sh脚本,并修改隶属用户及组(位于/home/oracle/scripts)
# mkdir -p /home/oracle/scripts
# chown oracle.oinstall /home/oracle/scripts
[root@JTWF Desktop]# chown oracle.dba /home/oracle/scripts


/home/oracle/scripts/startup.sh脚本内容如下:

#!/bin/bash

export TMP=/tmp
export TMPDIR=$TMP
export PATH=/usr/sbin:/usr/local/bin:$PATH
export ORACLE_HOSTNAME=JTWF
#export ORACLE_UNQNAME=db12c

export ORACLE_SID=sunlight
ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES

# Start Listener
lsnrctl start

# Start Database
sqlplus / as sysdba << EOF
STARTUP;
EXIT;
EOF



/home/oracle/scripts/shutdown.sh脚本内容如下:

#!/bin/bash

export TMP=/tmp
export TMPDIR=$TMP
export PATH=/usr/sbin:/usr/local/bin:$PATH
export ORACLE_HOSTNAME=