Docker中使用rpm包的方式安装Oracle 19c

125 篇文章 109 订阅
作者:IT邦德
中国DBA联盟(ACDU)成员,目前从事DBA及程序编程
(Web\java\Python)工作,主要服务于生产制造
现拥有 Oracle 11g  OCP/OCM、
Mysql、Oceanbase(OBCA)认证
分布式TBase\TDSQL数据库、国产达梦数据库以及红帽子认证
从业8年DBA工作,在数据库领域有丰富的经验
B站主播Oracle、Mysql、PG实战课程,请搜索:jeames007

擅长Oracle数据库运维开发,备份恢复,安装迁移,性能优化、故障应急处理等。

在这里插入图片描述

前言

本次部署为Docker环境下在线部署Oracle 19C

一、创建CentOS7.6的容器

https://hub.docker.com/_/centos?tab=tags

1.1 拉取镜像

[root@docker ~]#  docker pull centos:7.6.1810

1.2 创建容器

[root@docker ~]# docker run -d --name oracle19C -h oracle19C \
-p 5500-5510:5500-5510 -p 1524:1521 -p 230:22 \
--network=mynet --ip 172.18.12.6 \
--privileged=true \
centos:7.6.1810 /usr/sbin/init

[root@docker ~]# docker update --restart=always oracle19C   --开机自启

1.3 修改时区

[root@docker ~]# docker cp /usr/share/zoneinfo/Asia/Shanghai oracle19C:/etc/localtime

1.4 进入容器

[root@docker ~]# docker exec -it oracle19C /bin/bash

1.5 安装一些必要的系统包

yum install -y openssh-clients openssh-server initscripts  net-tools telnet which wget passwd e4fsprogs lrzsz sudo unzip lvm2 tree traceroute bridge-utils dos2unix rlwrap
yum -y install vim redhat-lsb

1.6 解决agetty进程

cpu占用率100%,宿主机和容器都需要执行
systemctl stop getty@tty1.service
systemctl mask getty@tty1.service

1.7 启动ssh进程

[root@oracle19C /]# systemctl restart sshd
[root@oracle19C /]# echo "root:root" | chpasswd  --修改root用户密码

1.8 远程登录

ssh root@192.168.1.54 -p 223    --cmd可以测试登陆

1.9 配置容器内的yum源:阿里云

[root@oracle19C /]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@oracle19C /]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

[root@oracle19C /]# yum clean all
[root@oracle19C /]# rpm --rebuilddb

二、rpm方式安装Oracle 19c

2.1 、安装database-preinstall包

https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/index.html
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

2.2、下载安装db软件,上传到docker容器内

下载db 19c的地址:https://www.oracle.com/database/technologies/oracle-database-software-downloads.html
安装19c数据库软件:
[root@docker ~]# docker cp oracle-database-ee-19c-1.0-1.x86_64.rpm oracle19C:/
[root@oracle19C /]#  yum install -y oracle-database-ee-19c-1.0-1.x86_64.rpm

2.3、创建数据库实例

参数文件:/etc/init.d/oracledb_ORCLCDB-19c、/etc/sysconfig/oracledb_ORCLCDB-19c.conf
[root@oracle19C /]# /etc/init.d/oracledb_ORCLCDB-19c configure
此过程即静默建库的过程,我们也可以使用DBCA命令来直接创建数据库

注:/etc/init.d/oracledb_ORCLCDB-19c configure #也可以重启数据库

在这里插入图片描述

三、数据库配置

xftp 上传软件包 rlwrap 源代码包安装
3.1、修改密码

此处若sqlplus命令无效,先修改环境变量
#rpm安装,数据库会产生随机密码,所以需要我们自行修改密码
SYS@ORCLCDB> alter user sys identified by oracle;

3.2、修改参数

#rpm安装,若主机内存很大,则生成的数据库会分配很大的sga,我们自己测试,最好将内存修改小一点
SYS@ORCLCDB> alter system set sga_max_size=1g scope=spfile;
SYS@ORCLCDB> alter system set pga_aggregate_target=100m;
SYS@ORCLCDB> startup force
SYS@ORCLCDB> create pfile='/home/oracle/init1.ora' from spfile;
修改创建好的pfile
SYS@ORCLCDB> startup pfile='/home/oracle/init1.ora'

