5分钟学会在Linux上安装Oracle和一条命令创建数据库

简介: 在Linux上安装Oracle软件的过程相当复杂,让很多初学者望而却步。但在Oracle 18c以后Oracle推出了使用rpm包安装Oracle数据库软件的安装方式

两个rpm包完成Oracle数据库的安装

在Linux上安装Oracle软件的过程相当复杂,让很多初学者望而却步。但在Oracle 18c以后Oracle推出了使用rpm包安装Oracle数据库软件的安装方式,安装两个(预安装包和数据库安装包)rpm包即可完成整个Oracle数据库软件的安装,以Oracle 21c为例:


预安装包 数据库安装包

Linux 7 oracle-database-preinstall-21c-1.0-1.el7.x86_64.rpm oracle-database-ee-21c-1.0-1.ol7.x86_64.rpm

Linux 8 oracle-database-preinstall-21c-1.0-1.el8.x86_64.rpm oracle-database-ee-21c-1.0-1.ol8.x86_64.rpm

其中预安装包是从Oracle 11gR2版本开始出现的。这两个安装包可以让整个Oracle软件的安装过程傻瓜化,使用yum安装这两个包即可完成全部的安装工作。


预安装包(oracle-preinstallation-rpm)

预安装包的安装文档:

https://docs.oracle.com/en/database/oracle/oracle-database/21/ladbi/automatically-configuring-oracle-linux-with-oracle-preinstallation-rpm.html


下面是Linux 7和Linux8的预安装包的下载链接:


wget https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-21c-1.0-1.el7.x86_64.rpm
wget https://yum.oracle.com/repo/OracleLinux/OL8/appstream/x86_64/getPackage/oracle-database-preinstall-21c-1.0-1.el8.x86_64.rpm


使用yum -y localinstall,后面接包名进行安装。

Oracle Database Preinstallation RPM 完成如下工作:


自动下载并安装安装Oracle Grid Infrastructure和Oracle Database所需的任何附加RPM软件包,并解决任何依赖关系。

创建一个oracle用户,并为该用户创建Oracle inventory(oinstall)和OSDBA (dba)组 。

根据建议,设置sysctl.conf的设置、系统启动参数和驱动程序参数。

设置硬资源和软资源限制。

根据用户的内核版本,设置其他推荐参数。

在Linux x86_64机器的内核中设置numa=off。

安装完成后检查安装日志的例子如下:

