本例操作系統版本:CentOS 7.8、數據庫版本:Oracle 12c(12.201)
https://oracle-base.com/articles/12c/oracle-db-12cr2-installation-on-oracle-linux-6-and-7
安裝步驟如下分解:
hostname: ol7-122.localdomain hosts: 10.0.0.10 ol7-122.localdomain ol7-122
1.關閉防火牆,禁止防火牆開機自啟
# 關閉防火牆
systemctl stop firewalld.service
# 禁止防火牆開機啟動
systemctl disable firewalld.service
# 查看防火牆狀態
systemctl status firewalld.service
2.關閉selinux
# 編輯文件 vi /etc/selinux/config # 修改內容 SELINUX=disabled
3.yum安裝必要安裝包
使用 yum 批量安裝依賴包,若執行一遍失敗則繼續執行第二遍(多次執行不會出現其他問題)
yum install binutils -y yum install compat-libcap1 -y yum install compat-libstdc++-33 -y yum install compat-libstdc++-33.i686 -y yum install glibc -y yum install glibc.i686 -y yum install glibc-devel -y yum install glibc-devel.i686 -y yum install ksh -y yum install libaio -y yum install libaio.i686 -y yum install libaio-devel -y yum install libaio-devel.i686 -y yum install libX11 -y yum install libX11.i686 -y yum install libXau -y yum install libXau.i686 -y yum install libXi -y yum install libXi.i686 -y yum install libXtst -y yum install libXtst.i686 -y yum install libgcc -y yum install libgcc.i686 -y yum install libstdc++ -y yum install libstdc++.i686 -y yum install libstdc++-devel -y yum install libstdc++-devel.i686 -y yum install libxcb -y yum install libxcb.i686 -y yum install make -y yum install nfs-utils -y yum install net-tools -y yum install smartmontools -y yum install sysstat -y yum install unixODBC -y yum install unixODBC-devel -y
檢查是否安裝成功(31個安裝包)
rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel
4.創建 swap
詳見文章:
5.創建 oracle 分區(可選)
如果你操作系統原有分區都合適,這步可以忽略
# 查看硬盤及分區信息(啟動Disk開頭的就是硬盤,Device開頭的就是分區) fdisk -l # 創建分區(/dev/sdb 是硬盤,是你需要創建分區的硬盤,創建分區后會生成 /dev/sdb1,如果本來有sdb1,則會出現sdb2) fdisk /dev/sdb # 格式化新創建的分區 mkfs.xfs /dev/sdb1 # 將分區添加到 /etc/fstab 文件中,使之開機自動掛載(編輯保存 fstab 文件后不會立即生效) vim /etc/fstab /dev/sdb1 /u01 xfs defaults 0 0
6.創建 oracle data 目錄(同第5步可選)
# 創建目錄 mkdir /u01 # 重新加載文件 /etc/fstab 所有內容。該操作會忽略所有已經完成的操作,所以多次執行,只會有第一次能看到效果。 mount -a df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 20G 12G 8.7G 57% / devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 13M 3.8G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 2.0G 179M 1.9G 9% /boot /dev/mapper/centos-home 10G 33M 10G 1% /home tmpfs 781M 4.0K 781M 1% /run/user/42 tmpfs 781M 52K 781M 1% /run/user/0 /dev/sdb 20G 33M 20G 1% /u01
7.設置時區、升級系統、安裝桌面環境
方式一:針對最小化安裝的系統
# 設置時區 timedatectl set-timezone Asia/Shanghai # 升級系統 yum clean all && yum update -y # 安裝桌面環境(兩個組包必須,不然安裝oracle會出現卡死現象) yum groupinstall "GNOME Desktop" "Server with GUI" -y # 安裝完畢設置開機啟動桌面環境 systemctl set-default graphical.target
方式2 : 預裝系統時勾選桌面環境功能
-
Server with GUI
-
Hardware Monitoring Utilities
-
Large Systems Performance
-
Network file system client
-
Performance Tools
-
Compatibility Libraries
-
Development Tools
8.創建oracle用戶與用戶組
# 創建oinstall和dba組 groupadd -g 54321 oinstall groupadd -g 54322 dba groupadd -g 54323 oper # 創建oracle用戶 useradd -u 54321 -g oinstall -G dba,oper oracle # 設置oracle密碼 passwd oracle # 查看創建結果 id oracle uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper)
9.參數配置
# 配置內核參數(這些參數根據你機器的配置不同,有些參數需要再次修改,在安裝oralce過程中的check那一步,會給出提示,按要求逐個修改對應的推薦值即可)
vi /etc/sysctl.d/98-oracle.conf fs.file-max = 6815744 kernel.sem = 250 32000 100 128 kernel.shmmni = 4096 kernel.shmall = 1073741824 kernel.shmmax = 4398046511104 kernel.panic_on_oops = 1 net.core.rmem_default = 262144 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 1048576 net.ipv4.conf.all.rp_filter = 2 net.ipv4.conf.default.rp_filter = 2 fs.aio-max-nr = 1048576 net.ipv4.ip_local_port_range = 9000 65500 /sbin/sysctl -p /etc/sysctl.d/98-oracle.conf
# 配置ulimit參數 vi /etc/security/limits.d/oracle-database-server-12cR2-preinstall.conf oracle soft nofile 1024 oracle hard nofile 65536 oracle soft nproc 16384 oracle hard nproc 16384 oracle soft stack 10240 oracle hard stack 32768 oracle hard memlock 134217728 oracle soft memlock 134217728
# 設置上面創建的數據目錄權限 mkdir -p /u01/app/oracle/product/12.2.0.1/db_1 chown -R oracle:oinstall /u01 chmod -R 775 /u01
10.重啟服務器
reboot
11.下載或拷貝oracle文件
可以在線下載 可以通過拷貝方式 可以在同網段電腦上開啟ftp或者http服務后,在服務上 wget 下載 官方下載地址: https://www.oracle.com/database/technologies/oracle-database-software-downloads.html
12.配置環境變量
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 # 執行命令使環境變量生效 source ~/.bash_profile
13.解壓並開始安裝
假設 oracle 文件已經下載到 /opt/linuxx64_12201_database.zip
使用圖形化安裝方式,你可以直接在原服務器上連接顯示器安裝,或者使用其他 ssh 遠程安裝(不帶圖形化的靜默安找找度娘)。 如果使用 Xshell 這種工具安裝(需要開啟X11,可以參考:
su - oracle cd /opt/ unzip linuxx64_12201_database.zip cd database/ ./runInstaller
詳細安裝步驟如下:
安裝后
編輯“ /etc/oratab”文件,將每個實例的重新啟動標志設置為“ Y”。
cdb1:/u01/app/oracle/product/12.2.0.1/db_1:Y
14.創建啟停腳本
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
15.啟動並測試服務
~/scripts/start_all.sh # 啟動腳本 ~/scripts/stop_all.sh # 停止腳本 # 使用 telnet 測試服務端口 telnet 127.0.0.1 1521 # 使用 sqlplus 登錄數據庫 sqlplus /nolog conn / as sysdba
16.創建Linux服務
創建一個新服務以自動啟動/停止Oracle數據庫。這是假定Oracle數據庫不使用Oracle重新啟動和“start_all.sh”和“stop_all.sh”腳本已經存在
創建名為“ /lib/systemd/system/dbora.service”的服務文件。
vi /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
systemctl daemon-reload
systemctl stop dbora.service
systemctl start dbora.service
systemctl enable dbora.service