重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2286|回复: 2
打印 上一主题 下一主题

oracle for linux 自动启动

[复制链接]
跳转到指定楼层
楼主
发表于 2015-6-5 11:41:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.切换到root用戶
su -
2.产生服务配置文件
touch /etc/rc.d/init.d/ora_SID   #SID为oracle sid
3.修改配置文件权限
chmod 775 /etc/rc.d/init.d/ora_SID   #SID为oracle sid
4.vi /etc/rc.d/init.d/ora_SID    #SID为oracle sid
加入以下
#!/bin/bash
#
# chkconfig: 35 95 1
# description: init script to start/stop oracle database 10g, TNS listener, EMS
# match these values to your environment:
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_TERM=xterm
export PATH=/home/oracle/bin:$ORACLE_HOME/bin:$PATH:.
export NLS_LANG='croatian_croatia.ee8iso8859p2'
export ORACLE_SID=SID  #SID为oracle sid
export DISPLAY=localhost:0
export ORACLE_USER=oracle

case $1 in
    start)
    su - "$ORACLE_USER"<<EOO
    ORACLE_SID=SID  #SID为oracle sid
    lsnrctl start
    sqlplus /nolog<<EOS
    connect / as sysdba
    startup force;
EOS
EOO
    ;;
    stop)
    su - "$ORACLE_USER"<<EOO
    ORACLE_SID=SID  #SID为oracle sid
    lsnrctl stop
    sqlplus /nolog<<EOS
    connect / as sysdba
    shutdown immediate
EOS
EOO
    ;;
    status)
    su - "$ORACLE_USER"<<EOO
    ORACLE_SID=SID  #SID为oracle sid
    lsnrctl status
    emctl status dbconsole
EOO
    ;;
    *)
    echo "Usage: $0 {start|stop}"
    ;;
esac
5.加入到linux系统服务中
chkconfig --add ora_SID  #SID为oracle sid
6.设置此服务开机自动启动
setup->System services->ora_SID  #SID为oracle sid











分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

沙发
 楼主| 发表于 2015-6-5 11:43:15 | 只看该作者
测试运行dbshut,dbstart
  (1)修改dbstart和dbshut的日志文件的权限:
注:startup.log 和shutdown.log 可能没有,当你运行 ./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'
回复 支持 反对

使用道具 举报

板凳
发表于 2015-6-5 14:28:44 | 只看该作者

不错的方法 ,单机上面可以一用。

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-5-19 16:13 , Processed in 0.086721 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表