在RockyLinux 9.3環境中採用RPM模式部署Oracle 19C

范振勇發表於2024-04-18

在RockyLinux 9.3環境中採用RPM模式部署Oracle 19C

用途

在開發資料庫系統時,可以驗證功能是否與Oracle的表現一致,驗證正確性和相容性

限制

  1. 虛擬機器安裝,CPU 2*4 記憶體16G 磁碟100G
  2. 目標生產環境是RHEL 9.X,學習環境採用Rocky Linux 9.3
  3. 選擇Oracle版本是長期支援版19C
  4. 只驗證基礎的功能,可以禁用CDB PDB
  5. 安裝的Oracle只需要功能驗證不用於生產環境,也不進行效能測試

查詢資料

  1. bing上查詢資料,一般找到的安裝Oracle的資料是CentOS 7.x,8.x,而9.x的比較少,找到:
    • 基於RHEL9,ORACLE LINUX 9安裝Oracle 19c 資料庫
      可惜文中表示安裝Oracle時需要安裝庫補丁,流程還是比較麻煩
    • linux安裝oracle19c完整版(圖形+靜默安裝) 系統引數都是手工設定和透過介面設定,可以參考
  2. 直接查詢官方文件
    • Oracle Database Installation Guide 19c for Linux
      發現最新的19C沒有要求安裝補丁,並且支援RPM方式安裝,過程非常簡潔,嘗試成功後總結,供大家參考。

準備環境

安裝虛擬機器的過程不再贅述,安裝後需要做的準備工作如下:

  1. 關閉防火牆
#檢查防火牆狀態
systemctl status firewalld.service 
#關閉防火牆
systemctl stop firewalld.service 
#禁止開機啟動防火牆
systemctl disable firewalld.service 
  1. 關閉SELINUX
vi /etc/selinux/config

編輯內容:

#SELINUX=enforcing  #註釋掉
SELINUX=disabled  #增加

存檔退出,下次重新啟動後生效。如果想使配置立即生效,執行:

setenforce 0  
  1. 配置域名
    採用修改/etc/hostname的方式,重啟後生效
vi /etc/hostname
oracle19c.learning.cn
  1. 配置域名解析
vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.154.19 oracle19c oracle19c.learning.cn
  1. 配置軟體源
    事先將rocky linux 9.3的ISO mount到/mnt/rocky9/
vi /etc/yum.repos.d/rocky.repo
[baseos]
name=Rocky Linux $releasever - BaseOS
baseurl=file:///mnt/rocky9/BaseOS/
gpgcheck=1
enabled=1
countme=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9

[appstream]
name=Rocky Linux $releasever - AppStream
baseurl=file:///mnt/rocky9/AppStream/
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
  1. 準備Oracle RPM
  • 預安裝RPM:
    訪問Oracle Linux 9的軟體源,如x86對應的是: https://yum.oracle.com/repo/OracleLinux/OL9/appstream/x86_64/
    找到對應Oracle 19c的預安裝版本,如 oracle-database-preinstall-19c-1.0-1.el9.x86_64.rpm,下載該預安裝rpm
  • Oracle 19C:
    訪問 Oracle下載頁 找到最新的19C版本,如
    oracle-database-ee-19c-1.0-1.x86_64.rpm,然後下載到本地
  1. Linux共享Windows目錄
    為了節省Linux的磁碟空間,直接在Linux中訪問Windows下載的rpm
  • 在Windows中共享儲存rpm的資料夾,如名稱為//192.168.154.1/Oracle
  • 在Linux中連結Windows的共享
mkdir -p /mnt/oracle
mount -t cifs -o username=xxxx,password=yyyy //192.168.154.1/Oracle /mnt/oracle

請把"xxxx","yyyy"換成實際的使用者名稱和密碼

部署Oracle預安裝RPM包

按官方文件,安裝 Preinstallation RPM時會:

  1. 解析Oracle Grid Infrastructure和Oracle Database所需的依賴項,並自動下載和安裝對應的RPM包
  2. 建立oracle使用者,將其加入新建立的oraInventory (oinstall)和 OSDBA (dba)組中
  3. 按Oracle資料庫預安裝RPM程式的建議設定sysctl.conf、系統啟動引數和驅動程式引數
  4. 設定硬和軟資源限制 Linux程序資源訪問限制
  5. 根據核心版本設定其他推薦引數
  6. 在Linux x86_64和Linux aarch64機器的核心中設定numa=off
