Linux/Unix 中如何配置 Oracle Database 随服务器自动启动
Oracle Database 软件提供了以下两个脚本来配置数据库随服务器自动启动和关闭:
[oracle@prod bin]$ pwd
/u01/app/oracle/product/11.2.0/db_1/bin
[oracle@prod bin]$ ls -l dbs*
-rwxr-x--- 1 oracle oinstall 6030 Jan 1 2000 dbshut
-rwxr-x--- 1 oracle oinstall 13797 Jan 1 2000 dbstart
我们需要在 unix 启动/关闭脚本( rc0.d / rc1.d 等)中调用这两个脚本
1、检查 /etc/oratab 下的 oratab 文件,该文件应该包含要设置自动启动和关闭的数据库的条目,
其中 autostart 值域的值为 Y,如下所示:
$ORACLE_SID:$ORACLE_HOME:Y
[oracle@prod bin]$ more /etc/oratab
prod:/u01/app/oracle/product/11.2.0/db_1:N
[oracle@prod bin]$ vi /etc/oratab
prod:/u01/app/oracle/product/11.2.0/db_1:Y
2、将如下文件保存到 /etc/init.d/ 下(/etc/init.d/ 是 redhat linux 下特有的)。
[root@prod init.d]# pwd
/etc/init.d
[root@prod init.d]# ls -l dbora
-rw-r--r-- 1 root root 1049 Mar 27 20:10 dbora
--注意 ORA_OWNER 和 ORA_HOME 变量的设置
------------------ Start dbora ---------------------------------
#! /bin/bash
#
# description: Oracle auto start-stop script.
#
# chkconfig: 2345 99 10
#
# processname: oracle
# config: /etc/oratab
# pidfile: /var/run/oracle.pid
# Source function library.
. /etc/init.d/functions
RETVAL=0
ORA_OWNER="oracle"
ORA_HOME="/u01/app/oracle/product/11.2.0/db_1"
# See how we were called.
prog="oracle"
start() {
echo -n $"Starting $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dbora
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -r /var/lock/subsys/dbora
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
------------------ End dbora ---------------------------------
3: 以 root 用户身份执行如下命令:
[root@prod init.d]# cd /sbin
[root@prod sbin]# chkconfig --add dbora
--此命令将创建如下系统服务
[root@prod sbin]# chkconfig --list | grep dbora
dbora 0:off 1:off 2:on 3:on 4:on 5:on 6:off
--此外,还会创建如下文件
/etc/rc2.d/S99dbora ( calls $ORACLE_HOME/bin/dbstart )
/etc/rc3.d/S99dbora ( calls $ORACLE_HOME/bin/dbstart )
/etc/rc4.d/S99dbora ( calls $ORACLE_HOME/bin/dbstart )
/etc/rc5.d/S99dbora ( calls $ORACLE_HOME/bin/dbstart )
/etc/rc0.d/K10dbora ( calls $ORACLE_HOME/bin/dbshut )
/etc/rc1.d/K10dbora ( calls $ORACLE_HOME/bin/dbshut )
/etc/rc6.d/K10dbora ( calls $ORACLE_HOME/bin/dbshut )
lrwxrwxrwx 1 root root 15 Mar 27 20:12 /etc/rc2.d/S99dbora -> ../init.d/dbora
[root@prod rc2.d]# ls -l /etc/rc3.d/S99dbora
lrwxrwxrwx 1 root root 15 Mar 27 20:12 /etc/rc3.d/S99dbora -> ../init.d/dbora
[root@prod rc2.d]# ls -l /etc/rc4.d/S99dbora
lrwxrwxrwx 1 root root 15 Mar 27 20:12 /etc/rc4.d/S99dbora -> ../init.d/dbora
[root@prod rc2.d]# ls -l /etc/rc5.d/S99dbora
lrwxrwxrwx 1 root root 15 Mar 27 20:12 /etc/rc5.d/S99dbora -> ../init.d/dbora
[root@prod rc2.d]# ls -l /etc/rc0.d/K10dbora
lrwxrwxrwx 1 root root 15 Mar 27 20:12 /etc/rc0.d/K10dbora -> ../init.d/dbora
[root@prod rc2.d]# ls -l /etc/rc1.d/K10dbora
lrwxrwxrwx 1 root root 15 Mar 27 20:12 /etc/rc1.d/K10dbora -> ../init.d/dbora
[root