oracle数据库自动启动配置
2023-12-27 07:21:28
前言
Oracle数据库默认情况下是不会随系统启动而启动的。在某些特殊情况下,有些用户希望可以自动启动,那么就需要手工编写相关的脚本来实现了。如下借鉴网络上的信息整理测试如下,经过测试可以正常运行。
Su -root
1.
mkdir /home/oracle/scripts
2.
cat > /home/oracle/scripts/setEnv.sh <<EOF
# Oracle Settings
export TMP=/tmp
export TMPDIR=\$TMP
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/12.2.0.1/db_1
export ORACLE_SID=betadb
export PATH=/usr/sbin:/usr/local/bin:\$PATH
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
EOF
3.
echo ". /home/oracle/scripts/setEnv.sh" >> /home/oracle/.bash_profile
4.
cat > /home/oracle/scripts/start_all.sh <<EOF
#!/bin/bash
. /home/oracle/scripts/setEnv.sh
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
dbstart \$ORACLE_HOME
EOF
cat > /home/oracle/scripts/stop_all.sh <<EOF
#!/bin/bash
. /home/oracle/scripts/setEnv.sh
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
dbshut \$ORACLE_HOME
EOF
chown -R oracle.oinstall /home/oracle/scripts
chmod u+x /home/oracle/scripts/*.sh
5.
You should be able to start/stop the database with the following scripts run from the "oracle" user.
$ ~/scripts/start_all.sh
$ ~/scripts/stop_all.sh
创建服务:
Create the service file called "/lib/systemd/system/dbora.service".
[Unit]
Description=The Oracle Database Service
After=syslog.target network.target
[Service]
# systemd ignores PAM limits, so set any necessary limits in the service.
# Not really a bug, but a feature.
# https://bugzilla.redhat.com/show_bug.cgi?id=754285
LimitMEMLOCK=infinity
LimitNOFILE=65535
#Type=simple
# idle: similar to simple, the actual execution of the service binary is delayed
# until all jobs are finished, which avoids mixing the status output with shell output of services.
RemainAfterExit=yes
User=oracle
Group=oinstall
Restart=no
ExecStart=/bin/bash -c '/home/oracle/scripts/start_all.sh'
ExecStop=/bin/bash -c '/home/oracle/scripts/stop_all.sh'
[Install]
WantedBy=multi-user.target
If you are using NFS storage, you need to define the dependency between Oracle and NFS.
[Unit]
Description=The Oracle Database Service
Requires=rpc-statd.service network.target nfs.service nfs-mountd.service local-fs.target remote-fs.target
After=syslog.target network.target nfs.service nfs-mountd.service local-fs.target rpc-statd.service remote-fs.target
[Service]
# systemd ignores PAM limits, so set any necessary limits in the service.
# Not really a bug, but a feature.
# https://bugzilla.redhat.com/show_bug.cgi?id=754285
LimitMEMLOCK=infinity
LimitNOFILE=65535
#Type=simple
# idle: similar to simple, the actual execution of the service binary is delayed
# until all jobs are finished, which avoids mixing the status output with shell output of services.
Type=idle
RemainAfterExit=yes
User=oracle
Group=oinstall
Restart=no
ExecStart=/bin/bash -c '/home/oracle/scripts/start_all.sh'
ExecStop=/bin/bash -c '/home/oracle/scripts/stop_all.sh'
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl start dbora.service
# systemctl enable dbora.service
ln -s '/usr/lib/systemd/system/dbora.service' '/etc/systemd/system/multi-user.target.wants/dbora.service'
# systemctl status dbora.service
dbora.service - The Oracle Database Service
Loaded: loaded (/lib/systemd/system/dbora.service; linked)
Active: active (exited) since Tue 2015-03-24 10:55:28 GMT; 5min ago
Process: 6145 ExecStart=/home/oracle/scripts/start_all.sh (code=exited, status=0/SUCCESS)
Main PID: 6145 (code=exited, status=0/SUCCESS)
Mar 24 10:56:27 ol7-121.localdomain startup.sh[6145]: SQL> ORACLE instance started.
Mar 24 10:56:27 ol7-121.localdomain startup.sh[6145]: Total System Global Area 1140850688 bytes
Mar 24 10:56:27 ol7-121.localdomain startup.sh[6145]: Fixed Size 2923584 bytes
Mar 24 10:56:27 ol7-121.localdomain startup.sh[6145]: Variable Size 419431360 bytes
Mar 24 10:56:27 ol7-121.localdomain startup.sh[6145]: Database Buffers 704643072 bytes
Mar 24 10:56:27 ol7-121.localdomain startup.sh[6145]: Redo Buffers 13852672 bytes
Mar 24 10:56:31 ol7-121.localdomain startup.sh[6145]: Database mounted.
Mar 24 10:56:33 ol7-121.localdomain startup.sh[6145]: Database opened.
Mar 24 10:56:33 ol7-121.localdomain startup.sh[6145]: SQL> Disconnected from Oracle Database 12c Enterprise Edition Re...ction
Mar 24 10:56:33 ol7-121.localdomain startup.sh[6145]: With the Partitioning, OLAP, Advanced Analytics and Real Applica...tions
Hint: Some lines were ellipsized, use -l to show in full.
#
文章来源:https://blog.csdn.net/bing_yuan/article/details/135234286
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!