dnf install -y /mnt/oracle/19c/oracle-database-preinstall-19c-1.0-1.el9.x86_64.rpm
Last metadata expiration check: 0:01:14 ago on Wed 17 Apr 2024 12:02:20 PM CST.
Dependencies resolved.
======================================================================================================
 Package                              Architecture  Version                  Repository          Size
======================================================================================================
Installing:
 oracle-database-preinstall-19c       x86_64        1.0-1.el9                @commandline        33 k
Installing dependencies:
 chkconfig                            x86_64        1.24-1.el9               baseos             161 k
 gssproxy                             x86_64        0.8.4-6.el9              baseos             108 k
 initscripts                          x86_64        10.11.5-1.el9            baseos             210 k
 keyutils                             x86_64        1.6.3-1.el9              baseos              72 k
 ksh                                  x86_64        3:1.0.0~beta.1-3.el9     appstream          879 k
 libXxf86dga                          x86_64        1.1.5-8.el9              appstream           20 k
 libaio-devel                         x86_64        0.3.111-13.el9           appstream           10 k
 libdmx                               x86_64        1.1.4-12.el9             appstream           16 k
 libev                                x86_64        4.33-5.el9               baseos              52 k
 libnfsidmap                          x86_64        1:2.5.4-20.el9           baseos              60 k
 libnsl                               x86_64        2.34-83.el9.7            baseos              77 k
 libverto-libev                       x86_64        0.3.2-3.el9              baseos              13 k
 nfs-utils                            x86_64        1:2.5.4-20.el9           baseos             425 k
 rpcbind                              x86_64        1.2.6-5.el9              baseos              56 k
 sssd-nfs-idmap                       x86_64        2.9.1-4.el9_3            baseos              42 k
 xorg-x11-utils                       x86_64        7.5-40.el9               appstream          106 k
 xorg-x11-xauth                       x86_64        1:1.1-10.el9             appstream           36 k

Transaction Summary
======================================================================================================
Install  18 Packages

Total size: 2.3 M
Installed size: 7.5 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                            1/1 
  Installing       : libnfsidmap-1:2.5.4-20.el9.x86_64                         1/18 
  Installing       : ksh-3:1.0.0~beta.1-3.el9.x86_64                           2/18 
  Running scriptlet: ksh-3:1.0.0~beta.1-3.el9.x86_64                           2/18 
  Installing       : libdmx-1.1.4-12.el9.x86_64                                3/18 
  Installing       : libXxf86dga-1.1.5-8.el9.x86_64                            4/18 
  Installing       : xorg-x11-utils-7.5-40.el9.x86_64                          5/18 
  Installing       : xorg-x11-xauth-1:1.1-10.el9.x86_64                        6/18 
  Installing       : libaio-devel-0.3.111-13.el9.x86_64                        7/18 
  Installing       : libnsl-2.34-83.el9.7.x86_64                               8/18 
  Installing       : keyutils-1.6.3-1.el9.x86_64                               9/18 
  Installing       : libev-4.33-5.el9.x86_64                                  10/18 
  Installing       : libverto-libev-0.3.2-3.el9.x86_64                        11/18 
  Installing       : gssproxy-0.8.4-6.el9.x86_64                              12/18 
  Running scriptlet: gssproxy-0.8.4-6.el9.x86_64                              12/18 
  Running scriptlet: rpcbind-1.2.6-5.el9.x86_64                               13/18 
  Installing       : rpcbind-1.2.6-5.el9.x86_64                               13/18 
  Running scriptlet: rpcbind-1.2.6-5.el9.x86_64                               13/18 
Created symlink /etc/systemd/system/multi-user.target.wants/rpcbind.service → /usr/lib/systemd/system/rpcbind.service.
Created symlink /etc/systemd/system/sockets.target.wants/rpcbind.socket → /usr/lib/systemd/system/rpcbind.socket.

  Running scriptlet: nfs-utils-1:2.5.4-20.el9.x86_64                          14/18 
  Installing       : nfs-utils-1:2.5.4-20.el9.x86_64                          14/18 
  Running scriptlet: nfs-utils-1:2.5.4-20.el9.x86_64                          14/18 
  Installing       : chkconfig-1.24-1.el9.x86_64                              15/18 
  Installing       : initscripts-10.11.5-1.el9.x86_64                         16/18 
  Running scriptlet: initscripts-10.11.5-1.el9.x86_64                         16/18 
