Oracle如何设置在Linux上设置自启动(无crs/has管理)

 

Oracle如何设置在Linux上设置自启动(无crs/has管理)

 

安装了crs或者has的无需通过此方式。

官方提供的方式。

 

1.修改文件/etc/oratab:

   <SID>:<ORACLE_HOME>:Y
改为Y状态。
Y状态表示可以通过自带的脚本dbstart和dbshut来启动和关闭。
 
2.创建脚本:/etc/init.d/dbora
修改第13和14行
 1  #!/bin/bash
 2  #
 3  # chkconfig: 35 99 10   
 4  # description: Starts and stops Oracle processes
 5  #
 6  # Set ORA_HOME to be equivalent to the $ORACLE_HOME
 7  # from which you wish to execute dbstart and dbshut;
 8  #
 9  # Set ORA_OWNER to the user id of the owner of the
10  # Oracle database in ORA_HOME.
11  #
12 
13  ORA_HOME=<Type your ORACLE_HOME in full path here>
14  ORA_OWNER=<Type your Oracle account name here>
15 
16  case "$1" in
17    'start')
18       # Start the TNS Listener
19       su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
20  
21       # Start the Oracle databases:
22       # The following command assumes that the oracle login
23       # will not prompt the user for any values
24       su - $ORA_OWNER -c $ORA_HOME/bin/dbstart
25 
26       # Start the Intelligent Agent
27       if [ -f $ORA_HOME/bin/emctl ]; then
28          su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start agent"
29       elif [ -f $ORA_HOME/bin/agentctl ]; then
30          su - $ORA_OWNER -c "$ORA_HOME/bin/agentctl start"
31       else
32          su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl dbsnmp_start"
33       fi
34 
35       # Start Management Server
36       if [ -f $ORA_HOME/bin/emctl ]; then
37          su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
38       elif [ -f $ORA_HOME/bin/oemctl ]; then
39          su - $ORA_OWNER -c "$ORA_HOME/bin/oemctl start oms"
40       fi
41 
42       # Start HTTP Server
43       if [ -f $ORA_HOME/Apache/Apache/bin/apachectl ]; then
44          su - $ORA_OWNER -c "$ORA_HOME/Apache/Apache/bin/apachectl start"
45       fi
46 
47       touch /var/lock/subsys/dbora
48       ;;
49 
50    'stop')
51       # Stop HTTP Server
52       if [ -f $ORA_HOME/Apache/Apache/bin/apachectl ]; then
53          su - $ORA_OWNER -c "$ORA_HOME/Apache/Apache/bin/apachectl stop"
54       fi
55 
56       # Stop the TNS Listener
57       su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
58 
59       # Stop the Oracle databases:
60       # The following command assumes that the oracle login
61       # will not prompt the user for any values
62       su - $ORA_OWNER -c $ORA_HOME/bin/dbshut
63 
64       rm -f /var/lock/subsys/dbora
65       ;;
66  esac
67 
68  # End of script dbora
View Code

 

3.设置脚本权限:

chmod 755 /etc/init.d/dbora
chown oracle:oinstall /etc/init.d/dbora

 

4.注册服务(Linux 6)

chkconfig --add dbora

 

4.注册服务(Linux 7)

vi /usr/lib/systemd/system/dbora.service
[Unit]
Description=Oracle Database Start/Stop Service
After=syslog.target network.target local-fs.target remote-fs.target
[Service]
# systemd, by design does not honor PAM limits
# See: https://bugzilla.redhat.com/show_bug.cgi?id=754285
LimitNOFILE=65536
LimitNPROC=16384
LimitSTACK=32M
LimitMEMLOCK=infinity
LimitCORE=infinity
LimitDATA=infinity

Type=simple
User=oracle
Group=oinstall
Restart=no
ExecStartPre=/bin/rm -rf /u01/app/oracle/product/11.2.0/db_1/listener.log
ExecStartPre=/bin/rm -rf /u01/app/oracle/product/11.2.0/db_1/startup.log
ExecStart=/bin/bash /u01/app/oracle/product/11.2.0/db_1/bin/dbstart /u01/app/oracle/product/11.2.0/db_1
RemainAfterExit=yes
ExecStop=/bin/rm -rf /u01/app/oracle/product/11.2.0/db_1/shutdown.log
ExecStop=/bin/bash /u01/app/oracle/product/11.2.0/db_1/bin/dbshut /u01/app/oracle/product/11.2.0/db_1
TimeoutStopSec=5min

[Install]
WantedBy=multi-user.target

 

 

重载并并设置自启动服务:

systemctl daemon-reload
systemctl enable dbora

 

 

参考文档

How to Automate Startup/Shutdown of Oracle Database on Linux (文档 ID 222813.1)

Automatic Stop of Database (dbshut) not working in OL 7 with systemd (文档 ID 2229679.1)

posted @ 2022-09-20 16:20  PiscesCanon  阅读(82)  评论(0编辑  收藏  举报