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

  

原文地址:https://www.cnblogs.com/kingwwz/p/10759685.html

时间: 2024-08-08 12:00:17

Oracle 数据库和监听器开机自启动两种实现方法的相关文章

ORACLE数据库实现自增的两种方式

Mysql数据库因为其有自动+1,故一般我们不需要花费太多时间,直接用关键字auto_increment即可,但是Oracle不行,它没有自动增长机制.顾我们需要自己去实现.一般有两种方式,但是这两种方式都与序列化有关.第一种方式:序列化+触发器:第二种方式:序列化+显示调用序列化.一般我选用第一种方式.因为我们只要建立好序列化+触发器,这样我们就需要太多的去关注这个字段了,触发器会在我们插入数据时自动触发,帮助我们进行+1操作.这正好解决了我最近做的一个mini项目中的部门删除操作(子部门与父

MySQL数据库远程访问权限如何打开(两种方法)

MySQL数据库远程访问权限如何打开(两种方法) 下载GPL版本安装 MySQL Community Edition(GPL) Community (GPL) Downloads 在我们使用mysql数据库时,有时我们的程序与数据库不在同一机器上,这时我们需要远程访问数据库.缺省状态下,mysql的用户没有远程访问的权限. 下面介绍两种方法,解决这一问题. 1.改表法 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "

ASP+中文显示之两种解决方法

作者刚开始写ASP+程序时候碰到的第一个比较大的问题就是中文显示问题,运行后发现ASP+从数据库中读 取出来的中文全部变成了?????,有点类似jsp中的这个频率出现最高的中文显示问题了,查了资料发现有 两种方法可以轻松解决中文问题. 方法一: 在翻阅了微软NGWS文档后发现在文档的常见问题部分有提到要添加一个config.web文件到 web目录下,试了一下,中文显示果然OK了. 方法如下: 建立一个文件config.web,内容如下,放在WEB目录下 <configuration> <

黑马程序员【两种Ajax方法】

两种Ajax方法 Ajax是一种用于快速创建动态网页的技术,他通过在后台与服务器进行少量的数据交换,可以实现网页的异步更新,不需要像传统网页那样重新加载页面也可以做到对网页的某部分作出更新,现在这项技术已经被人们广泛应用,而对于一些对Web的了解还不是很深入的初学者,Ajax依然带着一层神秘的难懂的色彩,今天就在这里给大家以简单的方式解读一下Ajax的实现步骤和原理,并且给大家两种实现Ajax的方法,js和jquery. 首先ajax其实就是js+xml的技术,前端的表现就是一段js代码.要使用

C#中的两种debug方法介绍

第一种:需要把调试方法改成debug 代码用 #if DEBUG 包裹 using System; using System.Collections.Generic; using System.Text; using System.IO; namespace SplitPackage { public static class EnvConfig { static EnvConfig() { #if DEBUG ToolsPath = @"D:\workspace\shopstyle\tool&

基于Apache+Tomcat负载均衡的两种实现方法

Apache+Tomcat实现负载均衡的两种实现方法 如果我们将工作在不同平台的apache能够实现彼此间的高效通信,因此它需要一种底层机制来实现--叫做apr Apr的主要目的就是为了其能够让apache工作在不同的平台上,但在linux上安装apache的时候通常都是默认安装的 [[email protected] ~]#rpm -qi aprName                 :apr                                        Relocation

OGG的Director web hang住的两种解决方法

OGG的Director web hang住的两种解决方法: OGG的Director web hang住的解释:是指web界面能登陆进去,但是看得刷新日期是很久之前的日期,并且该日期不变化. OGG的Director web hang住 的情况之一: 参考如下的mos文章: Director web displaying "Error 500-Internal Server Error". Domain log has Cannot open paging store. (Doc I

git两种合并方法 比较merge和rebase

18:01 2015/11/18git两种合并方法 比较merge和rebase其实很简单,就是合并后每个commit提交的id记录的顺序而已注意:重要的是如果公司用了grrit,grrit不允许用merge,所以好像都是用rebase却别讲解,比如:在服务器上的develop分支有多人在开发,你们同时clone或pull下来最新代码,但是开发进度不一样,你在开发一个任务的时候其他人提交了编号为1,2的commit和push,你现在开发完了也要提交,你的提交编号是3,4(注意:编号不代表顺序现实

Eclipse web工程创建步骤及两种部署方法

1.Eclipse创建web工程步骤 (1)参考1(2)参考2 2.web工程两种部署方法 (1)部署方法同1中所述 (2)部署到Tomcat Server的webapps目录下的方法