Centos 7开机自启动oracle

环境:

OS:Centos 7

DB:11.2.0.4

 

方法一:启动脚本添加到/etc/rc.d/rc.local

1.修改/etc/oratab文件
[oracle@localhost ~]$ vim /etc/oratab
slnngk:/u01/app/oracle/product/11.2.0.4/db_1:N
修改为
slnngk:/u01/app/oracle/product/11.2.0.4/db_1:Y
(这个路径跟安装路径有关,$ORACLE_SID:$ORACLE_HOME:<N|Y>)

2.把lsnrctl start和dbstart添加到rc.local文件中:
root权限执行
[root@localhost oracle]# vim /etc/rc.d/rc.local
添加:
su - oracle -lc "/u01/app/oracle/product/11.2.0.4/db_1/bin/lsnrctl start"
su - oracle -lc "/u01/app/oracle/product/11.2.0.4/db_1/bin/dbstart"


说明:
第一行为开机启动数据库监听服务,第二行为开机启动数据库。(路径跟安装路径相关)。
注意:CentOs7中/etc/rc.d/rc.local不会开机执行,需添加执行权限。
查看/etc/rc.d/rc.local的权限
[root@localhost oracle]# ll /etc/rc.d/rc.local
添加执行权限
[root@localhost oracle]# chmod +x /etc/rc.d/rc.local

3.重启电脑后查看是否自启动成功

查看监听是否自启动成功
[oracle@localhost ~]$ lsnrctl status LISTENER
查看Oracle服务状态
[oracle@localhost ~]$ ps –ef | grep oracle

 

方法二:使用systemctl方式启动

 

[root@localhost system]# cat /usr/lib/systemd/system/oracle.service
[Unit]
Description=Oracle Database 12c Startup/Shutdown Service
After=syslog.target network.target
[Service]
LimitMEMLOCK=infinity
LimitNOFILE=65535
Type=oneshot
RemainAfterExit=yes
User=oracle
Environment="ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/db_1"
ExecStart=/u01/app/oracle/product/11.2.0.4/db_1/bin/dbstart $ORACLE_HOME >> 2>&1 &
ExecStop=/u01/app/oracle/product/11.2.0.4/db_1/bin/dbshut $ORACLE_HOME 2>&1 &
[Install]
WantedBy=multi-user.target


systemctl enable oracle
systemctl start oracle
systemctl stop oracle

 

posted @ 2021-08-31 16:21  slnngk  阅读(1180)  评论(0编辑  收藏  举报