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

举报
小麦苗DB宝 发表于 2022/02/21 12:44:20 2022/02/21
【摘要】 一、安装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-logro...

一、安装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
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。