安裝oracle-database-server-12cR2-preinstallhtml
wget http://public-yum.oracle.com/public-yum-ol7.repo -O /etc/yum.repos.d/public-yum-ol7.repo wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol7 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle yum clean all yum -y update yum -y groupinstall 'X Window System' yum -y install oracle-database-server-12cR2-preinstall
建立Oracle安裝目錄java
mkdir -p /u01/app/oracle/product/12.2.0.1/db_1 chown -R oracle:oinstall /u01 chmod -R 775 /u01
建立oracle環境變量配置文件sql
mkdir /home/oracle/scripts cat > /home/oracle/scripts/setEnv.sh <<EOF # Oracle Settings export TMP=/tmp export TMPDIR=\$TMP export ORACLE_HOSTNAME=ol7-122.localdomain export ORACLE_UNQNAME=cdb1 export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=\$ORACLE_BASE/product/12.2.0.1/db_1 export ORACLE_SID=cdb1 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 echo ". /home/oracle/scripts/setEnv.sh" >> /home/oracle/.bash_profile
建立Oracle啓動腳本,放在 /home/oracle/scripts/dbora.sh
:bash
#!/bin/bash . /home/oracle/scripts/setEnv.sh export ORAENV_ASK=NO . oraenv export ORAENV_ASK=YES startup_log=/home/oracle/scripts/startup.log shutdown_log=/home/oracle/scripts/shutdown.log function oracle_start(){ # Start the Oracle databases: echo "-------------------------------------------------" date +" %T %a %D : Starting Oracle Databases as part of system up." echo "-------------------------------------------------" ${ORACLE_HOME}/bin/sqlplus /nolog << EOF conn / as sysdba startup alter pluggable database all open; exit EOF echo "Done." # Start the Listener: echo "-------------------------------------------------" date +" %T %a %D : Starting Oracle Listeners as part of system up." echo "-------------------------------------------------" ${ORACLE_HOME}/bin/lsnrctl start echo "Done." echo "-------------------------------------------------" date +" %T %a %D : Finished." echo "-------------------------------------------------" } function oracle_stop(){ # Stop the Oracle Listener: echo "-------------------------------------------------" date +" %T %a %D : Stoping Oracle Listener as part of system down." echo "-------------------------------------------------" ${ORACLE_HOME}/bin/lsnrctl stop echo "Done." # Stop the Oracle Database: echo "-------------------------------------------------" date +" %T %a %D : Stoping Oracle Databases as part of system down." echo "-------------------------------------------------" ${ORACLE_HOME}/bin/sqlplus /nolog << EOF conn / as sysdba alter pluggable database all close immediate; shutdown immediate exit EOF echo "Done." echo "" echo "-------------------------------------------------" date +" %T %a %D : Finished." echo "-------------------------------------------------" } case "$1" in start) echo "Starting Oracle Databases ... " oracle_start >> $startup_log echo "Oracle Started Successfully." ;; stop) echo "Stoping Oracle Databases ... " oracle_stop >> $shutdown_log echo "Oracle Stopped." ;; restart) echo "Restarting Oracle Databases ... " oracle_stop >> $shutdown_log oracle_start >> $startup_log echo " Oracle Restarted." ;; status) ${ORACLE_HOME}/bin/lsnrctl status ;; *) echo "Usage: $(basename $0) {start|strop|restart|status}" exit 1 esac exit 0
調整腳本文件權限:oracle
chown -R oracle.oinstall /home/oracle/scripts chmod u+x /home/oracle/scripts/*.sh
編寫 systemd.service
服務腳本,在 /etc/systemd/system/oracle.service
:app
[Unit] Description=Oracle Service After=network.target After=syslog.target [Service] User=oracle Group=dba Type=oneshot ExecStart=/home/oracle/scripts/dbora.sh start ExecReload=/home/oracle/scripts/dbora.sh restart ExecStop=/home/oracle/scripts/dbora.sh stop RemainAfterExit=yes [Install] WantedBy=multi-user.target
以root
用戶執行:systemctl enable oracle.service
完成後便可啓動Oracle Universal Installations (OUI)dom