標籤:case home echo multi rdbms pat .com setting finish
安裝oracle-database-server-12cR2-preinstall
wget http://public-yum.oracle.com/public-yum-ol7.repo -O /etc/yum.repos.d/public-yum-ol7.repowget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol7 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracleyum clean allyum -y updateyum -y groupinstall 'X Window System'yum -y install oracle-database-server-12cR2-preinstall
建立Oracle安裝目錄
mkdir -p /u01/app/oracle/product/12.2.0.1/db_1chown -R oracle:oinstall /u01chmod -R 775 /u01
建立oracle環境變數設定檔
mkdir /home/oracle/scriptscat > /home/oracle/scripts/setEnv.sh <<EOF# Oracle Settingsexport TMP=/tmpexport TMPDIR=\$TMPexport ORACLE_HOSTNAME=ol7-122.localdomainexport ORACLE_UNQNAME=cdb1export ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=\$ORACLE_BASE/product/12.2.0.1/db_1export ORACLE_SID=cdb1export PATH=/usr/sbin:/usr/local/bin:\$PATHexport PATH=\$ORACLE_HOME/bin:\$PATHexport LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/libexport CLASSPATH=\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlibEOFecho ". /home/oracle/scripts/setEnv.sh" >> /home/oracle/.bash_profile
建立Oracle啟動指令碼,放在 /home/oracle/scripts/dbora.sh:
#!/bin/bash. /home/oracle/scripts/setEnv.shexport ORAENV_ASK=NO. oraenvexport ORAENV_ASK=YESstartup_log=/home/oracle/scripts/startup.logshutdown_log=/home/oracle/scripts/shutdown.logfunction 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; exitEOF 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 exitEOF echo "Done." echo "" echo "-------------------------------------------------" date +" %T %a %D : Finished." echo "-------------------------------------------------" }case "$1" instart) 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 1esacexit 0
調整指令檔許可權:
chown -R oracle.oinstall /home/oracle/scriptschmod u+x /home/oracle/scripts/*.sh
編寫 systemd.service 服務指令碼,在 /etc/systemd/system/oracle.service:
[Unit]Description=Oracle ServiceAfter=network.targetAfter=syslog.target[Service]User=oracleGroup=dbaType=oneshotExecStart=/home/oracle/scripts/dbora.sh startExecReload=/home/oracle/scripts/dbora.sh restartExecStop=/home/oracle/scripts/dbora.sh stopRemainAfterExit=yes[Install]WantedBy=multi-user.target
以root使用者執行:systemctl enable oracle.service
完成後即可啟動Oracle Universal Installations (OUI)
Oracle 12cR2 Installation On CentOS-7