Oracle 21c部署 in Docker

目录

# 热分配新硬盘

# 拉取镜像

# 启动数据库

访问Oracle数据库

本环境的用途为开发测试环境;所以,分配给Oracle的资源相对较低;如果在生产环境下,请提前规范分配的CPU、内存、IO、磁盘(本地磁盘 or 网络存储、磁盘空间大小);

本案例通过docker run启动容器,当然也可以通过docker-compose、kubernetes等平台启动管理。

# 热分配新硬盘

# 手动扫描新硬盘

echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan

# 磁盘分区和格式化

fdisk /dev/sdd
pvcreate /dev/sdd1 

vgextend  centos_k8s-testing-02-191 /dev/sdd1
lvcreate -l15360 -n oracle centos_k8s-testing-02-191
mkfs.xfs /dev/mapper/centos_k8s--testing--02--191-oracle

#挂载磁盘到/oradata

mkdir /oradata
mount /dev/mapper/centos_k8s--testing--02--191-oracle /oradata

#写入文件系统表

vi /etc/fstab 
/dev/mapper/centos_k8s--testing--02--191-oracle /oradata          xfs     defaults        0 0
 

# 拉取镜像

1、访问https://container-registry.oracle.com/,登录后点击同意《Oracle 标准条款和限制》;
2、然后在容器环境下执行docker login container-registry.oracle.com
3、执行docker pull container-registry.oracle.com/database/enterprise:21.3.0.0
$ docker images |grep enter
container-registry.oracle.com/database/enterprise   21.3.0.0            da441e2c6de2   7 months ago    8.01GB
container-registry.oracle.com/database/enterprise   latest              da441e2c6de2   7 months ago    8.01GB

# 启动数据库

## host上的挂载目录的权限必须保证uid=54321用户的读写,所以这里要赋予777,剩下的交给oracle
chmod 777 /oradata/
id oracle
uid=54321(oracle) gid=54321(oinstall) 组=54321(oinstall),54322(dba),54323(oper)

# 启动前替换##PASSWORD##为所需的密码

docker run -d --name oracle21cee \
-p 1521:1521 -p 5500:5500 \
-e ORACLE_SID=orcl \
-e ORACLE_PDB=orclpdb \
-e ORACLE_PWD=##PASSWORD## \
-e ORACLE_EDITION=ee \
-e ORACLE_CHARACTERSET=ZHS16GBK \
-e TZ="Asia/Shanghai" \
-e ENABLE_ARCHIVELOG=false \
-v /oradata:/opt/oracle/oradata \
container-registry.oracle.com/database/enterprise

通过docker logs -f oracle12cee查看日志。
出现如下标志则表示数据库启动成功:
#########################
DATABASE IS READY TO USE!
#########################
 

访问Oracle数据库

# sqlplus访问数据库
docker exec -it oracle12cee /bin/bash
$ sqlplus / as sysdba

SQL*Plus: Release 21.0.0.0.0 - Production on Fri May 19 09:55:57 2023
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>

# 远程访问数据库,查看监听状态:The listener supports no services

$ lsnrctl status

LSNRCTL for Linux: Version 21.0.0.0.0 - Production on 19-MAY-2023 10:25:21

Copyright (c) 1991, 2021, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 21.0.0.0.0 - Production
Start Date                19-MAY-2023 10:09:50
Uptime                    0 days 0 hr. 15 min. 31 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/homes/OraDB21Home1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/9319863cd1ed/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
The listener supports no services
The command completed successfully

# 解决一:登录数据库,强制注册服务:ALTER SYSTEM REGISTER;         --- 未生效。
SQL> ALTER SYSTEM REGISTER;
System altered.
SQL> quit

# 只能使用静态注册,修改listener.ora并重启监听

cd /oradata/dbconfig/ORCL
cp -p listener.ora{,_bak}
vi listener.ora
LISTENER =
(DESCRIPTION_LIST =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
    (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
  )
)


SID_LIST_LISTENER =
(SID_LIST =
  (SID_DESC =
    (GLOBAL_DBNAME = ORCL)
    (ORACLE_HOME = /opt/oracle/product/21c/dbhome_1)
    (SID_NAME = ORCL)
  )
  (SID_DESC =
    (GLOBAL_DBNAME = ORCLXDB)
    (ORACLE_HOME = /opt/oracle/product/21c/dbhome_1)
    (SID_NAME = ORCL)
  )
)


DEDICATED_THROUGH_BROKER_LISTENER=ON
DIAG_ADR_ENABLED = off

注意:SID_NAME和GLOBAL_DBNAME要使用大写,否则不可用,访问时报下面的错误信息。

ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory

你可能感兴趣的:(数据库,oracle,docker,数据库)