Created symlink /etc/systemd/system/sysinit.target.wants/import-state.service → /usr/lib/systemd/system/import-state.service.
Created symlink /etc/systemd/system/sysinit.target.wants/loadmodules.service → /usr/lib/systemd/system/loadmodules.service.

  Running scriptlet: oracle-database-preinstall-19c-1.0-1.el9.x86_64          17/18 
  Installing       : oracle-database-preinstall-19c-1.0-1.el9.x86_64          17/18 
  Installing       : sssd-nfs-idmap-2.9.1-4.el9_3.x86_64                      18/18 
  Running scriptlet: oracle-database-preinstall-19c-1.0-1.el9.x86_64          18/18 
  Running scriptlet: sssd-nfs-idmap-2.9.1-4.el9_3.x86_64                      18/18 
  Verifying        : chkconfig-1.24-1.el9.x86_64                               1/18 
  Verifying        : libverto-libev-0.3.2-3.el9.x86_64                         2/18 
  Verifying        : initscripts-10.11.5-1.el9.x86_64                          3/18 
  Verifying        : rpcbind-1.2.6-5.el9.x86_64                                4/18 
  Verifying        : libev-4.33-5.el9.x86_64                                   5/18 
  Verifying        : sssd-nfs-idmap-2.9.1-4.el9_3.x86_64                       6/18 
  Verifying        : gssproxy-0.8.4-6.el9.x86_64                               7/18 
  Verifying        : nfs-utils-1:2.5.4-20.el9.x86_64                           8/18 
  Verifying        : libnfsidmap-1:2.5.4-20.el9.x86_64                         9/18 
  Verifying        : keyutils-1.6.3-1.el9.x86_64                              10/18 
  Verifying        : libnsl-2.34-83.el9.7.x86_64                              11/18 
  Verifying        : libaio-devel-0.3.111-13.el9.x86_64                       12/18 
  Verifying        : xorg-x11-xauth-1:1.1-10.el9.x86_64                       13/18 
  Verifying        : xorg-x11-utils-7.5-40.el9.x86_64                         14/18 
  Verifying        : libXxf86dga-1.1.5-8.el9.x86_64                           15/18 
  Verifying        : libdmx-1.1.4-12.el9.x86_64                               16/18 
  Verifying        : ksh-3:1.0.0~beta.1-3.el9.x86_64                          17/18 
  Verifying        : oracle-database-preinstall-19c-1.0-1.el9.x86_64          18/18 

Installed:
  chkconfig-1.24-1.el9.x86_64          gssproxy-0.8.4-6.el9.x86_64          initscripts-10.11.5-1.el9.x86_64
  keyutils-1.6.3-1.el9.x86_64          ksh-3:1.0.0~beta.1-3.el9.x86_64      libXxf86dga-1.1.5-8.el9.x86_64
  libaio-devel-0.3.111-13.el9.x86_64   libdmx-1.1.4-12.el9.x86_64           libev-4.33-5.el9.x86_64
  libnfsidmap-1:2.5.4-20.el9.x86_64    libnsl-2.34-83.el9.7.x86_64          libverto-libev-0.3.2-3.el9.x86_64 
  nfs-utils-1:2.5.4-20.el9.x86_64      oracle-database-preinstall-19c-1.0-1.el9.x86_64     
  rpcbind-1.2.6-5.el9.x86_64           sssd-nfs-idmap-2.9.1-4.el9_3.x86_64  
  xorg-x11-utils-7.5-40.el9.x86_64     xorg-x11-xauth-1:1.1-10.el9.x86_64                 

Complete!

注意:安裝完成後重新啟動系統,確認所有的系統引數已經應用

驗證預安裝RPM的工作成果(不是強迫症無需關注這一部分)

  1. 檢查依賴項,執行命令
dnf repoquery --requires oracle-database-preinstall-19c-1.0-1.el9.x86_64.rpm
/bin/sh
/etc/redhat-release
/usr/bin/bash
bc
bind-utils
binutils
ethtool
glibc
glibc-devel
initscripts
ksh
libaio
libaio-devel
libgcc
libnsl
libstdc++
libstdc++-devel
make
module-init-tools
net-tools
nfs-utils
openssh-clients
pam
policycoreutils
policycoreutils-python-utils
procps
psmisc
smartmontools
sysstat
tar
unzip
util-linux-ng
xorg-x11-utils
xorg-x11-xauth

