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

建库结束!

相关文章
|
29天前
|
Linux 网络安全 数据安全/隐私保护
Linux 超级强大的十六进制 dump 工具:XXD 命令,我教你应该如何使用!
在 Linux 系统中,xxd 命令是一个强大的十六进制 dump 工具,可以将文件或数据以十六进制和 ASCII 字符形式显示,帮助用户深入了解和分析数据。本文详细介绍了 xxd 命令的基本用法、高级功能及实际应用案例,包括查看文件内容、指定输出格式、写入文件、数据比较、数据提取、数据转换和数据加密解密等。通过掌握这些技巧,用户可以更高效地处理各种数据问题。
74 8
|
29天前
|
监控 Linux
如何检查 Linux 内存使用量是否耗尽?这 5 个命令堪称绝了!
本文介绍了在Linux系统中检查内存使用情况的5个常用命令:`free`、`top`、`vmstat`、`pidstat` 和 `/proc/meminfo` 文件,帮助用户准确监控内存状态,确保系统稳定运行。
213 6
|
1月前
|
Linux
在 Linux 系统中,“cd”命令用于切换当前工作目录
在 Linux 系统中,“cd”命令用于切换当前工作目录。本文详细介绍了“cd”命令的基本用法和常见技巧,包括使用“.”、“..”、“~”、绝对路径和相对路径,以及快速切换到上一次工作目录等。此外,还探讨了高级技巧,如使用通配符、结合其他命令、在脚本中使用,以及实际应用案例,帮助读者提高工作效率。
77 3
|
1月前
|
监控 安全 Linux
在 Linux 系统中,网络管理是重要任务。本文介绍了常用的网络命令及其适用场景
在 Linux 系统中,网络管理是重要任务。本文介绍了常用的网络命令及其适用场景,包括 ping(测试连通性)、traceroute(跟踪路由路径)、netstat(显示网络连接信息)、nmap(网络扫描)、ifconfig 和 ip(网络接口配置)。掌握这些命令有助于高效诊断和解决网络问题,保障网络稳定运行。
69 2
|
11天前
|
Linux Shell
Linux 10 个“who”命令示例
Linux 10 个“who”命令示例
39 14
Linux 10 个“who”命令示例
|
17小时前
|
Ubuntu Linux
Linux 各发行版安装 ping 命令指南
如何在不同 Linux 发行版(Ubuntu/Debian、CentOS/RHEL/Fedora、Arch Linux、openSUSE、Alpine Linux)上安装 `ping` 命令,详细列出各发行版的安装步骤和验证方法,帮助系统管理员和网络工程师快速排查网络问题。
34 20
|
1天前
|
Unix Linux 编译器
UNIX/Linux 上的安装
UNIX/Linux 上的安装。
7 2
|
1天前
|
网络协议 Linux 应用服务中间件
kali的常用命令汇总Linux
kali的常用命令汇总linux
20 7
|
28天前
|
Oracle Cloud Native 关系型数据库
Oracle Linux 9.5 正式版发布 - Oracle 提供支持 RHEL 兼容发行版
Oracle Linux 9.5 正式版发布 - Oracle 提供支持 RHEL 兼容发行版
60 10
Oracle Linux 9.5 正式版发布 - Oracle 提供支持 RHEL 兼容发行版
|
20天前
|
Linux 数据库
Linux中第一次使用locate命令报错?????
在Linux CentOS7系统中,使用`locate`命令时出现“command not found”错误,原因是缺少`mlocate`包。解决方法是通过`yum install mlocate -y`或`apt-get install mlocate`安装该包,并执行`updatedb`更新数据库以解决后续的“can not stat”错误。
30 9