# cat /var/log/oracle-database-preinstall-21c/backup/Dec-28-2021-15-52-12/orakernel.log 
Adding group oinstall with gid 54321
Adding group dba with gid 54322
Adding group oper with gid 54323
Adding group backupdba with gid 54324
Adding group dgdba with gid 54325
Adding group kmdba with gid 54326
Adding group racdba with gid 54330
Adding user oracle with user id 54321, initial login group oinstall, supplementary groups oinstall,dba,oper,backupdba,dgdba,kmdba,racdba and  home directory /home/oracle
Changing ownership of /home/oracle to oracle:oinstall
Please set password for user - oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba),54330(racdba)
User creation passed 
Saving a copy of the initial sysctl.conf
Verifying  kernel parameters as per Oracle recommendations...
Trying to remove instances of  - setting for fs.file-max is
Adding fs.file-max = 6815744 
Trying to remove instances of  - setting for kernel.sem is
Adding kernel.sem = 250 32000 100 128 
Trying to remove instances of  - setting for kernel.shmmni is
Adding kernel.shmmni = 4096 
Trying to remove instances of  - setting for kernel.shmall is
Adding kernel.shmall = 1073741824 
Trying to remove instances of  - setting for kernel.shmmax is
Adding kernel.shmmax = 4398046511104 
Trying to remove instances of  - setting for kernel.panic_on_oops is
Adding kernel.panic_on_oops = 1 
Trying to remove instances of  - setting for net.core.rmem_default is
Adding net.core.rmem_default = 262144 
Trying to remove instances of  - setting for net.core.rmem_max is
Adding net.core.rmem_max = 4194304 
Trying to remove instances of  - setting for net.core.wmem_default is
Adding net.core.wmem_default = 262144 
Trying to remove instances of  - setting for net.core.wmem_max is
Adding net.core.wmem_max = 1048576 
Trying to remove instances of  - setting for net.ipv4.conf.all.rp_filter is
Adding net.ipv4.conf.all.rp_filter = 2 
Trying to remove instances of  - setting for net.ipv4.conf.default.rp_filter is
Adding net.ipv4.conf.default.rp_filter = 2 
Trying to remove instances of  - setting for fs.aio-max-nr is
Adding fs.aio-max-nr = 1048576 
Trying to remove instances of  - setting for net.ipv4.ip_local_port_range is
Adding net.ipv4.ip_local_port_range = 9000 65500 
Setting kernel parameters as per oracle recommendations...
Altered file /etc/sysctl.conf
Saved a copy of the current file in /etc/sysctl.d/99-oracle-database-preinstall-21c-sysctl.conf
Check /etc/sysctl.d for backups
Verification & setting of kernel parameters passed 
Setting user limits using /etc/security/limits.d/oracle-database-preinstall-21c.conf
Verifying oracle user OS limits as per Oracle recommendations...
Adding oracle soft nofile  1024
Adding oracle hard nofile  65536
Adding oracle soft nproc  16384
Adding oracle hard nproc  16384
Adding oracle soft stack  10240
Adding oracle hard stack  32768
Adding oracle hard memlock  134217728
Adding oracle soft memlock  134217728
Adding oracle soft data  unlimited
Adding oracle hard data  unlimited
Setting oracle user OS limits as per Oracle recommendations...
Altered file /etc/security/limits.d/oracle-database-preinstall-21c.conf
Original file backed up at /var/log/oracle-database-preinstall-21c/backup/Dec-28-2021-15-52-12
Verification & setting of user limits passed 
Saving a copy of /etc/default/grub file in /etc/default/grub-initial.orabackup
Saving a copy of /etc/default/grub in /var/log/oracle-database-preinstall-21c/backup/Dec-28-2021-15-52-12...
Verifying kernel boot parameters as per Oracle recommendations...
old boot params: "rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto  vconsole.keymap=us rhgb quiet"
new boot params: "rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto vconsole.keymap=us rhgb quiet numa=off"
Setting boot params - Checking for blscfg
old boot params: "rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto vconsole.keymap=us rhgb quiet numa=off"
new boot params: "rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto vconsole.keymap=us rhgb quiet numa=off transparent_hugepage=never"
Setting boot params - Checking for blscfg
Setting kernel boot parameters as per Oracle recommendations...
G_DIR=/boot/grub2
Default Kernel -> /boot/vmlinuz-3.10.0-123.el7.x86_64
Running Kernel -> 3.10.0-123.el7.x86_64
Saving a copy of grubenv... in /var/log/oracle-database-preinstall-21c/backup/Dec-28-2021-15-52-12
Running grub2-mkconfig
Generating grub configuration file ...
File descriptor 199 (/run/lock/subsys/oracle-preinstall.lock) leaked on vgs invocation. Parent PID 6603: /usr/sbin/grub2-probe
File descriptor 199 (/run/lock/subsys/oracle-preinstall.lock) leaked on vgs invocation. Parent PID 6603: /usr/sbin/grub2-probe
Found linux image: /boot/vmlinuz-3.10.0-123.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-123.el7.x86_64.img
Warning: Please don't use old title `CentOS Linux, with Linux 3.10.0-123.el7.x86_64' for GRUB_DEFAULT, use `Advanced options for CentOS Linux>CentOS Linux, with Linux 3.10.0-123.el7.x86_64' (for versions before 2.00) or `gnulinux-advanced-6f2bbd1f-912e-4f65-8e24-191d20e781b8>gnulinux-3.10.0-123.el7.x86_64-advanced-6f2bbd1f-912e-4f65-8e24-191d20e781b8' (for 2.00 or later)
Found linux image: /boot/vmlinuz-0-rescue-0dcd05882fb70447861feb88e3315612
Found initrd image: /boot/initramfs-0-rescue-0dcd05882fb70447861feb88e3315612.img
File descriptor 199 (/run/lock/subsys/oracle-preinstall.lock) leaked on vgs invocation. Parent PID 6819: /usr/sbin/grub2-probe
File descriptor 199 (/run/lock/subsys/oracle-preinstall.lock) leaked on vgs invocation. Parent PID 6819: /usr/sbin/grub2-probe
done
Setting the default back to /boot/vmlinuz-3.10.0-123.el7.x86_64
Boot parameters will be effected on next reboot
Altered file /etc/default/grub
Copy of the changed file is in - /etc/default/grub-oracle-database-preinstall-21c.orabackup
Copy of the original file is in - /var/log/oracle-database-preinstall-21c/backup/Dec-28-2021-15-52-12
Verification & setting of boot parameters passed 
Trying to add NOZEROCONF parameter...
Taking a backup of existing file to /etc/sysconfig/network.orabackup
Successfully added parameter NOZEROCONF to /etc/sysconfig/network
Setting /etc/sysconfig/network parameters passed 
Disabling Transparent Hugepages. 
Refer Oracle Note:1557478.1
Disabling defrag. 
Refer Oracle Note:1557478.1
Taking a backup of old config files under /var/log/oracle-database-preinstall-21c/backup/Dec-28-2021-15-52-12


