centos oracle开机启动

1 配置/etc/oratab

以root身份登录到linux系统,编辑/etc/oratab文件,找到
orcl:/u01/app/oracle/product/11.2.0/db_1:N,改为orcl:/u01/app/oracle/product/11.2.0/db_1:Y
注意:/u01/app/oracle/product/11.2.0/db_1为安装的$ORACLE_HOME,根据情况自行修改路径。

[root@oracle ~]# find / -name oratab
/etc/oratab
/u01/app/oracle/product/11.2.0/db_1/install/oratab
[root@oracle ~]# vim /etc/oratab

#



# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME::
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
orcl:/u01/app/oracle/product/11.2.0/db_1:N

2 配置/etc/rc.d/rc.local

添加如下行:

su oracle -lc "/u01/app/oracle/product/11.2.0/db_1/bin/lsnrctl start"
su oracle -lc /u01/app/oracle/product/11.2.0/db_1/bin/dbstart

其中第一行因为lsnrctl之后有空格,需要引号,第二行加不加引号都可以。修改完保存退出即可。
如果是在以前的centos版本中,这样就可以了。但是centos7 的/etc/rc.local不会开机执行,认真查看/etc/rc.local文件的内容就发现问题的原因了

[root@oracle ~]# cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

翻译一下

这个文件是为了兼容性的问题而添加的。
强烈建议创建自己的systemd服务或udev规则来在开机时运行脚本而不是使用这个文件。
与以前的版本引导时的并行执行相比较,这个脚本将不会在其他所有的服务后执行。
请记住,你必须执行“chmod +x /etc/rc.d/rc.local”来确保确保这个脚本在引导时执行。

查看一下/etc/rc.d/rc.local的权限

[root@oracle /]# ll /etc/rc.d/rc.local
-rw-r--r-- 1 root root 484 Oct 11 17:17 /etc/rc.d/rc.local

发现没有执行权限,按照说明的内容执行命令:

[root@oracle ~]# chmod +x /etc/rc.d/rc.local
[root@oracle ~]# reboot     #重启机器,确认结果

你可能感兴趣的:(centos oracle开机启动)