之前学习了通过增加文件/etc/rc.d/rc.local的执行权限,实现Oracle开机启动功能。今天将学习利用创建Oracle服务启动脚本,从而实现Oracle开机启动功能。
1. 环境准备
1.1 系统
操作系统:CentOS 7(64位)
1.2 工具/软件
已安装完成的Oracle11g(64位);
创建数据库实例,本文中数据库实例名:test;$ORACLE_SID:testsid
2. 方法/步骤
2.1 配置/etc/oratab
以root身份登录到linux系统,编辑/etc/oratab文件,找到
testsid:/data/oracle/product/11.2.0/db_1:N
,改为
testsid:/data/oracle/product/11.2.0/db_1:Y
注意:/data/oracle/product/11.2.0/db_1为安装的$ORACLE_HOME,根据情况自行修改路径。
[oracle@zm-centos7 ~]$ su #切换到root
Password: #输入root密码
[root@zm-centos7 oracle]# vim /etc/oratab #编辑
[root@zm-centos7 oracle]# cat /etc/oratab #查看
#
tsid:/data/oracle/product/11.2.0/db_1:N
# This file is used by ORACLE utilities. It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.
# 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:<N|Y>:
#
# 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.
#
#
testsid:/data/oracle/product/11.2.0/db_1:Y #修改位置
[root@zm-centos7 oracle]#
2.2 配置/etc/rc.d/rc.local
添加如下脚本:
su oracle -lc "/data/oracle/product/11.2.0/db_1/bin/lsnrctl start"
su oracle -lc /data/oracle/product/11.2.0/db_1/bin/dbstart
其中第一行因为lsnrctl之后有空格,需要引号,第二行加不加引号都可以。修改完保存退出即可。
添加结果:
[root@zm-centos7 /]# vim /etc/rc.d/rc.local
[root@zm-centos7 /]# 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.
# add start
su oracle -lc "/data/oracle/product/11.2.0/db_1/bin/lsnrctl start"
su oracle -lc /data/oracle/product/11.2.0/db_1/bin/dbstart
# add end
touch /var/lock/subsys/local
# mount -a
[root@zm-centos7 /]#
截止此处,配置都与之前的配置方法相同,后面将配置Oracle服务启动脚本。
2.3 在/etc/init.d/下创建Oracle服务启动脚本
以root身份登录到系统,创建以oracle命名的文件
[oracle@zm-centos7 ~]$ su
Password:
[root@zm-centos7 oracle]# vim /etc/init.d/oracle
将以下脚本代码复制到文件里(注意修改oracle路径)
#!/bin/sh
# chkconfig: 345 61 61
# description: Oracle 11g R2 AutoRun Servimces
# /etc/init.d/oracle
#
# Run-level Startup script for the Oracle Instance, Listener, and
# Web Interface
export ORACLE_BASE=/data/oracle #根据个人情况修改路径
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
<