顯示所有的依賴項,說明在部署預安裝RPM過程中,檢查3個檔案和31個rpm的依賴關係

  1. 檢查系統配置/etc/sysctl.conf 增加了內容
cat /etc/sysctl.conf

# oracle-database-preinstall-19c setting for fs.file-max is 6815744
fs.file-max = 6815744

# oracle-database-preinstall-19c setting for kernel.sem is '250 32000 100 128'
kernel.sem = 250 32000 100 128

# oracle-database-preinstall-19c setting for kernel.shmmni is 4096
kernel.shmmni = 4096

# oracle-database-preinstall-19c setting for kernel.shmall is 1073741824 on x86_64
kernel.shmall = 1073741824

# oracle-database-preinstall-19c setting for kernel.shmmax is 4398046511104 on x86_64
kernel.shmmax = 4398046511104

# oracle-database-preinstall-19c setting for kernel.panic_on_oops is 1 per Orabug 19212317
kernel.panic_on_oops = 1

# oracle-database-preinstall-19c setting for net.core.rmem_default is 262144
net.core.rmem_default = 262144

# oracle-database-preinstall-19c setting for net.core.rmem_max is 4194304
net.core.rmem_max = 4194304

# oracle-database-preinstall-19c setting for net.core.wmem_default is 262144
net.core.wmem_default = 262144

# oracle-database-preinstall-19c setting for net.core.wmem_max is 1048576
net.core.wmem_max = 1048576

# oracle-database-preinstall-19c setting for net.ipv4.conf.all.rp_filter is 2
net.ipv4.conf.all.rp_filter = 2

# oracle-database-preinstall-19c setting for net.ipv4.conf.default.rp_filter is 2
net.ipv4.conf.default.rp_filter = 2

# oracle-database-preinstall-19c setting for fs.aio-max-nr is 1048576
fs.aio-max-nr = 1048576

# oracle-database-preinstall-19c setting for net.ipv4.ip_local_port_range is 9000 65500
net.ipv4.ip_local_port_range = 9000 65500

注: 原檔案備份在/etc/sysctl.d/99-initial-sysctl.conf

  1. 檢查系統配置/etc/sysconfig/network 增加了內容
cat /etc/sysconfig/network
# Created by anaconda
# oracle-database-preinstall-19c : Add NOZEROCONF=yes
NOZEROCONF=yes
  1. 檢查程序資源配置
cat /etc/security/limits.d/oracle-database-preinstall-19c.conf

# oracle-database-preinstall-19c setting for nofile soft limit is 1024
oracle   soft   nofile    1024

# oracle-database-preinstall-19c setting for nofile hard limit is 65536
oracle   hard   nofile    65536

# oracle-database-preinstall-19c setting for nproc soft limit is 16384
# refer orabug15971421 for more info.
oracle   soft   nproc    16384

# oracle-database-preinstall-19c setting for nproc hard limit is 16384
oracle   hard   nproc    16384

# oracle-database-preinstall-19c setting for stack soft limit is 10240KB
oracle   soft   stack    10240

# oracle-database-preinstall-19c setting for stack hard limit is 32768KB
oracle   hard   stack    32768

# oracle-database-preinstall-19c setting for memlock hard limit is maximum of 128GB on x86_64 or 3GB on x86 OR 90 % of RAM
oracle   hard   memlock    134217728

# oracle-database-preinstall-19c setting for memlock soft limit is maximum of 128GB on x86_64 or 3GB on x86 OR 90% of RAM
oracle   soft   memlock    134217728

# oracle-database-preinstall-19c setting for data soft limit is 'unlimited'
oracle   soft   data    unlimited

# oracle-database-preinstall-19c setting for data hard limit is 'unlimited'
oracle   hard   data    unlimited
  1. 檢查進啟動配置的變化
diff /boot/grub2/grub.cfg /boot/grub2/grub.cfg-oracle-database-preinstall-19c.orabackup
設定“numa=off transparent_hugepage=never”關閉了透明大頁和numa
<   set kernelopts="root=/dev/mapper/rl-root ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/rl-swap rd.lvm.lv=rl/root rd.lvm.lv=rl/swap rhgb quiet numa=off transparent_hugepage=never "
---
>   set kernelopts="root=/dev/mapper/rl-root ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/rl-swap rd.lvm.lv=rl/root rd.lvm.lv=rl/swap rhgb quiet "