数据库安装包(oracle-database)

数据库安装包的安装文档:

https://docs.oracle.com/en/database/oracle/oracle-database/21/ladbi/installing-oracle-database-using-rpm-packages.html

需要注意:


rpm包不支持使用 rpm -Uvh进行升级

rpm安装可以在一台机器上用不同的ORACLE_HOME安装多个版本

下载链接:

https://www.oracle.com/database/technologies/oracle-database-software-downloads.html

image.png

在这个网页里面点击“See All”

image.png

这里有两个Linux的版本分别对应Linux 8和Linux 7,下面还有预安装包的下载链接。

数据库安装包会自动完成以下操作:

执行预安装检查

展开数据库软件包

将展开的软件的所有权重新分配给预配置的用户和组

维护Oracle inventory

使用root权限为Oracle数据库的创建进行配置

使用下面的命令进行安装

#  yum -y localinstall oracle-database-ee-21c-1.0-1.ol7.x86_64.rpm
Loaded plugins: fastestmirror
Examining oracle-database-ee-21c-1.0-1.ol7.x86_64.rpm: oracle-database-ee-21c-1.0-1.x86_64
Marking oracle-database-ee-21c-1.0-1.ol7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package oracle-database-ee-21c.x86_64 0:1.0-1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================
 Package                          Arch             Version          Repository                                          Size
=============================================================================================================================
Installing:
 oracle-database-ee-21c           x86_64           1.0-1            /oracle-database-ee-21c-1.0-1.ol7.x86_64           7.1 G
Transaction Summary
=============================================================================================================================
Install  1 Package
Total size: 7.1 G
Installed size: 7.1 G
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : oracle-database-ee-21c-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-21c configure
  Verifying  : oracle-database-ee-21c-1.0-1.x86_64                                                                       1/1
Installed:
  oracle-database-ee-21c.x86_64 0:1.0-1
Complete!



可以看到在整个安装过程中没有下载依赖包,因为在之前安装预安装包时依赖包都安装好了。

检查安装日志的例子如下:


# cat /var/log/oracle-database-ee-21c/results/oraInstall.log 
[INFO] Starting the installation process of the Oracle Database...
12/29/2021-10:52:27 AM
[INFO] Verifying the final status of the user after all the prechecks execution: 
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba),54330(racdba)
[INFO] Registering Oracle home to the Oracle inventory...
[INFO] Oracle home registered to the Oracle inventory.
[INFO] Executing post installation scripts...
[INFO] Setting up inventory as it has not been setup on this machine.
[INFO] Configuring ADR directories...
[INFO] ADR directories configured.
[INFO] Post installation scripts executed successfully.
[INFO] Creating configuration directories for Oracle Home...
[INFO] Configuration directories created.
[INFO] Post installation scripts executed successfully.
[INFO] Oracle home installed successfully and ready to be configured.



创建数据库

安装完成后,可以使用/etc/init.d/oracledb_ORCLCDB-21c服务脚本(在18c和19c上也有类似的脚步)创建一个新的数据库。创建数据库之前可以修改下面的文件进行相关配置:


# cat /etc/sysconfig/oracledb_ORCLCDB-21c.conf|grep -v '^#'| grep -v '^$'
LISTENER_PORT=1521
ORACLE_DATA_LOCATION=/opt/oracle/oradata
EM_EXPRESS_PORT=5500


创建数据库的例子如下:


#  /etc/init.d/oracledb_ORCLCDB-21c configure
Configuring Oracle Database ORCLCDB.
Prepare for db operation
8% complete
Copying database files
31% complete
Creating and starting Oracle instance
32% complete
36% complete
40% complete
43% complete
46% complete
Completing Database Creation
51% complete
54% complete
Creating Pluggable Databases
58% complete
77% 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.


建库完成后的操作

登录到Oracle用户,配置环境变量:


export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/21c/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=ORCLCDB


检查监听器的状态:


$ lsnrctl status
LSNRCTL for Linux: Version 21.0.0.0.0 - Production on 29-DEC-2021 11:44:51
Copyright (c) 1991, 2021, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=centos78)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 21.0.0.0.0 - Production
Start Date                29-DEC-2021 11:24:58
Uptime                    0 days 0 hr. 19 min. 53 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/homes/OraDBHome21cEE/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/centos78/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=centos78)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=centos78)(PORT=5500))(Security=(my_wallet_directory=/opt/oracle/admin/ORCLCDB/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "ORCLCDB" has 1 instance(s).
  Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
Service "ORCLCDBXDB" has 1 instance(s).
  Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
Service "d441b43e7eb549dfe055872a80f56c76" has 1 instance(s).
  Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
Service "orclpdb1" has 1 instance(s).
  Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
The command completed successfully


发现实例已经注册上了,通过sqlplus连接到orclcdb实例,执行以下操作:


$ sqlplus / as sysdba
SQL*Plus: Release 21.0.0.0.0 - Production on Wed Dec 29 11:44:55 2021
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle.  All rights reserved.
Connected to:
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
SQL> show pdbs;
    CON_ID CON_NAME     OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
  2 PDB$SEED     READ ONLY  NO
  3 ORCLPDB1     READ WRITE NO
SQL> alter user sys identified by yaoyuan;
User altered.
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
BANNER_FULL
--------------------------------------------------------------------------------
BANNER_LEGACY
--------------------------------------------------------------------------------
    CON_ID
----------
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
  0
BANNER
--------------------------------------------------------------------------------
BANNER_FULL
--------------------------------------------------------------------------------
BANNER_LEGACY
--------------------------------------------------------------------------------
    CON_ID
----------

建库结束!

相关文章
|
5天前
|
SQL 缓存 监控
|
5天前
|
前端开发 Linux Shell
|
19小时前
|
数据可视化 搜索推荐 Linux
|
2天前
|
资源调度 JavaScript Ubuntu
Yarn介绍及快速安装Debian/Ubuntu Linux
现在,你已经成功安装了Yarn,可以在你的JavaScript项目中使用它来管理依赖。
20 3
|
2天前
|
Linux Shell 网络安全
网络安全中Dos和linux常用命令总结
本篇是对网安学习中,常用的命令做一个图文与命令示例,并对一些比较重要的dos和shell命令进行总结,方便自己后续学习进行查询,并希望能够给更多人有一个总结命令和了解命令的地方.
26 5
|
5天前
|
Linux
Linux系统ps命令
这些是一些常见的 `ps`命令选项和用法,用于查看系统中运行的进程及其相关信息。您可以根据需要选择合适的选项以满足您的任务要求。
16 0
|
5天前
|
存储 Linux Shell
linux课程第二课------命令的简单的介绍2
linux课程第二课------命令的简单的介绍2
|
5天前
|
Linux C语言 数据安全/隐私保护
linux课程第二课------命令的简单的介绍3
linux课程第二课------命令的简单的介绍3
|
5天前
|
监控 Unix Linux
如何使用 Linux less 命令?
【4月更文挑战第25天】
18 1
如何使用 Linux less 命令?
|
5天前
|
JSON 网络协议 Linux
Linux ip命令:网络的瑞士军刀
【4月更文挑战第25天】
10 1