Linux Oracle service start & stop script and boot self-start

After installing Oracle 10g R2 under CentOS 6.3, after rebooting, you will find that Oracle does not start by itself, which is normal, because installing Oracle under Linux does not start by itself, you must set the relevant parameters by yourself, first introduce How to start oracle in general.

1. Start Oracle under Linux

Log in to CentOS and switch to oracle user authority

# su – oracle

Then enter:

$ sqlplus "/as sysdba"

The original screen will change to
SQL>

Then enter
SQL> startup

The database can be started normally.

In addition, the command to stop the database is as follows:
SQL> shutdown immediate

2. Check whether the Oracle DB listener is normal

Back in terminal mode, enter:

$ lsnrctl status

Check to see if the listener is started

If it doesn't start, you can enter:

$ lsnrctl start

start the listener

SQL> conn sys@orcl as sysdba

Then enter the password, and sys logs in to the database as sysdba.

3. Start emctl

In addition, it can also be found that http://localhost.localdomain:1158/em is currently unresponsive. It needs to be started separately here. The startup instructions are as follows:

$ emctl start dbconsole

This command runs for a long time, and the screen after execution is as follows:

After manually starting the Oracle database, create a script for the system to start Oracle by itself.

Fourth, Oracle start & stop script

1. Modify the Oracle system configuration file: /etc/oratab. Only in this way can Oracle's own dbstart and dbshut work.

# vi /etc/oratab
orcl:/opt/oracle/102:Y

# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:

2. 在 /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=/opt/oracle/102
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
 

3. 改变文件权限
# chmod 755 /etc/init.d/oracle

4. 添加服务
# chkconfig --level 35 oracle on

5. 需要在关机或重启机器之前停止数据库,做一下操作
# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle   //关机
# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle   //重启 

6. 使用方法
# service oracle start        //启动oracle
# service oracle stop        //关闭oracle
# service oracle restart     //重启oracle

7. 测试

a. 开机自启动

 
Last login: Mon Nov 26 19:57:06 2012 from 10.0.0.145
[root@ORS ~]# su - oracle
[oracle@ORS ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Nov 26 20:07:33 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> set linesize 300;
SQL> set pagesize 30;
SQL> select * from scott.emp;

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10

14 rows selected.

SQL>
 

b. service oracle stop

复制代码
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@ORS ~]$ logout
[root@ORS ~]# service oracle stop
Stoping Oracle Listeners ... 
Done.
Stoping Oracle Databases ... 
Done.

[root@ORS ~]# su - oracle
[oracle@ORS ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Nov 26 20:17:20 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> set linesize 300;
SQL> set pagesize 30;
SQL> select * from scott.emp;
select * from scott.emp
*
ERROR at line 1:
ORA-01034: ORACLE not available


SQL> 
复制代码

c. service oracle start

复制代码
SQL> Disconnected
[oracle@ORS ~]$ logout
[root@ORS ~]# service oracle start
Starting Oracle Databases ... 
Done
Starting Oracle Listeners ... 
Done.
[root@ORS ~]# 
复制代码

d. service oracle restart

复制代码
[root@ORS ~]# service oracle restart
Stoping Oracle Listeners ... 
Done.
Stoping Oracle Databases ... 
Done.

Starting Oracle Databases ... 
Done
Starting Oracle Listeners ... 
Done.
[root@ORS ~]# 
复制代码

至此,Oracle服务启动&停止脚本与开机自启动设置完毕。

 

CentOS 6.3(x32)下安装Oracle 10g R2

http://www.cnblogs.com/mchina/archive/2012/11/06/2737472.html

 


David Camp

我们永远相信,分享是一种美德 | We Believe, Great People Share Knowledge...

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326117170&siteId=291194637