注意:修改了核心引數,需要重新啟動

  1. 驗證建立使用者和使用者組
groups oracle
oracle : oinstall dba oper backupdba dgdba kmdba racdba
id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba),54330(racdba)

從結果可見oracle屬於7個組

  1. 驗證透明大頁是否關閉
cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
cat /sys/kernel/mm/transparent_hugepage/defrag
always defer defer+madvise [madvise] never
  1. 也可以檢視安裝日誌
cat /var/log/oracle-database-preinstall-19c/results/orakernel.log 

安裝Oracle RPM

dnf install -y /mnt/oracle/19c/oracle-database-ee-19c-1.0-1.x86_64.rpm
Last metadata expiration check: 0:04:44 ago on Wed 17 Apr 2024 12:02:20 PM CST.
Dependencies resolved.
==========================================================================================================
 Package                                            Architecture      Version       Repository       Size
==========================================================================================================
Installing:
 oracle-database-ee-19c                             x86_64            1.0-1         @commandline    2.5 G

Transaction Summary
==========================================================================================================
Install  1 Package

Total size: 2.5 G
Installed size: 6.9 G
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                  1/1 
  Running scriptlet: oracle-database-ee-19c-1.0-1.x86_64                                              1/1 
  Installing       : oracle-database-ee-19c-1.0-1.x86_64                                              1/1 
  Running scriptlet: oracle-database-ee-19c-1.0-1.x86_64                                              1/1 
[INFO] Executing post installation scripts...
[INFO] Oracle home installed successfully and ready to be configured.
To configure a sample Oracle Database you can execute the following service configuration script as root: /etc/init.d/oracledb_ORCLCDB-19c configure

  Verifying        : oracle-database-ee-19c-1.0-1.x86_64                                                                                                             1/1 

Installed:
  oracle-database-ee-19c-1.0-1.x86_64                                                                                                                                    

Complete!

禁用CDB

vi /etc/init.d/oracledb_ORCLCDB-19c
...
export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1

export ORACLE_VERSION=19c
export ORACLE_SID=ORCLCDB
export TEMPLATE_NAME=General_Purpose.dbc
export CHARSET=AL32UTF8
export PDB_NAME=ORCLPDB1
export LISTENER_NAME=LISTENER
export NUMBER_OF_PDBS=1
export CREATE_AS_CDB=true
修改為
export CREATE_AS_CDB=false

初始化資料庫

[root@oracle19c ansible]# /etc/init.d/oracledb_ORCLCDB-19c configure
Configuring Oracle Database ORCLCDB.
Prepare for db operation
10% complete
Copying database files
40% complete
Creating and starting Oracle instance
42% complete
46% complete
50% complete
54% complete
60% complete
Completing Database Creation
66% complete
70% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
 /opt/oracle/cfgtoollogs/dbca/ORCLCDB.
Database Information:
Global Database Name:ORCLCDB
System Identifier(SID):ORCLCDB
Look at the log file "/opt/oracle/cfgtoollogs/dbca/ORCLCDB/ORCLCDB.log" for further details.

Database configuration completed successfully. The passwords were auto generated, you must change them by connecting to the database using 'sqlplus / as sysdba' as the oracle user.

可以檢視詳細一點兒的日誌(輸出了時間)

cat /opt/oracle/cfgtoollogs/dbca/ORCLCDB/ORCLCDB.log

本次初始化耗時6分鐘,對比沒有禁用CDB的一次實驗,初始化耗時15分鐘

修改oracle使用者的環境變數

su - oracle
vi .bashrc
# 在原檔案最後增加
umask 022
export TMP=/tmp
export TMPDIR=$TMP
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19c/dbhome_1
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export ORACLE_SID=ORCLCDB
export PATH=$ORACLE_HOME/bin:$PATH

小技巧:修改.bashrc 而不是.bash_profile的原因是可以支援非登入模式執行shell

驗證基本功能

返回root重新以oracle使用者執行

