原由:公司买了亚马逊云的服务器,在云服务器上搭建oracle测试数据库。由于亚马逊云是按照时间来收费的。所以每天下班都会关闭,早上开启。
所以每次开启都要手动启动实例,很麻烦,所以要每天早上开启服务器的时候自动开启数据库实例和监听,故做成自动启动。
步骤如下:
1、用root用户登录修改 /etc/oratab文件
把
orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_1:N (在19行左右,也是最后一行)
改为
orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_1:Y
2、使用ORACLE用户修改$ORACLE_HOME/bin/dbstart文件
把
ORACLE_HOME_LISTNER=$0 (在80行左右)
改为
ORACLE_HOME_LISTNER=$ORACLE_HOME
所以每次开启都要手动启动实例,很麻烦,所以要每天早上开启服务器的时候自动开启数据库实例和监听,故做成自动启动。
步骤如下:
1、用root用户登录修改 /etc/oratab文件
把
orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_1:N (在19行左右,也是最后一行)
改为
orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_1:Y
2、使用ORACLE用户修改$ORACLE_HOME/bin/dbstart文件
把
ORACLE_HOME_LISTNER=$0 (在80行左右)
改为
ORACLE_HOME_LISTNER=$ORACLE_HOME
3、使用root用户在/etc/rc.d/init.d/目录下,创建自动启动的执行脚本oradbstart
脚本内容如下:
#!/bin/bash
# chkconfig: 345 99 10
# description: Startup Script for oracle Databases
# /etc/rc.d/init.d/dbstart
export ORACLE_BASE=/u01/app/oracle (写自己的真实的ORACLE_BASE )
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 ( 写自己的真实的ORACLE_HOME )
export ORACLE_SID=dicomdb ( 写自己的真实的实例名字 )
export PATH=$PATH:$ORACLE_HOME/bin
ORA_OWNR="oracle"
# if the executables do not exist -- display error
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display
case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart"
touch /var/lock/oracle
su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctrl start"
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctrl stop"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbshut"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
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、在root用户下执行
chown oracle:oinstall /etc/rc.d/init.d/oradbstart 设置oradbstart文件的属主
chmod 775 /etc/rc.d/init.d/oradbstart 设置执行权限
chkconfig --add oradbstart 使服务器开机自启
5、reboot服务器,测试是否成功。
脚本内容如下:
#!/bin/bash
# chkconfig: 345 99 10
# description: Startup Script for oracle Databases
# /etc/rc.d/init.d/dbstart
export ORACLE_BASE=/u01/app/oracle (写自己的真实的ORACLE_BASE )
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 ( 写自己的真实的ORACLE_HOME )
export ORACLE_SID=dicomdb ( 写自己的真实的实例名字 )
export PATH=$PATH:$ORACLE_HOME/bin
ORA_OWNR="oracle"
# if the executables do not exist -- display error
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display
case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart"
touch /var/lock/oracle
su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctrl start"
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctrl stop"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbshut"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
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、在root用户下执行
chown oracle:oinstall /etc/rc.d/init.d/oradbstart 设置oradbstart文件的属主
chmod 775 /etc/rc.d/init.d/oradbstart 设置执行权限
chkconfig --add oradbstart 使服务器开机自启
5、reboot服务器,测试是否成功。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31447263/viewspace-2136406/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31447263/viewspace-2136406/