此时如果设置不当会存在数据库启动不了的情况
ORA-00823 Specified value of sga_target greater than sga_max_size
原因分析:原因是设定的sga_target大于指定值的sga_max_size值
[oracle@oracle19C ~]$ sqlplus /nolog
@> conn / as sysdba
SYS@ORCLCDB> create spfile from pfile='/home/oracle/init1.ora';
SYS@ORCLCDB> startup pfile='/home/oracle/init1.ora'    --等待启动是否正常
SYS@ORCLCDB> shu immediate
SYS@ORCLCDB> create spfile from pfile='/home/oracle/init1.ora';

3.3、修改EM的展现方式

可通过如下命令切换
##切换为Flash-based的EM Express
SQL> @?/rdbms/admin/execemx emx
##切换为Java JET的EM Express
SQL> @?/rdbms/admin/execemx omx

访问容器内的EM:
https://192.168.1.54:5500/em

3.4、配置用户环境变量

cat  >>  /home/oracle/.bash_profile << "EOF"

export ORACLE_SID=ORCLCDB
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19c/dbhome_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export PATH=$ORACLE_HOME/bin:$PATH
export TNS_ADMIN=$ORACLE_HOME/network/admin

export NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
alias asmcmd='rlwrap asmcmd'
alias sql='sqlplus / as sysdba'

EOF

cat >> $ORACLE_HOME/sqlplus/admin/glogin.sql << "EOF"

set linesize 9999 pagesize 9999
set sqlprompt "_USER'@'_CONNECT_IDENTIFIER> "
EOF

四、重启容器后的操作

4.1 若重启容器后,则需要重新启动db,如下

[root@docker ~]# docker start oracle19C
oracle19C
You have new mail in /var/spool/mail/root
[root@docker~]# docker exec -it oracle19C bash
[root@oracle19C /]# ps -ef|grep pmon
root       971   941  0 15:22 pts/1    00:00:00 grep --color=auto pmon
[root@oracle19C /]# /etc/init.d/oracledb_ORCLCDB-19c start
Starting Oracle Net Listener.
Oracle Net Listener started.
Starting Oracle Database instance ORCLCDB.
Oracle Database instance ORCLCDB started.

[root@oracle19C /]# su - oracle
Last login: Wed Jun 24 15:22:45 CST 2020 on pts/1
[oracle@oracle19C ~]$ sql

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jun 24 15:23:19 2020
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> show pdbs
SQL> alter pluggable database all open;  --开PDB库
alter user sys identified by oracle;  --cdb中修改
SQL> select name,cdb from v$database;

SYS@ORCLCDB> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB1                       READ WRITE NO
SYS@ORCLCDB> ! lsnrctl status

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 24-JUN-2020 15:23:29

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle19C)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                24-JUN-2020 15:22:45
Uptime                    0 days 0 hr. 0 min. 43 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/lhr2019ocp/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhr2019ocp)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhr2019ocp)(PORT=5500))(Security=(my_wallet_directory=/opt/oracle/product/19c/dbhome_1/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 "a8be8cc09f902cd2e0530d0011ac912e" 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

4.2 CDB及PDB相关操作

SYS@ORCLCDB> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB1                       READ WRITE NO

TNS配置
ORCLPDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = oracle19C)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORCLPDB1)
    )
  )

connect 切换到edbpdb 中 sys 用户
SYS@ORCLCDB>conn sys/oracle@ORCLPDB1 as sysdba;

切回 cdb 关闭数据库实例
SYS@ORCLPDB1>conn / as sysdba
SYS@ORCLCDB>shutdown immediate;

SQL> alter pluggable database ORCLPDB1 open;   --CDB管理PDB
SQL> alter pluggable database all open;
SQL> alter pluggable database all close;  -关闭

如果觉得文章对你有帮助,点赞、收藏、关注、评论,一键四连支持
您的批评指正是我写作的最大动力!

❤️ 技术交流可以 关注公众号:IT邦德 ❤️

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT邦德

客户部署资料,步骤超详细

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值