Oracle Database,又名Oracle RDBMS,或简称Oracle,是甲骨文公司开发的一款关系数据库管理系统。
劳伦斯·埃里森(Lawrence (Larry) Ellison) 和他的两个朋友以及前同事Bob Miner和Ed Oates,在1977年创建了软件开发实验室咨询公司(SDL,Software Development Laboratories),SDL开发了Oracle软件的最初版本。Oracle的名称来自于埃里森在Ampex工作时参加的一个由中央情报局创建的项目的代码名称。
目前Oracle能够在 Windows、UNIX、Linux 和 Mac OS 等最具影响力的平台上运行,Oracle 数据库有Enterprise Edition企业版、Standard Edition标准版、Express Edition(也称为XE)快捷版和Personal Edition个人版几个版本。
官方链接:
https://www.oracle.com/cn/database/
https://www.oracle.com/database/technologies/
https://docs.oracle.com/en/database/oracle/oracle-database
基于CentOS 8 操作系统,使用rpm包快速安装Oracle Database 19c。
参考:
https://docs.oracle.com/en/database/oracle/oracle-database/19/ladbi/running-rpm-packages-to-install-oracle-database.html
配置主机名
hostnamectl set-hostname oracledb
以root用户身份安装 Oracle 数据库预安装 RPM
centos7
yum install -y https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
centos8
dnf install -y https://yum.oracle.com/repo/OracleLinux/OL8/appstream/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el8.x86_64.rpm
或者配置oracle yum源
curl http://public-yum.oracle.com/public-yum-ol7.repo -o /etc/yum.repos.d/public-yum-ol7.repo
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/public-yum-ol7.repo
rpm --import http://yum.oracle.com/RPM-GPG-KEY-oracle-ol7
yum --enablerepo=ol7_latest -y install oracle-database-preinstall-19c
访问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
文件上传到服务器。
安装oracle数据库软件
dnf localinstall -y oracle-database-ee-19c-1.0-1.x86_64.rpm
数据库默认安装位置为 /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 身份执行脚本进行配置。
首先修改oracledb_ORCLCDB-19c.conf配置自定义配置参数
[root@oracledb ~]# 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
创建示例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.
创建完成之后,切换到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@rsyslog-client ~]$ 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> select instance_name, host_name, version, startup_time from v$instance;
INSTANCE_NAME
----------------
HOST_NAME
----------------------------------------------------------------
VERSION STARTUP_T
----------------- ---------
ORCLCDB
oracledb
19.0.0.0.0 02-NOV-21
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
登录Oracle Enterprise Manager
https://192.168.92.31:5500/em
修改/etc/oratab配置
sed -i "s#dbhome_1:N#dbhome_1:Y#g" /etc/oratab
[root@oracledb ~]# tail -n1 /etc/oratab
ORCLCDB:/opt/oracle/product/19c/dbhome_1:Y
创建ORCLCDB.oracledb文件
cat >/etc/sysconfig/ORCLCDB.oracledb<<EOF
# create new : define environment variables
ORACLE_BASE=/opt/oracle/oradata
ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
ORACLE_SID=ORCLCDB
EOF
创建listener service
cat >/usr/lib/systemd/system/[email protected]<<'EOF'
# 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
EOF
创建database service
cat >/usr/lib/systemd/system/[email protected]<<'EOF'
# 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
EOF
停止脚本方式启动
[root@localhost ~]# /etc/init.d/oracledb_ORCLCDB-19c sotp
关闭监听
su - oracle
lsnrctl stop
使用systemd启动服务并设为开机启动
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable ORCLCDB@lsnrctl
[root@localhost ~]# systemctl enable --now ORCLCDB@oracledb
查看lsnrctl服务运行状态
[root@localhost ~]# systemctl status ORCLCDB@lsnrctl
● [email protected] - Oracle Net Listener
Loaded: loaded (/usr/lib/systemd/system/[email protected]; 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/[email protected]
└─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
● [email protected] - Oracle Database service
Loaded: loaded (/usr/lib/systemd/system/[email protected]; 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/[email protected]
├─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.
参考: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