Oracle 安装完成后,如果有执行orainstRoot.sh该脚本,会在/etc目录下创建oraInst.loc和oratab两个文件
其中自动启动与oratab配置有关
oratab分成三个部分,以":"分隔:
第一部分为 $ORACLE_SID 表示数据库的实例ID名
第二部分为 $ORACLE_HOME 表示数据库家目录
第三部分为 Y|N 表示是否允许系统启动时DB自启动
配置文件中的解释,这里不在翻译,需要注意的是其中提到多个条目不允许使用同一个SID
# 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.
如允许DB自启动,范例:
orcl:/u01/app/oracle/product/11.2.0/db_1:Y
然后添加自动启动脚本 /etc/init.d/dbora
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/u01/app/oracle/product/11.2.0
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
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 "$ORA_HOME/bin/lsnrctl start" &
su $ORA_OWNER -c $ORA_HOME/bin/dbstart &
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 $ORA_HOME/bin/dbshut
su $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
rm -f /var/lock/subsys/dbora
;;
esac
该脚本包括监听的自动启动.注意实际应用中$ORA_HOME应与安装时指定$ORACLE_HOME相符
chgrp oinstall /etc/init.d/dbora
chmod 750 /etc/init.d/dbora
ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K01dbora
ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora
chkconfig --add dbora
重启系统,观察数据库是否自动启动.
这里顺便提一下为什么没有使用ORACLE官方文档提供的脚本.官方文档使用的脚本中是通过rsh工具来远程连接oracle用户并执行相应的启动任务,很多人直接使用时报connection refuse的错误,在网上找了一下相应的问题.
其实为RHEL 5的rsh命令由多个包提供,并且放在不同的目录.
而官方启动脚本中调用了PATH变量,PATH的定义可以看出是先去读/usr/kerberos下的sbin/bin目录:
[root@dbserver1 ~]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin...........
检查发现rsh,rlogin命令均存在于kerberos/bin目录下,查看命令由哪个包提供的
which rsh/rlogin
rpm -qf `which rlogin`
krb5-workstation-1.6.1-36.el5_4.1
删除该包后再验证是否正确
rpm -e krb5-workstation
除此之外,还要安装rsh服务端的包
rpm -Uvh rsh-server-0.17-40.el5_7.1.i386.rpm
启动服务
chkconfig rsh on
chkconfig rlogin on
service xinetd reload
这个时候脚本应该就自动运行正常了.另外我之前给oracle用户添加过密码,执行官方的自启脚本时,还要输入密码:
解决的方式是回收oracle用户的密码,不要让脚本运行提示输入oracle用户登陆密码.
passwd -d oracle -d 参数快速取消账户的密码认证,仅root用户可以使用
参考文章