准备工作
版本
Linux版本:Oracle Linux 6.3
Oracle版本:Oracle11.2.0.4
也适用于centos,Oracle 11 R2其他版本
安装,配置环境变量 .bash_profile
关于安装的教程很多,不赘述
这里贴出我自己的 .bash_profile
JAVA_HOME=/usr/java/jdk1.8.0_144
ORACLE_SID=orcl
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
PATH=$ORACLE_HOME/bin:$JAVA_HOME/bin:$PATH
export JAVA_HOME ORACLE_SID ORACLE_BASE ORACLE_HOME
export PATH
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
步骤
修改/etc/oratab:将N 改为Y
orcl:/u01/app/oracle/product/11.2.0/dbhome_1:Y
切换到root用户,在/etc/init.d中创建oracle文件并将下面内容添加到文件中
将ORA_HOME 与ORA_OWNER 替换成你自己的#!/bin/sh # chkconfig: 2345 80 20 # description: Oracle auto start-stop script. # # Set ORA_HOME to be equivalent to the $ORACLE_HOME # from which you wish to execute dbstart and dbshut; # # Set ORA_OWNER to the user id of the owner of the # Oracle database in ORA_HOME. ORA_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 ORA_OWNER=oracle if [ ! -f $ORA_HOME/bin/dbstart ] then echo "Oracle startup: cannot start" exit fi case "$1" in 'start') # Start the Oracle databases: echo "Starting Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle echo "Done" # Start the Listener: echo "Starting Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle echo "Done." echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle touch /var/lock/subsys/oracle ;; 'stop') # Stop the Oracle Listener: echo "Stoping Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle echo "Done." rm -f /var/lock/subsys/oracle # Stop the Oracle Database: echo "Stoping Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle echo "Done." echo "" echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle ;; 'restart') $0 stop $0 start ;; esac
设置权限
chmod a+x /etc/init.d/oracle
添加到服务中心
输入如下命令chkconfig --add oracle
添加到/etc/rc.d/rc.local 中
编辑 /etc/rc.d/rc.local,在末尾添加/etc/init.d/oracle start
测试
终端输入 reboot 重启机器
等待机器重启后
输入 lsnrctl status 查看实例状态
数据库也可以连上
还可以在/var/log文件夹中查看oracle 日志文件
cat /var/log/oracle