oracle启动脚本

环境

Centos7(64位) oracle11g

配置/etc/oratab

orcl:/data01/oracleDB/product/11.2.0/db_1:N

改为

orcl:/data01/oracleDB/product/11.2.0/db_1:Y

如果没有这个文件find / -name oratab 找到文件路径复制到/etc/下

对于oratab文件的说明: 
1.只在Linux环境中存在 
2.设置格式::: 示例:orcl:/data01/oracleDB/product/11.2.0/db_1:N
3.可以为不同的数据库设置相应的选项 
4.如果想用$ORACLE_HOME/bin/dbstart脚本来启动数据库,则需要将/etc/oratab文件中相应的数据库的项置为Y, 
简单的说即dbstart脚本根据oratab文件中的配置决定启动哪几个数据库。 
5.如果不使用dbstart脚本启动数据库,而是用自己的脚本来启动,那么根本不用关心oratab文件。

https://www.linuxidc.com/Linux/2011-04/34155.htm解决执行Oracle控制脚本时遇到的 “cat: /etc/oratab: 没有那个文件或目录”的问题

 

在/etc/init.d/下创建Oracle服务启动脚本:

vi /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=/data01/oracleDB/    #根据个人情况修改路径

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1/

export ORACLE_SID=orcl         #改成自己的ORACLE_SID:orcl

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

su $ORA_OWNR -lc $ORACLE_HOME/bin/dbstart

echo "Oracle Start Succesful!OK."

;;

stop)

# Oracle listener and instance shutdown

su $ORA_OWNR -lc $ORACLE_HOME/bin/dbshut

echo "Oracle Stop Succesful!OK."

;;

reload|restart)

$0 stop

$0 start

;;

*)

echo $"Usage: `basename $0` {start|stop|reload|reload}"

exit 1

esac

exit 0

检查一下脚本能否正确执行

cd /etc/rc.d/init.d

chmod +x oracle

ll oracle

执行oracle脚本

./oracle start

这里需要注意了,在启动Oracle服务的时候,提示“ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener”,大体意思是“Oracle监听没有配置,监听没能启动”。

下面就需要配置一下监听,让启动数据库的时候也把监听一起启动。

 

配置oracle监听开机自启动服务

修改dbstart和dbshut启动关闭脚本,使其启动数据库的同时也自动启动监听器(即启动数据库时启动监听器,停止数据库时停止监听器): 

 

vi /data01/oracleDB/product/11.2.0/db_1/bin/dbstart

找到下面的代码:

ORACLE_HOME_LISTNER=$1

将其改为

ORACLE_HOME_LISTNER=/data01/oracleDB/product/11.2.0/db_1/

vi /data01/oracleDB/product/11.2.0/db_1/bin/dbshut

找到下面的代码:

ORACLE_HOME_LISTNER=$1

将其改为

ORACLE_HOME_LISTNER=/data01/oracleDB/product/11.2.0/db_1/

再次测试oracle服务脚本

cd /etc/rc.d/init.d

./oracle start

Processing Database instance "testsid": log file /data/oracle/product/11.2.0/db_1/startup.log

Oracle Start Succesful!OK.

发现之前关于监听的提示消失了,测试成功。

chkconfig --add oracle

chkconfig oracle on

chkconfig --list oracle

[root@centos7 init.d]# chkconfig --list  oracle

Note: This output shows SysV services only and does not include native

      systemd services. SysV configuration data might be overridden by native

      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.

      To see services enabled on particular target use

      'systemctl list-dependencies [target]'.

oracle          0:off   1:off   2:on    3:on    4:on    5:on    6:off

最后重启机器,确认自启动结果(看情况重启,测试脚本就随便重启)

[oracle@zm-centos7 ~]$ lsnrctl status   # 查看监听状态

 

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-OCT-2017 23:05:06

 

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                11-OCT-2017 23:02:22

Uptime                    0 days 0 hr. 2 min. 45 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /data01/oracleDB/product/11.2.0/db_1/network/admin/listener.ora

Listener Log File         /data01/oracle/diag/tnslsnr/zm-centos7/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))

Services Summary...

Service "test" has 1 instance(s).

  Instance "testsid", status READY, has 1 handler(s) for this service...

Service "testsidXDB" has 1 instance(s).

  Instance "testsid", status READY, has 1 handler(s) for this service...

The command completed successfully

查看oracle服务状态

ps -ef |grep ora

 

posted on 2019-01-15 14:08  luck666  阅读(1213)  评论(0编辑  收藏  举报

导航