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
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)
分类:
Oracle
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?