利用dbstart和dbshut在开关机时自动启动和关闭db
使用chkconfig增加服务
1、编辑/etc/oratab文件
TEST:/u01/app/oracle/product/9.2.0:Y (把原来的N改为Y)
2、增加Linux服务(叫服务不一定准且,反正理解意思就行,名称为oradb10g)
2.1 cd /etc/rc.d/init.d/
touch oradb10g
chmod a+x oracle9i
2.2 vi oradb10g 并输入以下内容:
[oracle@xys init.d]$ more oradb10g
#more /etc/rc.d/init.d/oradb10g
#!/bin/bash
#whoami
#root
#chkconfig:345 58 42 这里注意如果db使用的raw,那么启动顺序一定要放在rawdevices被mount之后,当然shutdown的时候一定要在rawdevices dismount之前
#description: start oracle database deamons
#
ORACLE_HOME=/opt/app/oracle/product/10.2.0/db_1
ORACLE_OWNER=oracle
case "$1" in
start)
echo -n "Starting oradb10g:"
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbstart"
touch /var/lock/subsys/oradb10g
echo
esac
case "$1" in
stop)
echo -n "Shutting down oradb10g:"
echo
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbshut"
rm -f /var/lock/subsys/oradb10g
echo
esac
2.3 设定oradb10g的启动级别
cd /etc/rc.d/init.d/
chkconfig --add oradb10g
chkconfig --list oradb10g
oracle9i 0:off 1:off 2:off 3:on 4:on 5:on 6:off
2.4 测试服务
/etc/rc.d/init.d/oradb10g start
/etc/rc.d/init.d/oradb10g stop
3. 重启linux
reboot
在linux启动的时候,可以看到一个启动项oradb10g,出现[OK]的时候,就表示数据库随系统启动了。
3.1 重启Linux后,查看进程
ps -ef|grep ora
ps -ef|grep tnslsnr
3.2 sqlplus测试
sqlplus '/as sysdba'
3.3 lsnrctl status