Oracle单机怎么设置开机自启?

来源:这里教程网 时间:2026-03-03 22:02:08 作者:

Oracle    $ORACLE_HOME/bin  下提供许多对数据库进行操作的脚本,其中  dbstart    dbshut  可分别用来启动和关闭数据库。注意,这两个脚本已包含监听器的启动或关闭,但并未对  EM  进行相关的操作。使用如下命令:

1
2
/oracle/product/11.2.0/db_1/bin/dbstart   /oracle/product/11.2.0/db_1 #启动数据库实例(包含监听器)
/oracle/product/11.2.0/db_1/bin/dbshut /oracle/product/11.2.0/db_1   #关闭数据库实例(包括监听器)

以上命令要成功启动数据库实例还得打开  Oracle  设置的一个关卡:  vi /etc/oratab  ,修改行:

1
2
3
4
5
orcl:/oracle/product/11.2.0/db_1:
Y
  #
默认为
orcl:/oracle/product/11.2.0/db_1:N

这时候用命令启动会报  ORACLE_HOME_LISTNER  没有设置

1
2
[oracle@ primary  bin]$  /oracle/product/11.2.0/db_1/bin/dbstart  /oracle/product/11.2.0/db_1
ORACLE_HOME_LISTNER  is  not  SET , unable  to  auto-start Oracle Net Listener

修改  dbstart    dbshut

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
dbstart修改前
First    argument  is  used  to  bring up Oracle Net Listener
ORACLE_HOME_LISTNER=$1
if [ !   $ORACLE_HOME_LISTNER ] ;  then
   echo  "ORACLE_HOME_LISTNER is not SET,   unable to auto-start Oracle Net Listener"
   echo  "Usage: $0 ORACLE_HOME"
else
   LOG=$ORACLE_HOME_LISTNER/listener.log
   
dbstart修改后    
First    argument  is  used  to  bring up Oracle Net Listener
ORACLE_HOME_LISTNER=/u01/app/oracle/product/11.2.0/db_1                                   
   //    --/u01/app/oracle/product/11.2.0/db_1为$ORACLE_HOME
if [ !   $ORACLE_HOME_LISTNER ] ;  then
   echo  "ORACLE_HOME_LISTNER is not SET,   unable to auto-start Oracle Net Listener"
   echo  "Usage: $0 ORACLE_HOME"
else
   LOG=$ORACLE_HOME_LISTNER/listener.log

同理  dbshut  也做相应修改

在启动了  Linux  系统之后,转到    /etc/init.d   目录下;

1
[root@oracle ~]# cd /etc/init.d

        使用  vi  命令,新建一个以  oracle  命名的文件(并将以下代码复制至文件中)

1
[root@oracle init.d]# vi oracle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
#   chkconfig: 345 61 61
#   description: Oracle 11g AutoRun Services
#   /etc/init.d/oracle
#
#   Run- level  Startup script  for  the Oracle Instance, Listener,  and
# Web   Interface
  
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=ddhldata
export PATH=$ORACLE_HOME/bin:$PATH
  
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
      su $ORA_OWNR -lc   $ORACLE_HOME/bin/dbstart
      echo  "Oracle Start   Succesful!OK."
      ;;
  stop)
      # Oracle listener  and  instance shutdown
      su $ORA_OWNR -lc $ORACLE_HOME/bin/dbshut
      echo  "Oracle Stop   Succesful!OK."
      ;;
  reload|restart)
      $0 stop
      $0 start
      ;;
  *)
      echo $ "Usage: `basename $0`   {start|stop|reload|reload}"
      exit 1
esac
exit 0

赋予执行权限

1
[root@oracle init.d]# chmod 750 /etc/init.d/oracle

 

做一个链接  :

1
2
3
[root@oracle init.d]# ln -s /etc/init.d/oracle /etc/rc1.d/K61oracle
  
[root@oracle init.d]# ln -s /etc/init.d/oracle /etc/rc3.d/S61oracle

执行以下命令  :

1
2
3
[root@oracle init.d]# chkconfig  --level 345 oracle on
  
[root@oracle init.d]# chkconfig  --add oracle         //添加到服务里

相关推荐