参考:http://www.jb51.net/article/32214.htm
创新互联是一家网站设计公司,集创意、互联网应用、软件技术为一体的创意网站建设服务商,主营产品:自适应网站建设、品牌网站设计、成都全网营销推广。我们专注企业品牌在网站中的整体树立,网络互动的体验,以及在手机等移动端的优质呈现。网站设计、成都网站设计、移动互联产品、网络运营、VI设计、云产品.运维为核心业务。为用户提供一站式解决方案,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏析悦目的作品,网站的价值服务。
1. Oracle的一些基本参数
[oracle@localhost ~]$ echo $ORACLE_SID
adela
[oracle@localhost ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/12.1.0/db_1
[oracle@localhost ~]$ echo $ORACLE_BASE
/u01/app/oracle
2. 修改/etc/oratab,使Oracle可以自启动
[oracle@localhost ~]$ vim /etc/oratab
增加一行
# $ORACLE_SID:$ORACLE_HOME:
adela:/u01/app/oracle/product/12.1.0/db_1:Y
3. 在 /etc/init.d/ 下创建文件oracle
[root@localhost ~]# touch /etc/init.d/oracle
[root@localhost ~]# chmod 755 /etc/init.d/oracle
[root@localhost ~]# vim /etc/init.d/oracle
添加如下脚本
#!/bin/sh # chkconfig: 35 80 10 # 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/12.1.0/db_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
4. 添加服务
[root@localhost ~]# chkconfig --level 35 oracle on
5. 需要在关机或重启机器之前停止数据库,做以下操作
[root@localhost ~]# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle //关机
[root@localhost ~]# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle //重启
6. 测试命令是否有效
[root@localhost ~]# service oracle start //启动oracle
Starting Oracle Databases ...
Done
Starting Oracle Listeners ...
Done.
[root@localhost ~]# service oracle stop //关闭oracle
Stoping Oracle Listeners ...
Done.
Stoping Oracle Databases ...
Done.
# service oracle restart //重启oracle
[root@localhost ~]# service oracle restart
Stoping Oracle Listeners ...
Done.
Stoping Oracle Databases ...
Done.
Starting Oracle Databases ...
Done
Starting Oracle Listeners ...
Done.
7. 重启Linux
[root@localhost ~]# reboot
8. 重启后进入oracle用户,进sqlplus
[oracle@localhost Desktop]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Sat Jul 18 23:16:17 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> set linesize 300;
SQL> set pagesize 30;
SQL> select sysdate from dual;
SYSDATE
---------
18-JUL-15
数据库正常启动!