创建oracle数据库后配置自启动

来源:互联网 发布:eviews mac 破解版 编辑:程序博客网 时间:2024/06/06 04:31

一、创建oracle数据库后配置自启动

1、

1.1、修改$ORACLE_HOME/bin/dbstart

# id

uid=0(root) gid=0(root) 组=0(root)
# vi /etc/oratab
boss:/oracle/product/10.2.0:Y
# su - oracle

$ cd $ORACLE_HOME/bin/
$ lsnrctl status

$ vi $ORACLE_HOME/bin/dbstart

ORACLE_HOME_LISTNER=$ORACLE_HOME


1.2、创建oracle启动的脚本

# vi /etc/rc.d/init.d/oracle
#!/bin/sh
#
# chkconfig: 345 99 99
# description: init script to start/stop oracle database 10g, TNS listener

# match these values to your environment:
export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=boss
export DISPLAY=:0
export ORACLE_USER=oracle
# see how we are called:
case $1 in
        start)
        su - "$ORACLE_USER"<<EOF
        lsnrctl start
        sqlplus /nolog<<EOS
        connect / as sysdba
        startup
        exit
EOS
EOF
touch /var/lock/subsys/$scriptname
        ;;
        stop)
        su - "$ORACLE_USER"<<EOF
        lsnrctl stop
        sqlplus /nolog<<EOS
        connect / as sysdba
        shutdown immediate
        exit
EOS
EOF
rm -f /var/lock/subsys/scriptname
        ;;
        *)
        echo "Usage: $0 {start|stop}"
        ;;
esac

1.3、检查启动脚本是否可以启动oracle

# su - oracle
$ lsnrctl start
# cd /etc/rc.d/init.d
# ./oracle start  ##没有执行权限x
-bash: ./oracle: 权限不够
# chmod 755 /etc/rc.d/init.d/oracle
# ./oracle start

LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 06-MAY-2014 11:27:35

# service oracle start

LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 06-MAY-2014 11:29:22

##重启系统之后,发现不能启动监听器等
$ lsnrctl status
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 06-MAY-2014 11:34:32

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 2: No such file or directory
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=auth-acco-1)(PORT=1521)))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 111: Connection refused


1.4、配置oracle随系统启动,必须执行该项,否则oracle不会随系统启动

# cd /etc/rc.d/init.d
# chkconfig –-add oracle
chkconfig 版本 1.3.49.3 - 版权 (C) 1997-2000 Red Hat, Inc.
在 GNU 公共许可的条款下,本软件可以被自由发行。
用法:   chkconfig [--list] [--type <type>] [name]
         chkconfig --add <name>
         chkconfig --del <name>
         chkconfig --override <name>
         chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>
# ln -s /etc/init.d/oracle /etc/rc1.d/K61oracle
# ln -s /etc/init.d/oracle /etc/rc3.d/S61oracle
# chkconfig --level 345 oracle on

# chkconfig --add oracle
##重启系统之后
# su - oracle
$ lsnrctl status

LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 06-MAY-2014 11:50:12

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date                06-MAY-2014 11:50:03
Uptime                    0 days 0 hr. 0 min. 8 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle/product/10.2.0/network/admin/listener.ora
Listener Log File         /oracle/product/10.2.0/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=auth-acco-1)(PORT=1521)))
Services Summary...
Service "BOSS" has 2 instance(s).
  Instance "boss", status UNKNOWN, has 1 handler(s) for this service...
  Instance "boss", status READY, has 1 handler(s) for this service...
Service "boss_XPT" has 1 instance(s).
  Instance "boss", status READY, has 1 handler(s) for this service...
The command completed successfully

0 0