su - oracle
[oracle@oracle19c ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Apr 18 17:23:03 2024
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> create table t1(a int primary key,b varchar(16));
Table created.
SQL> insert into t1 values(100,'beijing');
1 row created.
SQL> insert into t1 values(200,'天津');
1 row created.
SQL> select * from t1 order by a desc;
         A B
---------- ----------------
       200 天津
       100 beijing

重新啟動系統後,發現服務不會自動重啟,設定自動重啟

採用RPM安裝並沒有設定自動重新啟動Oracle的服務,執行 sqlplus / as sysdba 執行簡單SQL報錯,資訊如下:

[oracle@oracle19c ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Thu Apr 18 22:59:25 2024
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Connected to an idle instance.

SQL> select * from t1 ;
select * from t1
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0

所以要手工增加自動重啟的服務,此處主要參考ORACLE 19C 在centos 7的本地rpm包安裝及除錯,個別地方稍作修正

  • 設定公共環境變數檔案
vi /etc/sysconfig/ORCLCDB.oracledb
ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
ORACLE_SID=ORCLCDB
  • 建立監聽服務
vi /usr/lib/systemd/system/ORCLCDB@lsnrctl.service
[Unit]
Description=Oracle Net Listener
After=syslog.target network.target

[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/ORCLCDB.oracledb
ExecStart=/opt/oracle/product/19c/dbhome_1/bin/lsnrctl start
ExecStop=/opt/oracle/product/19c/dbhome_1/bin/lsnrctl stop
User=oracle

[Install]
WantedBy=multi-user.target
  • 建立服務啟動服務
vi /usr/lib/systemd/system/ORCLCDB@oracledb.service
[Unit]
Description=Oracle Database service
After=syslog.target network.target lsnrctl.service

[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/ORCLCDB.oracledb
ExecStart=/opt/oracle/product/19c/dbhome_1/bin/dbstart $ORACLE_HOME
ExecStop=/opt/oracle/product/19c/dbhome_1/bin/dbshut $ORACLE_HOME
User=oracle

[Install]
WantedBy=multi-user.target
  • 設定啟動
vi /etc/oratab
...
#ORCLCDB:/opt/oracle/product/19c/dbhome_1:N
#將此處原來的N修改為Y
ORCLCDB:/opt/oracle/product/19c/dbhome_1:Y
  • 啟用服務
    systemctl enable ORCLCDB@lsnrctl
    systemctl enable ORCLCDB@oracledb

  • 小技巧,先不忙著啟動系統,先手工啟動服務進行驗證

systemctl start ORCLCDB@lsnrctl
systemctl start ORCLCDB@oracledb

如果有錯誤資訊,則透過 systemctl status ORCLCDB@lsnrctl 分析問題

  • 重啟後檢驗服務狀態
[root@oracle19c ansible]# netstat -tunlp | grep -E '1521|5500'
tcp6       0      0 :::5500                 :::*                    LISTEN      1090/tnslsnr        
tcp6       0      0 :::1521                 :::*                    LISTEN      1090/tnslsnr        
[root@oracle19c ansible]# su - oracle
[oracle@oracle19c ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Apr 18 23:21:52 2024
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> select * from t2 ;
         A B
---------- ----------------
       100 beijing
       200 天津
 

總結

本文的內容主要來自網路,但是經過了本人多次的驗證和整理,剔除了一些不必要的環節,也為大家跳過了一些坑。如果有不足之處,請不吝指正,我一定及時修改更新。

1、RPM安裝的限制

  1. 僅用於安裝 Oracle 資料庫軟體,RAC不能這樣安裝,並且扣除preinstallation,安裝rpm的難度與靜默安裝相當。
  2. RPM 只能用於安裝軟體,而不能用於更新軟體
  3. 無法控制軟體安裝的目錄,即不一定能滿足企業安裝規範的目錄約束
  4. 推薦僅用於實驗環境,不要用於生產環境

2、一些坑(網上個別文件有些筆誤)

  1. 19C 預設在/etc/init.d/oracledb_ORCLCDB-19c 設定了字符集為AL32UTF8,無需在其他地方設定伺服器字符集
  2. /etc/hosts 一定要設定正確,但是無需刪除127.0.0.1,::1 那兩行
  3. 預安裝RPM準備的內容見“驗證預安裝RPM的工作成果”部分,這些工作都不需要手工執行
  4. 僅僅功能驗證的話不要啟動CDB,否則連建立一個普通使用者都要好幾步操作

相關文章