2020年7月14日 星期二

在 CentOS 7 上安裝 Oracle 資料庫 12c


主要內容同以下網址,此文增加一些註解與注意事項
在 CentOS 7 上安裝 Oracle 資料庫 12c




1. 引言

本指南介紹如何在 CentOS 7.1(64 位元)上利用快速安裝的功能部署 Oracle 資料庫 12c(12.1.0.2.0)。

參考系統:

[root@centos7 ~]# hostnamectl
   Static hostname: centos7.example.com
         Icon name: computer
           Chassis: n/a
        Machine ID: 583b4d69eaea465ea4bb96ac3b891e15
           Boot ID: 931ed1af622046ebbde071a87844a7d5
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-229.11.1.el7.x86_64
      Architecture: x86_64

2. 先決條件

成功安裝操作系統後,請確認主機名稱並在你的 DNS 上登記它。你也可選擇在 /etc/hosts 內加入你的主機名稱/IP。

[root@centos7 ~]# cat /etc/hostname
centos7.example.com

將 SELinux 維持在 enforcing 模式,並啟用防火牆

[root@centos7 ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

[root@centos7 ~]# firewall-cmd --state
running

把 CentOS 系統更新至最新套件

[root@centos7 ~]# yum update -y

下載 Oracle 資料庫 12c 的 Linux x86-64 版本:

http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

3. 安裝步驟

為 Oracle 資料庫建立所須的操作系統用戶及群組。

[root@centos7 ~]# groupadd oinstall
[root@centos7 ~]# groupadd dba
[root@centos7 ~]# useradd -g oinstall -G dba oracle
[root@centos7 ~]# passwd oracle

在 /etc/sysctl.conf 加入下列內核參數

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1987162112
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586

檢查並運用新的數值。

[root@centos7 ~]# sysctl -p
[root@centos7 ~]# sysctl -a

在 /etc/security/limits.conf 為 oracle 用戶設定上限

oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536

將 Oracle 資料庫軟件的 zip 檔案(linuxamd64_12102_database_1of2.zip, linuxamd64_12102_database_2of2.zip)解壓至 /stage 目錄。

[root@centos7 ~]# yum install -y zip unzip
[root@centos7 ~]# unzip linuxamd64_12102_database_1of2.zip -d /stage/
[root@centos7 ~]# unzip linuxamd64_12102_database_2of2.zip -d /stage/

修改 /stage 的權限

[root@centos7 ~]# chown -R oracle:oinstall /stage/

為 Oracle 軟件建立 /u01 目錄,及為資料庫檔案建立 /u02 目錄。

[root@centos7 ~]# mkdir /u01
[root@centos7 ~]# mkdir /u02
[root@centos7 ~]# chown -R oracle:oinstall /u01
[root@centos7 ~]# chown -R oracle:oinstall /u02
[root@centos7 ~]# chmod -R 775 /u01
[root@centos7 ~]# chmod -R 775 /u02
[root@centos7 ~]# chmod g+s /u01
[root@centos7 ~]# chmod g+s /u02

安裝所須套件:

[root@centos7 ~]# yum install -y binutils.x86_64 compat-libcap1.x86_64 gcc.x86_64 gcc-c++.x86_64 glibc.i686 glibc.x86_64 \
glibc-devel.i686 glibc-devel.x86_64 ksh compat-libstdc++-33 libaio.i686 libaio.x86_64 libaio-devel.i686 libaio-devel.x86_64 \
libgcc.i686 libgcc.x86_64 libstdc++.i686 libstdc++.x86_64 libstdc++-devel.i686 libstdc++-devel.x86_64 libXi.i686 libXi.x86_64 \
libXtst.i686 libXtst.x86_64 make.x86_64 sysstat.x86_64

還有安裝 X Window System 套件群組。

[root@centos7 ~]# yum groupinstall -y "X Window System"

由於 Oracle 的安裝採用圖像介面,你可透過以下兩個簡單的方法進行。

方案 1

透過 SSH 從一台圖像化 Linux 電腦遠端登入。

ssh -X oracle@centos7.example.com


若使用MobaXterm,預設有勾選X11-forwarding,若Linux有啟用成功,SSH登入後會有下方的綠色勾勾




方案 2

利用一台擁有 SSH 客戶端(PuTTY)及 X-Windows 終端機模擬器(Xming)的微軟 Windows 桌面。

以下文檔描述如何在 Windows 系統上安裝 Xming。

Xming —— 微軟 Windows 電腦下的 X-Windows 終端機模擬器

請採用上述的方案登入為 oracle 用戶,然後執行 Oracle 安裝程式:

[oracle@centos7 ~]$ /stage/database/runInstaller
Starting Oracle Universal Installer...

如果出現swapfile問題

Checking swap space: 0 MB available, 150 MB required. Failed


解決方法: 設定或變更 swapfile大小


swapoff /swapfile

rm /swapfile

fallocate -l 1G /swapfile

sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576

chmod 600 /swapfile

mkswap /swapfile

swapon /swapfile

nano /etc/fstab

在最下方加入以下文字

/swapfile swap swap defaults 0 0

swapon --show

top


若使用MobaXterm會出現以下畫面

4. Oracle 安裝程式畫面

第一步 —— 安全性更新

假若你不想接收來自 Oracle 支援部的電郵,請取消勾選該項目並按 Next

在新開啟的視窗按 YES。

第二步 —— 安裝選項

選擇 Create and configure a database 並按 Next

第三步 —— 系統級別

選擇 Desktop Class 進行預設的簡便 Oracle 資料庫安裝。

第四步 —— 典型安裝

在 Typical Install Configuration 畫面,設定以下功能。

Oracle base

/u01/app/oracle

Software location

/u01/app/oracle/product/12.1.0/dbhome_1

Database file location

/u02

Global database name

orcl.example.com

另外請設定合適的 Database edition(資料庫版本)及 Character set(字集)。請為資料庫的管理訂立一個安全的密碼,最後請取消勾選 Create as Container database 項目。


第五步 —— 建立庫存

接納預設的 /u01/app/oraInventory 並按 Next

第六步 —— 檢查先決條件 Prerequisite

安裝程式會自動檢查所有必須的操作系統套件及內核設定。


如果出現Soft Limit maximum stack size的status狀態是failed

Soft Limit: maximum stack size - This is a prerequisite condition to test whether the soft limit for maximum stack size is set correctly. Details: 

PRVG-0449 : Proper soft limit for maximum stack size was not found on node "ora12c" [Expected >= "10240" ; Found = "8192"].  - Cause:  The Cluster Verification Utility determined that the setting for the indicated soft limit did not meet Oracle''s recommendations for proper operation on the indicated nodes.  - Action:  Modify the resource limits to meet the requirement and take operating system specific measures to ensure that the corrected value takes effect for the current user before retrying this check. 


sudo vi /etc/security/limits.conf

增加 兩行

oracle soft stack 10240

oracle hard stack 32768


關閉安裝程式,退出ssh,再登入一次,重新啟動安裝程式

logout and login again 



第七步 —— 摘要

這是編輯安裝特點的最後機會。請按 Install

第八步 —— 執行設置腳本

當詢問視窗出現時,請登入成為 root 並執行兩個腳本:

[root@centos7 ~]# /u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.

[root@centos7 ~]# /u01/app/oracle/product/12.1.0/dbhome_1/root.sh
Performing root user operation.
The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/product/12.1.0/dbhome_1
Enter the full pathname of the local bin directory: [/usr/local/bin]: <PRESS ENTER>
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...
Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
You can follow the installation in a separated window.

這兩個腳本都必須以 root 的身份來執行。

第九步 —— 安裝進度

一個顯示安裝進度的視窗將會出現。請勿關閉這個視窗。

第十步 —— 順利完成安裝

最後一個畫面將會通知你安裝已經完成並顯示 Oracle 企業級管理員的 URL。

https://localhost:5500/em

請按 OK 來關閉安裝程式。

5. 安裝後的任務

5.1. 防火牆

請登入成為 root 並檢查已啟動的區域

[root@centos7 ~]# firewall-cmd --get-active-zones
public
  interfaces: eth0

開啟相關的連接埠

[root@centos7 ~]# firewall-cmd --zone=public --add-port=1521/tcp --add-port=5500/tcp --add-port=5520/tcp --add-port=3938/tcp \ 
--permanent
success

[root@centos7 ~]# firewall-cmd --reload
success

[root@centos7 ~]# firewall-cmd --list-ports
1521/tcp 3938/tcp 5500/tcp 5520/tcp

5.2. Oracle 工作環境

請登入為 oracle 用戶並在 /home/oracle/.bash_profile 內加入下列數值

TMPDIR=$TMP; export TMPDIR
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/lib64; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH

重新載入 bash_profile 來運用新設定值:

[oracle@centos7 ~]$ . .bash_profile

5.3. 登入資料庫

最後請登入資料庫:

[oracle@centos7 ~]$ sqlplus system@orcl
... output omitted ...
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL>

請利用 Oracle 企業級管理員來管理資料庫:

https://<主機名稱>:5500/em




Reference:

How to Add Swap Space on CentOS 7

https://linuxize.com/post/how-to-add-swap-space-on-centos-7/


SQL Server Database Mirroring 資料庫鏡像

SQL Server Database Mirroring 資料庫鏡像