基于CentOS 7.8 操作系统,使用rpm包快速安装Oracle Database 19c。
参考:
https://docs.oracle.com/en/database/oracle/oracle-database/19/ladbi/running-rpm-packages-to-install-oracle-database.html
1、以root用户身份,下载并安装 Oracle 数据库预安装 RPM
参考:https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/
curl -o oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm yum -y localinstall oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
2、访问Oracle 官网数据库下载页面
https://www.oracle.com/database/technologies/oracle-database-software-downloads.html
从 Oracle 官网下载 Oracle 数据库 RPM 安装包,将oracle-database-ee-19c-1.0-1.x86_64.rpm文件上传到/tmp目录。
3、使用yum localinstall命令安装数据库软件
cd /tmp yum -y localinstall oracle-database-ee-19c-1.0-1.x86_64.rpm
Oracle 数据库软件的安装现已完成,安装的缺省目录为 /opt
[root@localhost ~]# ll /opt/ total 0 drwxr-xr-x 6 oracle oinstall 72 Sep 29 00:06 oracle drwxr-xr-x 3 root root 22 Sep 29 00:06 ORCLfmap
注意,以上只是完成了软件的安装部署,接下来如果要创建数据库,还需要用 root 身份执行一个脚本进行配置。
4、创建和配置示例 Oracle 数据库实例,登录为root用户,运行以下服务配置脚本:
/etc/init.d/oracledb_ORCLCDB-19c configure
当我们执行命令时,后台实际上自动进行了一个静默的数据库创建,数据库创建的执行过程如下:
[root@localhost ~]# /etc/init.d/oracledb_ORCLCDB-19c 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.
可以通过编辑/etc/sysconfig/oracledb_ORCLCDB-19c.conf文件来修改默认配置参数。
$ cat /etc/sysconfig/oracledb_ORCLCDB-19c.conf #This is a configuration file to setup the Oracle Database. #It is used when running '/etc/init.d/oracledb_ORCLCDB configure'. #Please use this file to modify the default listener port and the #Oracle data location. # LISTENER_PORT: Database listener LISTENER_PORT=1521 # ORACLE_DATA_LOCATION: Database oradata location ORACLE_DATA_LOCATION=/opt/oracle/oradata # EM_EXPRESS_PORT: Oracle EM Express listener EM_EXPRESS_PORT=5500
5、创建完成之后,切换到oracle 用户
su - oracle
配置环境变量
cat >> ~/.bash_profile <<'EOF' # Set environment variables for Oracle user umask 022 export ORACLE_SID=ORCLCDB export ORACLE_base=/opt/oracle/oradata export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1 export PATH=$PATH:$ORACLE_HOME/bin EOF source ~/.bash_profile
登入数据库
[oracle@localhost ~]$ sqlplus / as sysdba SQL*Plus: Release 19.0.0.0.0 - Production on Wed Sep 29 00:51:53 2021 Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle. All rights reserved. Connected to an idle instance. SQL>
解锁帐户:
SQL> ALTER USER sys ACCOUNT UNLOCK;
重置密码:
SQL> ALTER USER sys IDENTIFIED BY oracle;
查看oracle安装版本
SQL> Select BANNER_FULL From V$Version; BANNER_FULL -------------------------------------------------------------------------------- Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0
查看数据库实例
SQL> Select Instance_name From V$Instance; INSTANCE_NAME ---------------- ORCLCDB
登录Oracle Enterprise Manager
https://192.168.92.31:5500/em
用户名为sys,密码为oracle:
查看数据库运行情况
修改/etc/oratab配置
[root@localhost ~]# vi /etc/oratab # last line : change ORCLCDB:/opt/oracle/product/19c/dbhome_1:Y
创建ORCLCDB.oracledb文件
[root@localhost ~]# vi /etc/sysconfig/ORCLCDB.oracledb # create new : define environment variables ORACLE_base=/opt/oracle/oradata ORACLE_HOME=/opt/oracle/product/19c/dbhome_1 ORACLE_SID=ORCLCDB
创建listener service
[root@localhost ~]# vi /usr/lib/systemd/system/ORCLCDB@lsnrctl.service # this is an example, modify for free [Unit] Description=Oracle Net Listener After=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
创建database service
[root@localhost ~]# vi /usr/lib/systemd/system/ORCLCDB@oracledb.service # this is an example, modify for free [Unit] Description=Oracle Database service After=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
停止脚本方式启动
[root@localhost ~]# /etc/init.d/oracledb_ORCLCDB-19c sotp
使用systemd启动服务并设为开机启动
[root@localhost ~]# systemctl daemon-reload [root@localhost ~]# systemctl enable --now ORCLCDB@lsnrctl [root@localhost ~]# systemctl enable --now ORCLCDB@oracledb
查看lsnrctl服务运行状态
[root@localhost ~]# systemctl status ORCLCDB@lsnrctl
● ORCLCDB@lsnrctl.service - Oracle Net Listener
Loaded: loaded (/usr/lib/systemd/system/ORCLCDB@lsnrctl.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-09-29 02:35:55 CST; 58s ago
Main PID: 42902 (tnslsnr)
CGroup: /system.slice/system-ORCLCDB.slice/ORCLCDB@lsnrctl.service
└─42902 /opt/oracle/product/19c/dbhome_1/bin/tnslsnr LISTENER -inherit
Sep 29 02:35:55 rsyslog-client lsnrctl[42900]: System parameter file is /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Sep 29 02:35:55 rsyslog-client lsnrctl[42900]: Log messages written to /opt/oracle/diag/tnslsnr/rsyslog-client/listener/alert/log.xml
Sep 29 02:35:55 rsyslog-client lsnrctl[42900]: Listening on: (DEscriptION=(ADDRESS=(PROTOCOL=tcp)(HOST=rsyslog-client)(PORT=1521)))
Sep 29 02:35:55 rsyslog-client lsnrctl[42900]: Listening on: (DEscriptION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Sep 29 02:35:55 rsyslog-client lsnrctl[42900]: Connecting to (DEscriptION=(ADDRESS=(PROTOCOL=TCP)(HOST=rsyslog-client)(PORT=1521)))
Sep 29 02:35:55 rsyslog-client lsnrctl[42900]: STATUS of the LISTENER
Sep 29 02:35:55 rsyslog-client lsnrctl[42900]: ------------------------
Sep 29 02:35:55 rsyslog-client lsnrctl[42900]: Alias LISTENER
Sep 29 02:35:55 rsyslog-client lsnrctl[42900]: Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Sep 29 02:35:55 rsyslog-client systemd[1]: Started Oracle Net Listener.
查看oracledb服务运行状态
[root@localhost ~]# systemctl status ORCLCDB@oracledb
● ORCLCDB@oracledb.service - Oracle Database service
Loaded: loaded (/usr/lib/systemd/system/ORCLCDB@oracledb.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-09-29 02:36:25 CST; 34s ago
Process: 42958 ExecStart=/opt/oracle/product/19c/dbhome_1/bin/dbstart $ORACLE_HOME (code=exited, status=0/SUCCESS)
CGroup: /system.slice/system-ORCLCDB.slice/ORCLCDB@oracledb.service
├─43066 ora_pmon_ORCLCDB
├─43068 ora_clmn_ORCLCDB
├─43070 ora_psp0_ORCLCDB
├─43075 ora_vktm_ORCLCDB
├─43080 ora_gen0_ORCLCDB
├─43082 ora_mman_ORCLCDB
├─43086 ora_gen1_ORCLCDB
├─43089 ora_diag_ORCLCDB
├─43091 ora_ofsd_ORCLCDB
├─43094 ora_dbrm_ORCLCDB
├─43096 ora_vkrm_ORCLCDB
├─43098 ora_svcb_ORCLCDB
├─43100 ora_pman_ORCLCDB
├─43102 ora_dia0_ORCLCDB
├─43104 ora_dbw0_ORCLCDB
├─43106 ora_lgwr_ORCLCDB
├─43108 ora_ckpt_ORCLCDB
├─43110 ora_lg00_ORCLCDB
├─43112 ora_smon_ORCLCDB
├─43114 ora_lg01_ORCLCDB
├─43116 ora_smco_ORCLCDB
├─43118 ora_reco_ORCLCDB
├─43120 ora_w000_ORCLCDB
├─43122 ora_lreg_ORCLCDB
├─43124 ora_w001_ORCLCDB
├─43126 ora_pxmn_ORCLCDB
├─43130 ora_mmon_ORCLCDB
├─43132 ora_mmnl_ORCLCDB
├─43134 ora_d000_ORCLCDB
├─43136 ora_s000_ORCLCDB
├─43138 ora_tmon_ORCLCDB
├─43147 ora_m000_ORCLCDB
├─43149 ora_m001_ORCLCDB
├─43155 ora_tt00_ORCLCDB
├─43157 ora_tt01_ORCLCDB
├─43159 ora_tt02_ORCLCDB
├─43164 ora_aqpc_ORCLCDB
├─43166 ora_w002_ORCLCDB
├─43170 ora_p000_ORCLCDB
├─43172 ora_p001_ORCLCDB
├─43174 ora_p002_ORCLCDB
├─43176 ora_p003_ORCLCDB
├─43179 ora_cjq0_ORCLCDB
├─43409 ora_w003_ORCLCDB
├─43415 ora_s001_ORCLCDB
├─43427 ora_m002_ORCLCDB
├─43452 ora_m003_ORCLCDB
├─43454 ora_w004_ORCLCDB
├─43461 ora_qm02_ORCLCDB
├─43463 ora_qm03_ORCLCDB
├─43465 ora_q002_ORCLCDB
└─43467 ora_q003_ORCLCDB
Sep 29 02:36:11 rsyslog-client systemd[1]: Starting Oracle Database service...
Sep 29 02:36:12 rsyslog-client dbstart[42958]: Processing Database instance "ORCLCDB": log file /opt/oracle/product/19c/dbhome_1/rdbms/log/startup.log
Sep 29 02:36:25 rsyslog-client systemd[1]: Started Oracle Database service.
删除基于 RPM 的 Oracle 数据库安装
参考:https://docs.oracle.com/en/database/oracle/oracle-database/19/ladbi/removing-rpm-based-database-installation.html
1、删除实例和侦听器配置。
/etc/init.d/oracledb_ORCLCDB-19c stop
命令参考
[root@localhost ~]# /etc/init.d/oracledb_ORCLCDB-19c -h
Usage: /etc/init.d/oracledb_ORCLCDB-19c {start|stop|restart|configure|delete}
2、以root用户身份运行以下命令删除基于 RPM 的数据库安装:
yum -y remove oracle-database-ee-19c
该yum命令检测 Oracle 主目录中默认配置的组件,例如数据库 (ORCLCDB) 和侦听器 (LISTENER),并为您删除这些组件。
除了默认数据库 (ORCLCDB) 和侦听器 (LISTENER) 之外,如果该yum命令检测到 Oracle 主目录中的其他配置组件(例如附加数据库或侦听器),则会停止卸载过程。将显示一条消息,指示您手动删除这些配置的组件。要删除这些配置的组件:
1、以 Oracle 数据库安装所有者用户 (oracle)身份登录。
2、要删除与您的安装关联的任何数据库,请使用 Oracle 数据库配置助手 (Oracle DBCA)。
cd $ORACLE_HOME/bin ./dbca
3、要删除与您的安装关联的任何侦听器,请运行 Oracle Net Configuration Assistant (Oracle NETCA)。
cd $ORACLE_HOME/bin ./netca
4、以身份登录root并yum再次运行该命令以删除基于 rpm 的数据库安装。
yum -y remove oracle-database-ee-19c
参考:
https://www.server-world.info/en/note?os=CentOS_7&p=oracle19c&f=6



