1.设置相应数据库实例允许用系统服务自动启动:修改oratab文件:
$ vim /etc/oratab
将sales:/u01/app/oracle/product/11.2.0/dbhome_1:N
改为:sales:/u01/app/oracle/product/11.2.0/dbhome_1:Y
2. 在/etc/init.d/下创建文件oracle,内容如下:
# vim /etc/init.d/oracle
#!/bin/bash
#!/bin/sh
#chkconfig:345 61 61
#description:Oracle self-startup script
OPT_=$1
case "$OPT_" in
start)
/bin/echo "$0 : (start)"
su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start"
su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart"
su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/emctl start dbconsole"
chmod 1777 /tmp
chown sys:sys /tmp
exit 0
;;
stop)
/bin/ehco "$0 : (stop)"
su -oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl stop"
su -oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbshut"
su -oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/emctl stop dbconsole"
exit 0
;;
*) /bin/echo ''
/bin/echo "Usage: $0 [start|stop]"
/bin/echo " Invalid argument ==> \"${OPT_}\""
/bin/echo ''
exit 0
;;
esac
3. 改变文件权限
# chmod 755 /etc/init.d/oracle
4. 添加服务
# chkconfig --level 35 oracle on
5. 需要在关机或重启机器之前停止数据库,做一下操作
# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle //关机
# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle //重启
6. 使用方法(适用于RHEL7)
# service oracle start //启动oracle
# service oracle stop //关闭oracle
# service oracle restart //重启oracle
来源:CSDN
作者:阳光洒脱
链接:https://blog.csdn.net/qq_16128855/article/details/104759344