linux下oracle自动启动配置步骤

来源:互联网 发布:ubuntu emacs 安装 编辑:程序博客网 时间:2024/05/22 12:43

[oracle@www ~]$ cat /etc/oratab
orcl:/usr/app/oracle/product/10.2.0/db_l:Y #N

 

2.用oracle用户(你装ORACLE数据库的用户)登录系统
      修改$ORACLE_HOME/bin/dbstart文件
  $vi $ORACLE_HOME/bin/dbstart
  找到 ORACLE_HOME_LISTNER=.....这行, 修改成
       ORACLE_HOME_LISTNER=/u01/app/oracle/product/10.2.0/db_1
            或者直接修改成:
       ORACLE_HOME_LISTNER=$ORACLE_HOME
      
 3.测试运行dbshut,dbstart
  (1)修改dbstart和dbshut的日志文件的权限:
   $su - root
   #cd $ORACLE_HOME
   #chown oracle:oinstall startup.log
   #chown oracle:oinstall shutdown.log
  (2)执行相应的脚本进行测试
   #su oracle
   $cd $ORACLE_HOME/bin
   $./dbstart   (./dbshut)
   $ ps -efw | grep ora_
   $ lsnrctl status
   $ ps -efw | grep LISTEN | grep -v grep


[oracle@www ~]$ cat /home/oracle/.bash_profile
# .bash_profile
 
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
#oracle profile
TMP=/tmp;export TMP
TMPDIR=$TMP;export TMPDIR
ORACLE_BASE=/usr/app/oracle;export ORACLE_BASE
TMP=/tmp;export TMP
TMPDIR=$TMP;export TMPDIR
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_l;
export ORACLE_HOME
ORACLE_SID=orcl;
TMP=/tmp;export TMP
TMPDIR=$TMP;export TMPDIR
export ORACLE_SID
ORACLE_TERM=xterm;
export ORACLE_TERM
PATH=$PATH:$ORACLE_HOME/bin;
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;
export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;
export CLASSPATH
#export DISPLAY=192.168.0.33:0.0
export DISPLAY=127.0.0.1:0.0
export LANG=AMRICAN
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
 
#oracle profile end

 

[oracle@www ~]$ source /home/oracle/.bash_profile
[oracle@www ~]$ host +
+.localdomain has address 202.106.199.36
Host +.localdomain not found: 3(NXDOMAIN)
Host +.localdomain not found: 3(NXDOMAIN)


[oracle@www init.d]$ cat /home/oracle/oradbstart
#!/bin/bash
# chkconfig: 345 99 10
# description: Startup Script for oracle Databases
# /etc/rc.d/init.d/dbstart
export ORACLE_BASE=/usr/app/oracle/
export ORACLE_HOME=/usr/app/oracle/product/10.2.0/db_l
export 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
    echo -n "Starting Oracle: "
     su $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl start " 
     su $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart" 
    touch /var/lock/oracle
     su $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole"
     su $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctl start"
    echo "OK"
    ;;
 
  stop)
    # Oracle listener and instance shutdown
    echo -n "Shutdown Oracle: "
    su $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole"
    su $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctl stop"
    su $ORA_OWNR -c "$ORACLE_HOME/bin/dbshut"
    su $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
    rm -f /var/lock/oracle
    echo "OK"
    ;;
 
  reload|restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: `basename $0` start|stop|restart|reload"
    exit 1
esac
exit 0
 
 
[oracle@www init.d]$ chkconfig --add oradbstart
[oracle@www init.d]$ chkconfig --list oradbstart


测试服务(快速启动Oracle)
 /etc/rc.d/init.d/oradbstart stop
 /etc/rc.d/init.d/oradbstart start
 /etc/rc.d/init.d/oradbstart restart(或者reload)

 

 

重启linux
reboot -n
   在linux启动的时候,你就可以看到一个启动项oracle10g,出现[OK]的时候,
就表示你的数据库随系统启动了。

3.1 重启Linux后,查看进程
 ps -ef|grep ora_|grep -v grep
 ps -ef|grep tnslsnr|grep -v grep

3.2 sqlplus测试进入
 sqlplus '/as sysdba'
 
 


三:Oracle启动有关的命令说明
 一般是执行:(在oracle用户下)
     $ lsnrctl start  #启动监听
     $ dbstart      #启动数据库
     $ emctl start dbconsole  #启动控制台
     $ isqlplusctl start      #pl/sql启动
 如果你有多个数据库,当执行完以上后,还需要设置ORACLE_SID参数,以启动另外一个数据库如下:
     $exopt ORACLE_SID=ORA2  #需求启动的服务
     $ lsnrctl start
     $ dbstart
     $ emctl start dbconsole
     $ isqlplusctl start
    
    

 
四:关于系统开机自动启动
系统脚本可以放置在/etc/rc.d/init.d中并建立/etc/rc.d/rc?.d链接,也可以直接放置在/etc/rc.d/rc.local中。
init.d脚本包含完整的start,stop,status,reload等参数,是标准做法,推荐使用。
为特定用户使用的程序(如有的用户需要使用中文输入法而有的不需要)放置在~/中的bash启动脚本中。
 下面用自启动apache为例;
 a.自启动脚本:
  /usr/local/apache2/bin;
  ./apachectl start
 b.文件位于/etc/rc.d/init.d下,名为apached, 注意要可执行.
  #chmod +x /etc/rc.d/init.d/apached //设置文件的属性为可执行
  #ln -s /etc/rc.d/init.d/apached /etc/rc3.d/S90apache //建立软连接,快捷方式
  #ln -s /etc/rc.d/init.d/apached /etc/rc0.d/K20apache
 c.启动级别说明:
  #说明:
   #等级0表示:表示关机
   #等级1表示:单用户模式
   #等级2表示:无网络连接的多用户命令行模式
   #等级3表示:有网络连接的多用户命令行模式
   #等级4表示:不可用
   #等级5表示:带图形界面的多用户模式
   #等级6表示:重新启动
       For example, random.init has these three lines:
         # chkconfig: 2345 20 80
         # description: Saves and restores system entropy pool for /
         #              higher quality random number generation.
         This says that the random script should be started in levels 2,  3,  4,
         and 5, that its start priority should be 20, and that its stop priority
         should be 80.  You should be able to figure out  what  the  description
         says;  the / causes the line to be continued.  The extra space in front
         of the line is ignored.