Oracle 数据库和监听器开机自启动两种实现方法

Posted kingwwz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle 数据库和监听器开机自启动两种实现方法相关的知识,希望对你有一定的参考价值。

数据库和监听器开机自启动
 
编辑oratab文件:
修改:orcl:/u01/app/oracle/product/11.2.0/db_1:N
           orcl:/u01/app/oracle/product/11.2.0/db_1:Y
[[email protected] bin]$ vi /etc/oratab
#
 
 
# 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.
#
#
orcl:/u01/app/oracle/product/11.2.0/db_1:Y

  

  

执行dbstart和dbshut(数据库启动而监听器没有自启动)
[[email protected] ~]$ dbstart
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/app/oracle/product/11.2.0/db_1/bin/dbstart ORACLE_HOME
Processing Database instance "orcl": log file /u01/app/oracle/product/11.2.0/db_1/startup.log

  

 
修改dbstart和dbshut文件:
[[email protected] ~]$ cd $ORACLE_HOME/bin
[[email protected] bin]$ vi dbstart

  

 
找到这行修改为:
ORACLE_HOME_LISTNER=$1
ORACLE_HOME_LISTNER=$ORACLE_HOME
同上修改dbshut文件。
 
dbstart验证:
[[email protected] bin]$ dbstart
Processing Database instance "orcl": log file /u01/app/oracle/product/11.2.0/db_1/startup.log
[[email protected] bin]$ ps -ef|grep smon
oracle     4125      1  0 23:46 ?        00:00:00 ora_smon_orcl
oracle     4241   3254  0 23:46 pts/0    00:00:00 grep smon
[[email protected] bin]$ lsnrctl status
 
 
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-APR-2019 23:47:11
 
 
Copyright (c) 1991, 2009, Oracle.  All rights reserved.
 
 
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ocptest)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                21-APR-2019 23:46:20
Uptime                    0 days 0 hr. 0 min. 51 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/ocptest/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ocptest)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...

  

 
dbshut验证:
[[email protected] bin]$ dbshut
Processing Database instance "orcl": log file /u01/app/oracle/product/11.2.0/db_1/shutdown.log
[[email protected] bin]$ ps -ef|grep smon
oracle     4369   3254  0 23:48 pts/0    00:00:00 grep smon
[[email protected] bin]$ lsnrctl status
 
 
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-APR-2019 23:48:32
 
 
Copyright (c) 1991, 2009, Oracle.  All rights reserved.
 
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ocptest)(PORT=1521)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 111: Connection refused

  

 
添加开机自启动:
编辑/etc/rc.d/rc.local添加su oracle -lc /u01/app/oracle/product/11.2.0/db_1/bin/dbstart 到最后一行
[[email protected] ~]$ vi /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don‘t
# want to do the full Sys V style init stuff.
 
 
 
 
touch /var/lock/subsys/local
su oracle -lc /u01/app/oracle/product/11.2.0/db_1/bin/dbstart
如果上面没有编辑dbstart和dbshut文件添加侦听器参数:
则还需添加 su oracle -lc "/u01/oracle/bin/lsnrctl start"到/etc/rc.d/rc.local文件中;
 
 
第二种方法:
在oracle家目录创建两个文件:
oracle.start
oracle.stop
编辑:
vi oracle.start
[[email protected] ~]$ vi oracle.start
#!/bin/bash
source /u01/app/oracle/product/11.2.0/db_1
lsnrctl start;
sqlplus / as sysdba <<EOF
startup
EOF

  

vi oracle.stop
[[email protected] ~]$ vi oracle.stop
#!/bin/bash
source /u01/app/oracle/product/11.2.0/db_1
sqlplus / as sysdba <<EOF
startup
EOF
lsnrctl stop;

 

权限:
chmod +x /etc/init.d/oracle
chmod a+x oracle.start oracle.stop
 
单独执行这两个脚本进行验证;
 
通过copy一个network模板
cp /etc/init.d/network /etc/init.d/oracle
[[email protected] ~]# vi /etc/init.d/oracle
#! /bin/bash
#
# oracle       Bring up/down oracle
#
# chkconfig: 2345 90 1
# description: Activates/Deactivates all oracle configured to #              start at boot time.
#
# Source function library.
. /etc/init.d/functions
 
 
# See how we were called.
case "$1" in
  start)
        su - oracle -c "/home/oracle/oracle.start"
        ;;
  stop)
        su - oracle -c "/home/oracle/oracle.stop"
        ;;
  *)
        echo $"Usage: $0 {start|stop}"
        exit 2
esac
chkconfig oracle on
 然后重启服务器测试下,我这里测试都没问题。
 
验证端口:
[[email protected] ~]$ netstat -an|grep :1521
tcp        0      0 192.168.181.2:62747         192.168.181.2:1521          ESTABLISHED
tcp        0      0 :::1521                     :::*                        LISTEN
tcp        0      0 ::ffff:192.168.181.2:1521   ::ffff:192.168.181.2:62747  ESTABLISHED

  

 

以上是关于Oracle 数据库和监听器开机自启动两种实现方法的主要内容,如果未能解决你的问题,请参考以下文章

ORACLE 12C 开机自动启动监听CDBPDB

如何实现apk安装后自启动

Linux配置开机自启动的两种方法

Android APP开机自启动基本方法

如何让oracle DB监听和oem开机启动(dbstart)

Linux下开机自动启动Oracle的设置