oracle 12cr2 installation on centos

安装oracle-database-server-12cR2-preinstall

1
2
3
4
5
6
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安装目录

1
2
3
mkdir -p /u01/app/oracle/product/12.2.0.1/db_1
chown -R oracle:oinstall /u01
chmod -R 775 /u01

创建oracle环境变量配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/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

调整脚本文件权限:

1
2
chown -R oracle.oinstall /home/oracle/scripts
chmod u+x /home/oracle/scripts/*.sh

编写 systemd.service 服务脚本,在 /etc/systemd/system/oracle.service

[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)