【DB宝3】在Docker中使用rpm包的方式安装Oracle 19c

【DB宝3】在Docker中使用rpm包的方式安装Oracle 19c

文章目录

  • 【DB宝3】在Docker中使用rpm包的方式安装Oracle 19c
  • 一、安装Docker软件
  • 二、创建CentOS7.6的容器
  • 三、rpm方式安装Oracle 19c
    • 3.1 、安装database-preinstall包
    • 3.2、下载安装db软件,上传到docker容器内
    • 3.3、创建数据库实例
  • 四、数据库配置
    • 4.1、修改密码
    • 4.2、修改参数
    • 4.3、修改EM的展现方式
    • 4.3、配置用户环境变量
  • 五、重启容器后的操作

本文公众号地址:https://mp.weixin.qq.com/s?__biz=MzIzOTA2NjEzNQ==&mid=2454779129&idx=1&sn=437a48ddf1cfa30c09c1dc21cd159ef1&chksm=fe8b9981c9fc10971de5c74735c46ab638092ca19afc87e61737520de2ae8d7f7398935e5b35&scene=21#wechat_redirect

一、安装Docker软件

CentOS 7安装Docker: https://docs.docker.com/engine/install/centos/

1、卸载掉旧版本的 Docker:
yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

2、执行以下安装命令去安装依赖包:
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum -y install docker-ce docker-ce-cli containerd.io

# 若执行报错,则配置yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

或一键安装:
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh


systemctl start docker
systemctl status docker


3、检查版本
docker version
docker info

二、创建CentOS7.6的容器

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

--拉取镜像
docker pull centos:7.6.1810

--创建容器
docker run -d --name lhr2019ocp -h lhr2019ocp -p 5500-5510:5500-5510 -p 1521:1521 -p 222:22 --privileged=true centos:7.6.1810 /usr/sbin/init

--修改时区
docker cp /usr/share/zoneinfo/Asia/Shanghai lhr2019ocp:/etc/localtime

--进入容器
docker exec -it lhr2019ocp /bin/bash

--安装一些必要的系统包
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

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

--启动ssh进程
systemctl restart sshd
--修改root用户密码
echo "root:lhr" | chpasswd

--远程登录
ssh root@192.168.1.35 -p222

-- 配置容器内的yum源:阿里云
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum clean all
rpm --rebuilddb

三、rpm方式安装Oracle 19c

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

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

下载db 19c的地址:https://www.oracle.com/database/technologies/oracle-database-software-downloads.html
安装19c数据库软件:

yum install -y oracle-database-ee-19c-1.0-1.x86_64.rpm

3.3、创建数据库实例

参数文件:/etc/init.d/oracledb_ORCLCDB-19c、/etc/sysconfig/oracledb_ORCLCDB-19c.conf

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

运行过程:

[root@lhr2019ocp ~]# /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
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.

此过程即静默建库的过程,我们也可以使用DBCA命令来直接创建数据库。

四、数据库配置

4.1、修改密码

alter user sys identified by lhr;

4.2、修改参数

alter system set sga_max_size=1g scope=spfile;
alter system set sga_max_size=1g;
alter system set pga_aggregate_target=100m;
startup force


4.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.35:5500/em

4.3、配置用户环境变量

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 sas='sqlplus / as sysdba'

EOF


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

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

EOF

注意:对于18c的安装,和19c一样。以上代码中,凡是有19c的地方都修改为18c。

五、重启容器后的操作

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

[root@docker35 ~]# docker start lhr2019ocp
lhr2019ocp
You have new mail in /var/spool/mail/root
[root@docker35 ~]# docker exec -it lhr2019ocp bash
[root@lhr2019ocp /]# ps -ef|grep pmon
root       971   941  0 15:22 pts/1    00:00:00 grep --color=auto pmon
[root@lhr2019ocp /]# /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@lhr2019ocp /]# su - oracle
Last login: Wed Jun 24 15:22:45 CST 2020 on pts/1
[oracle@lhr2019ocp ~]$ sas

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

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=lhr2019ocp)(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





[root@docker35 ~]# docker container stop lhr2019ocp
lhr2019ocp

[root@docker35 ~]# docker commit lhr2019ocp lhrbest/oracle19clhr_rpm_db
sha256:96b0393fbc96f2ee2c9f5de17e4cd9ee82818b112b3491c0c64bbc48ddf306b8
You have new mail in /var/spool/mail/root
[root@docker35 ~]# docker images | grep oracle19clhr_rpm_db
lhrbest/oracle19clhr_rpm_db      latest              96b0393fbc96        About a minute ago   12.5GB
oracle19clhr_rpm_db              1.0                 6749a424a440        About a minute ago   12.5GB
[root@docker35 ~]# 

[root@docker35 ~]# docker login
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

--后台执行
[root@docker35 ~]# nohup docker push lhrbest/oracle19clhr_rpm_db:latest &
[1] 27202
[root@docker35 ~]# ps -ef|grep push
root     27202  4743  0 16:39 pts/5    00:00:00 docker push lhrbest/oracle19clhr_rpm_db:latest

... ...

[root@docker35 ~]# ps -ef|grep push
root     16822 14646  0 08:41 pts/0    00:00:00 grep --color push
[root@docker35 ~]# 
[root@docker35 ~]# 
[root@docker35 ~]# docker push lhrbest/oracle19clhr_rpm_db:latest
The push refers to repository [docker.io/lhrbest/oracle19clhr_rpm_db]
b70a2f017499: Layer already exists 
89169d87dbe2: Layer already exists 
latest: digest: sha256:0d1bf18e4242610d16fc342b4d6c8ff6bdefcbe39c5484eeb8b83e2c2dd016dd size: 743

About Me


● 本文作者:小麦苗,部分内容整理自网络,若有侵权请联系小麦苗删除
● 本文在个人微 信公众号(DB宝)上有同步更新
● QQ群号: 230161599 、618766405,微信群私聊
● 个人QQ号(646634621),微 信号(db_bao),注明添加缘由
● 于 2020年7月 在西安完成
● 最新修改时间:2020年7月
● 版权所有,欢迎分享本文,转载请保留出处


●小麦苗的微店: https://weidian.com/s/793741433?wfr=c&ifr=shopdetail
●小麦苗出版的数据库类丛书: http://blog.itpub.net/26736162/viewspace-2142121/
●小麦苗OCP、OCM、高可用、DBA学习班: http://blog.itpub.net/26736162/viewspace-2148098/
●数据库笔试面试题库及解答: http://blog.itpub.net/26736162/viewspace-2134706/


使用微信客户端扫描下面的二维码来关注小麦苗的微信公众号(DB宝)及QQ群(DBA宝典)、添加小麦苗微信, 学习最实用的数据库技术。
【DB宝3】在Docker中使用rpm包的方式安装Oracle 19c_第1张图片


你可能感兴趣的:(oracle,RAC系列)