一、安装Docker软件
二、创建CentOS7.6的容器
三、rpm方式安装Oracle 19c
3.1、安装database-preinstall包
3.2、下载安装db软件,上传到docker容器内
3.3、创建数据库实例
四、数据库配置
4.1、修改密码
4.2、修改参数
4.3、修改EM的展现方式
4.4、配置用户环境变量
五、重启容器后的操作
六、将容器打包成镜像上传,供其他用户使用
七、其他用户下载使用
CentOS 7安装Docker官网: https://docs.docker.com/engine/install/centos/
11、卸载掉旧版本的 Docker:
2yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
3
42、执行以下安装命令去安装依赖包:
5yum install -y yum-utils device-mapper-persistent-data lvm2
6yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
7
8yum -y install docker-ce docker-ce-cli containerd.io
9
10# 若执行报错,则配置yum源
11wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
12wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
13
14或一键安装:
15curl -fsSL get.docker.com -o get-docker.sh
16sh get-docker.sh
17
18
19systemctl start docker
20systemctl status docker
21
22
233、检查版本
24docker version
25docker info
1https://hub.docker.com/_/centos?tab=tags
2
3--拉取镜像
4docker pull centos:7.6.1810
5
6--创建容器
7docker 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
8
9--修改时区
10docker cp /usr/share/zoneinfo/Asia/Shanghai lhr2019ocp:/etc/localtime
11
12--进入容器
13docker exec -it lhr2019ocp /bin/bash
14
15--安装一些必要的系统包
16yum install -y openssh-clients openssh-server initscripts net-tools telnet which wget passwd e4fsprogs lrzsz sudo unzip lvm2 tree traceroute bridge-utils dos2unix rlwrap
17yum -y install vim redhat-lsb
18
19--解决agetty进程cpu占用率100%,宿主机和容器都需要执行
20systemctl stop getty@tty1.service
21systemctl mask getty@tty1.service
22
23--启动ssh进程
24systemctl restart sshd
25--修改root用户密码
26echo "root:lhr" | chpasswd
27
28--远程登录
29ssh root@192.168.1.35 -p222
30
31-- 配置容器内的yum源:阿里云
32wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
33wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
34
35yum clean all
36rpm --rebuilddb
如果OEL平台,只需要执行:
1yum -y install oracle-database-preinstall-19c
如果不是OEL平台,首先要下载对应平台的RPM包,我用的是CentOS,如下所示:
1yum install -y https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
具体地址可以打开https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/index.html
搜索preinstall-19c,找到,
安装过程:
1[root@lhr2019ocp /]# 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
2Loaded plugins: fastestmirror, ovl
3oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm | 18 kB 00:00:00
4Examining /var/tmp/yum-root-q4qyEj/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm: oracle-database-preinstall-19c-1.0-1.el7.x86_64
5Marking /var/tmp/yum-root-q4qyEj/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm to be installed
6Resolving Dependencies
7... ...
8Transaction Summary
9====================================================================================================================================================================================================================================================================================================================================================================
10Install 1 Package (+35 Dependent packages)
11Upgrade ( 2 Dependent packages)
12Total size: 8.7 M
13Total download size: 8.7 M
14Downloading packages:
15。。。
16Installed:
17 oracle-database-preinstall-19c.x86_64 0:1.0-1.el7
18Dependency Installed:
19 GeoIP.x86_64 0:1.5.0-14.el7 bind-libs.x86_64 32:9.11.4-16.P2.el7_8.6 bind-libs-lite.x86_64 32:9.11.4-16.P2.el7_8.6 bind-utils.x86_64 32:9.11.4-16.P2.el7_8.6 compat-libcap1.x86_64 0:1.10-7.el7 compat-libstdc++-33.x86_64 0:3.2.3-72.el7 ethtool.x86_64 2:4.8-10.el7 geoipupdate.x86_64 0:2.5.0-1.el7
20 gssproxy.x86_64 0:0.7.0-28.el7 keyutils.x86_64 0:1.5.8-3.el7 ksh.x86_64 0:20120801-142.el7 libXv.x86_64 0:1.0.11-1.el7 libXxf86dga.x86_64 0:1.1.4-2.1.el7 libaio-devel.x86_64 0:0.3.109-13.el7 libbasicobjects.x86_64 0:0.1.1-32.el7 libcollection.x86_64 0:0.7.0-32.el7
21 libdmx.x86_64 0:1.1.3-3.el7 libevent.x86_64 0:2.0.21-4.el7 libini_config.x86_64 0:1.3.1-32.el7 libnfsidmap.x86_64 0:0.25-19.el7 libpath_utils.x86_64 0:0.2.1-32.el7 libref_array.x86_64 0:0.1.5-32.el7 libstdc++-devel.x86_64 0:4.8.5-39.el7 libtirpc.x86_64 0:0.2.4-0.16.el7
22 libverto-libevent.x86_64 0:0.2.5-4.el7 lm_sensors-libs.x86_64 0:3.4.0-8.20160601gitf9185e5.el7 nfs-utils.x86_64 1:1.3.0-0.66.el7 quota.x86_64 1:4.01-19.el7 quota-nls.noarch 1:4.01-19.el7 rpcbind.x86_64 0:0.2.0-49.el7 smartmontools.x86_64 1:7.0-2.el7 sysstat.x86_64 0:10.1.5-19.el7
23 tcp_wrappers.x86_64 0:7.6-77.el7 xorg-x11-utils.x86_64 0:7.5-23.el7 xorg-x11-xauth.x86_64 1:1.0.9-1.el7
24Dependency Updated:
25 bind-license.noarch 32:9.11.4-16.P2.el7_8.6 libstdc++.x86_64 0:4.8.5-39.el7
26Complete!
27
28
29[root@lhr2019ocp /]# id oracle
30uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba),54330(racdba)
31[root@lhr2019ocp /]#
32[root@lhr2019ocp results]# rpm -ql oracle-database-preinstall-19c
33/etc/rc.d/init.d/oracle-database-preinstall-19c-firstboot
34/etc/security/limits.d/oracle-database-preinstall-19c.conf
35/etc/sysconfig/oracle-database-preinstall-19c
36/etc/sysconfig/oracle-database-preinstall-19c/oracle-database-preinstall-19c-verify
37/etc/sysconfig/oracle-database-preinstall-19c/oracle-database-preinstall-19c.param
38/usr/bin/oracle-database-preinstall-19c-verify
39/var/log/oracle-database-preinstall-19c
40/var/log/oracle-database-preinstall-19c/results
下载db 19c的地址:https://www.oracle.com/database/technologies/oracle-database-software-downloads.html安装19c数据库软件:
1yum install -y oracle-database-ee-19c-1.0-1.x86_64.rpm
1[root@lhr2019ocp ~]# yum install -y oracle-database-ee-19c-1.0-1.x86_64.rpm
2Loaded plugins: fastestmirror, ovl
3Examining oracle-database-ee-19c-1.0-1.x86_64.rpm: oracle-database-ee-19c-1.0-1.x86_64
4Marking oracle-database-ee-19c-1.0-1.x86_64.rpm to be installed
5Resolving Dependencies
6--> Running transaction check
7---> Package oracle-database-ee-19c.x86_64 0:1.0-1 will be installed
8--> Finished Dependency Resolution
9
10Dependencies Resolved
11
12=========================================================================================================================
13 Package Arch Version Repository Size
14=========================================================================================================================
15Installing:
16 oracle-database-ee-19c x86_64 1.0-1 /oracle-database-ee-19c-1.0-1.x86_64 6.9 G
17
18Transaction Summary
19=========================================================================================================================
20Install 1 Package
21
22Total size: 6.9 G
23Installed size: 6.9 G
24Downloading packages:
25Running transaction check
26Running transaction test
27Transaction test succeeded
28Running transaction
29 Installing : oracle-database-ee-19c-1.0-1.x86_64 1/1
30[INFO] Executing post installation scripts...
31[INFO] Oracle home installed successfully and ready to be configured.
32To configure a sample Oracle Database you can execute the following service configuration script as root: /etc/init.d/oracledb_ORCLCDB-19c configure
33 Verifying : oracle-database-ee-19c-1.0-1.x86_64 1/1
34
35Installed:
36 oracle-database-ee-19c.x86_64 0:1.0-1
37
38Complete!
创建数据库实例所使用的默认参数文件为:
/etc/init.d/oracledb_ORCLCDB-19c和
/etc/sysconfig/oracledb_ORCLCDB-19c.conf
需要以root用户执行:
1[root@oracle19clhr /]# /etc/init.d/oracledb_ORCLCDB-19c -h
2Usage: /etc/init.d/oracledb_ORCLCDB-19c {start|stop|restart|configure|delete}
运行过程:
1[root@lhr2019ocp ~]# /etc/init.d/oracledb_ORCLCDB-19c configure
2Configuring Oracle Database ORCLCDB.
3Prepare for db operation
48% complete
5Copying database files
631% complete
7Creating and starting Oracle instance
832% complete
936% complete
1040% complete
1143% complete
1246% complete
13Completing Database Creation
14Creating Pluggable Databases
1558% complete
1677% complete
17Executing Post Configuration Actions
18100% complete
19Database creation complete. For details check the logfiles at:
20 /opt/oracle/cfgtoollogs/dbca/ORCLCDB.
21Database Information:
22Global Database Name:ORCLCDB
23System Identifier(SID):ORCLCDB
24Look at the log file "/opt/oracle/cfgtoollogs/dbca/ORCLCDB/ORCLCDB.log" for further details.
25
26Database 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命令来直接创建数据库。
rpm安装,数据库会产生随机密码,所以需要我们自行修改密码:
1alter user sys identified by lhr;
rpm安装,若主机内存很大,则生成的数据库会分配很大的sga,我们自己测试,最好将内存修改小一点:
1alter system set sga_max_size=1g scope=spfile;
2alter system set sga_max_size=1g;
3alter system set pga_aggregate_target=100m;
4startup force
从Oracle Database 19c开始,Oracle不再推荐Flash-base的Enterprise Manager Express(EM Express),缺省采用Java JET技术。可通过如下命令切换:
1##切换为Flash-based的EM Express
2SQL> @?/rdbms/admin/execemx emx
3##切换为Java JET的EM Express
4SQL> @?/rdbms/admin/execemx omx
访问容器内的EM:
1https://192.168.1.35:5500/em
Java Flash格式展示:
Java JET格式展示:
1cat >> /home/oracle/.bash_profile << "EOF"
2
3export ORACLE_SID=ORCLCDB
4export ORACLE_BASE=/opt/oracle
5export ORACLE_HOME=$ORACLE_BASE/product/19c/dbhome_1
6export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
7export PATH=$ORACLE_HOME/bin:$PATH
8export TNS_ADMIN=$ORACLE_HOME/network/admin
9
10export NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
11export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
12
13alias sqlplus='rlwrap sqlplus'
14alias rman='rlwrap rman'
15alias asmcmd='rlwrap asmcmd'
16alias sas='sqlplus / as sysdba'
17
18EOF
19
20
21cat >> $ORACLE_HOME/sqlplus/admin/glogin.sql << "EOF"
22
23set linesize 9999 pagesize 9999
24set sqlprompt "_USER'@'_CONNECT_IDENTIFIER> "
25
26EOF
注意:对于18c的安装,和19c一样。以上代码中,凡是有19c的地方都修改为18c。
若重启容器后,则需要重新启动db,如下所示:
1[root@docker35 ~]# docker start lhr2019ocp
2lhr2019ocp
3You have new mail in /var/spool/mail/root
4[root@docker35 ~]# docker exec -it lhr2019ocp bash
5[root@lhr2019ocp /]# ps -ef|grep pmon
6root 971 941 0 15:22 pts/1 00:00:00 grep --color=auto pmon
7[root@lhr2019ocp /]# /etc/init.d/oracledb_ORCLCDB-19c start
8Starting Oracle Net Listener.
9Oracle Net Listener started.
10Starting Oracle Database instance ORCLCDB.
11Oracle Database instance ORCLCDB started.
12
13[root@lhr2019ocp /]# su - oracle
14Last login: Wed Jun 24 15:22:45 CST 2020 on pts/1
15[oracle@lhr2019ocp ~]$ sas
16
17SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jun 24 15:23:19 2020
18Version 19.3.0.0.0
19
20Copyright (c) 1982, 2019, Oracle. All rights reserved.
21
22
23Connected to:
24Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
25Version 19.3.0.0.0
26
27SYS@ORCLCDB> show pdbs
28
29 CON_ID CON_NAME OPEN MODE RESTRICTED
30---------- ------------------------------ ---------- ----------
31 2 PDB$SEED READ ONLY NO
32 3 ORCLPDB1 READ WRITE NO
33SYS@ORCLCDB> ! lsnrctl status
34
35LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 24-JUN-2020 15:23:29
36
37Copyright (c) 1991, 2019, Oracle. All rights reserved.
38
39Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhr2019ocp)(PORT=1521)))
40STATUS of the LISTENER
41------------------------
42Alias LISTENER
43Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
44Start Date 24-JUN-2020 15:22:45
45Uptime 0 days 0 hr. 0 min. 43 sec
46Trace Level off
47Security ON: Local OS Authentication
48SNMP OFF
49Listener Parameter File /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
50Listener Log File /opt/oracle/diag/tnslsnr/lhr2019ocp/listener/alert/log.xml
51Listening Endpoints Summary...
52 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhr2019ocp)(PORT=1521)))
53 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
54 (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))
55Services Summary...
56Service "ORCLCDB" has 1 instance(s).
57 Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
58Service "ORCLCDBXDB" has 1 instance(s).
59 Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
60Service "a8be8cc09f902cd2e0530d0011ac912e" has 1 instance(s).
61 Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
62Service "orclpdb1" has 1 instance(s).
63 Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
64The command completed successfully
1[root@docker35 ~]# docker container stop lhr2019ocp
2lhr2019ocp
3
4[root@docker35 ~]# docker commit lhr2019ocp lhrbest/oracle19clhr_rpm_db
5sha256:96b0393fbc96f2ee2c9f5de17e4cd9ee82818b112b3491c0c64bbc48ddf306b8
6You have new mail in /var/spool/mail/root
7[root@docker35 ~]# docker images | grep oracle19clhr_rpm_db
8lhrbest/oracle19clhr_rpm_db latest 96b0393fbc96 About a minute ago 12.5GB
9oracle19clhr_rpm_db 1.0 6749a424a440 About a minute ago 12.5GB
10[root@docker35 ~]#
11
12[root@docker35 ~]# docker login
13Authenticating with existing credentials...
14WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
15Configure a credential helper to remove this warning. See
16https://docs.docker.com/engine/reference/commandline/login/#credentials-store
17
18Login Succeeded
19
20--后台执行
21[root@docker35 ~]# nohup docker push lhrbest/oracle19clhr_rpm_db:latest &
22[1] 27202
23[root@docker35 ~]# ps -ef|grep push
24root 27202 4743 0 16:39 pts/5 00:00:00 docker push lhrbest/oracle19clhr_rpm_db:latest
25
26... ...
27
28[root@docker35 ~]# ps -ef|grep push
29root 16822 14646 0 08:41 pts/0 00:00:00 grep --color push
30[root@docker35 ~]#
31[root@docker35 ~]#
32[root@docker35 ~]# docker push lhrbest/oracle19clhr_rpm_db:latest
33The push refers to repository [docker.io/lhrbest/oracle19clhr_rpm_db]
34b70a2f017499: Layer already exists
3589169d87dbe2: Layer already exists
36latest: digest: sha256:0d1bf18e4242610d16fc342b4d6c8ff6bdefcbe39c5484eeb8b83e2c2dd016dd size: 743
正在上传:
上传完成后,打开网址https://hub.docker.com/,登陆自己的账号就可以看到如下内容:
1 -- 从docker hub下载
2docker pull lhrbest/oracle19clhr_rpm_db:latest
3docker run -itd -h oracle19clhr --name oracle19clhr -p 1521:1521 -p 5500:5500 --privileged=true lhrbest/oracle19clhr_rpm_db:latest /bin/bash
4
5docker exec -it oracle19clhr bash
6-- 执行其他数据库操作
网页地址:https://hub.docker.com/repository/docker/lhrbest/oracle19clhr_rpm_db/tags?page=1
运行过程:
1[root@docker36 ~]# docker images
2REPOSITORY TAG IMAGE ID CREATED SIZE
3[root@docker36 ~]# docker pull lhrbest/oracle19clhr_rpm_db:latest
4latest: Pulling from lhrbest/oracle19clhr_rpm_db
5ac9208207ada: Already exists
698a80bef5b13: Downloading [=================================================> ] 4.113GB/4.181GB
7... ...
8
9[root@docker36 ~]# docker images
10REPOSITORY TAG IMAGE ID CREATED SIZE
11lhrbest/oracle19clhr_rpm_db latest 96b0393fbc96 3 days ago 12.5GB
12
13[root@docker36 ~]# docker run -itd -h lhr2019ocp --name oracle19clhr -p 1521:1521 -p 5500:5500 --privileged=true lhrbest/oracle19clhr_rpm_db:latest /bin/bash
1497fadbc19ed338fa9845ade6779f4edbbb0435fb4c56b9f5221dd5ae60affeca
15[root@docker36 ~]# docker exec -it oracle19clhr bash
16[root@lhr2019ocp /]# /etc/init.d/oracledb_ORCLCDB-19c start
17Starting Oracle Net Listener.
18Oracle Net Listener started.
19Starting Oracle Database instance ORCLCDB.
20Oracle Database instance ORCLCDB started.
21
22[root@lhr2019ocp /]# ps -ef|grep pmon
23oracle 68 0 0 10:22 ? 00:00:00 ora_pmon_ORCLCDB
24root 512 25 0 10:24 pts/1 00:00:00 grep --color=auto pmon
25[root@lhr2019ocp /]# su - oracle
26Last login: Sun Jun 28 10:22:25 CST 2020 on pts/1
27[oracle@lhr2019ocp ~]$ sas
28
29SQL*Plus: Release 19.0.0.0.0 - Production on Sun Jun 28 10:24:52 2020
30Version 19.3.0.0.0
31
32Copyright (c) 1982, 2019, Oracle. All rights reserved.
33
34
35Connected to:
36Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
37Version 19.3.0.0.0
38
39SYS@ORCLCDB> show pdbs
40
41 CON_ID CON_NAME OPEN MODE RESTRICTED
42---------- ------------------------------ ---------- ----------
43 2 PDB$SEED READ ONLY NO
44 3 ORCLPDB1 READ WRITE NO
笔记本的cmd也可以直接连接容器内的数据库:
EM也可以正常访问:
至此,在Docker中使用rpm的方式来安装Oracle 19c数据库就给大家介绍完毕了。
下一篇给大家介绍在Docker中使用ASM存储的Oracle Restart环境的安装。
• 版权所有,欢迎分享本文,转载请保留出处 • 若有侵权请联系小麦苗删除