简介
本文介绍如何在CentOS7.6上设置Oracle Database 12c Release 2开机启动
软件 | 版本 | 备注 |
---|---|---|
本地操作系统 | Win10 | ip:192.168.1.1 |
虚拟机操作系统 | CentOS Linux release 7.6.1810 (Core) | ip:192.168.1.14 内存2.8G swap 2G |
Oracle | Oracle Database 12c Release 2 | linux版本 |
开机启动
以root
账号登入虚拟机
编辑oratab
文件
vim /etc/oratab
修改最后一位位Y
修改前截图
修改后截图
创建dbora
文件
[root@localhost ~]# vim /etc/init.d/dbora
内容如下:
#! /bin/sh
# 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 ORACLE_HOME.
ORA_HOME=/home/oracle/app/oracle/product/12.2.0/dbhome_1/
ORA_OWNER=oracle
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/dbstart $ORA_HOME" &
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 $ORA_HOME" &
rm -f /var/lock/subsys/dbora
;;
esac
修改执行权限
# 将所有者文件改为oracle用户
chown oracle /etc/init.d/dbora
# oracle账号和root组具备执行权限
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
手动启停
-
编辑
oratab
文件
参照开机启动配置 -
启动脚本
dbstart $ORACLE_HOME
dbshut $ORACLE_HOME
- 简便方式
# 使用别名的方式
vim .bashrc
# 添加以下内容,注意不要使用dbstart,dbshut
alias startdb='dbstart $ORACLE_HOME'
alias shutdb='dbshut $ORACLE_HOME'
# 使别名生效
source .bashrc
参考
官方管理文档: https://docs.oracle.com/en/database/oracle/oracle-database/12.2/unxar/stopping-and-starting-oracle-software.html#GUID-A4864665-F68E-4C53-8411-606CF2DED443