一、使用root用户修改/etc/oratab 文件:
$ gedit /etc/oratab
orcl:/Oracle /app/product/10.2.0/db_1:N
改为:
orcl:/Oracle /app/product/10.2.0/db_1:Y
也就是将最后的N改为Y
创建自启动脚本
1、edit /etc/oratab after creating the database, and set the last column to Y
2、设置环境变量(若以前设置过,此步可省略)
- gengzhi @gengzhi -desktop:~$ sudo gedit /etc/profile
gengzhi@gengzhi-desktop:~$ sudo gedit /etc/profile
添加如下内容:
- export ORACLE_HOME=/opt/oracle/product/ 10.2 . 0 /db_1
- export PATH=$PATH:/opt/oracle/product/10.2 . 0 /db_1/bin
export ORACLE_HOME=/opt/oracle/product/10.2.0/db_1
export PATH=$PATH:/opt/oracle/product/10.2.0/db_1/bin
3、创建oracledb脚本到/etc/init.d/oracledb,内容如下
- #!/bin/bash
- #
- # /etc/init.d/oracledb
- #
- # Run-level Startup script for the Oracle Listener and Instances
- # It relies on the information on /etc/oratab
- export ORACLE_BASE=/opt/oracle
- export ORACLE_HOME=/opt/oracle/product/10.2 . 0 /db_1
- export ORACLE_OWNR=oracle
- export PATH=$PATH:$ORACLE_HOME/bin
- if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
- then
- echo "Oracle startup: cannot start"
- exit 1
- fi
- case "$1" in
- start)
- # Oracle listener and instance startup
- echo -n "Starting Oracle: "
- su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl start"
- su $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
- touch /var/lock/oracle
- echo "OK"
- ;;
- stop)
- # Oracle listener and instance shutdown
- echo -n "Shutdown Oracle: "
- su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
- su $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
- rm -f /var/lock/oracle
- echo "OK"
- ;;
- reload|restart)
- $0 stop
- $0 start
- ;;
- *)
- echo "Usage: `basename $0` start|stop|restart|reload"
- exit 1
- esac
- exit 0
#!/bin/bash
#
# /etc/init.d/oracledb
#
# Run-level Startup script for the Oracle Listener and Instances
# It relies on the information on /etc/oratab
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/10.2.0/db_1
export ORACLE_OWNR=oracle
export PATH=$PATH:$ORACLE_HOME/bin
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl start"
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
touch /var/lock/oracle
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
rm -f /var/lock/oracle
echo "OK"
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: `basename $0` start|stop|restart|reload"
exit 1
esac
exit 0
4、设置权限和自启动
- //设置权限
- gengzhi@gengzhi -desktop:~$ sudo chmod a+x /etc/init.d/oracledb
- //设置每次机器启动时自动运行
- root@hardy :~# update-rc.d oracledb defaults 99
- Adding system startup for /etc/init.d/oracledb ...
- /etc/rc0.d/K99oracledb -> ../init.d/oracledb
- /etc/rc1.d/K99oracledb -> ../init.d/oracledb
- /etc/rc6.d/K99oracledb -> ../init.d/oracledb
- /etc/rc2.d/S99oracledb -> ../init.d/oracledb
- /etc/rc3.d/S99oracledb -> ../init.d/oracledb
- /etc/rc4.d/S99oracledb -> ../init.d/oracledb
- /etc/rc5.d/S99oracledb -> ../init.d/oracledb
- //增加用户到dba组(user用实际的用户名替代,诸如我的用户名为gengzhi),以便可以用常用用户启动时自动启动Oracle服务器而不用以Oracle用户登录
- gengzhi@gengzhi -desktop:~$ sudo usermod -G dba -a user