一、安装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、配置用户环境变量
五、重启容器后的操作
六、将容器打包成镜像上传,供其他用户使用
七、其他用户下载使用
一、安装Docker软件
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
二、创建CentOS7.6的容器
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
以上命令执行完后,就可以通过笔记本的cmd直接连接到容器内,注意端口的映射关系:
三、rpm方式安装Oracle 19c
3.1、安装database-preinstall包
1yum -y install oracle-database-preinstall-19c
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
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
安装过程中会安装系统依赖包,等安装完成后,就会创建orale用户和组,也会修改系统参数,详见目录:/var/log/oracle-database-preinstall-19c/results。
3.2、下载安装db软件,上传到docker容器内
下载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!
3.3、创建数据库实例
/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.
四、数据库配置
4.1、修改密码
1alter user sys identified by lhr;
4.2、修改参数
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
4.3、修改EM的展现方式
1##切换为Flash-based的EM Express
2SQL> @?/rdbms/admin/execemx emx
3##切换为Java JET的EM Express
4SQL> @?/rdbms/admin/execemx omx
1https://192.168.1.35:5500/em
4.4、配置用户环境变量
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
五、重启容器后的操作
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-- 执行其他数据库操作
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也可以直接连接容器内的数据库:
• 微信公众号:DB宝,作者:小麦苗
• 作者博客地址:http://blog.itpub.net/26736162/
• 作者微信:db_bao• 作者QQ:646634621,QQ群:230161599、618766405
• 提供Oracle OCP、OCM、高可用(rac+dg+ogg)和MySQL最实用的技能培训
• 版权所有,欢迎分享本文,转载请保留出处• 若有侵权请联系小麦苗删除
★DB宝分享的IT资料:https://mp.weixin.qq.com/s/Iwsy-zkzwgs8nYkcMz29ag
★DB宝笔试面试详解:https://mp.weixin.qq.com/s/Vm5PqNcDcITkOr9cQg6T7w
长按下图识别二维码或微信扫描下图二维码来关注小麦苗的微信公众号:DB宝,学习最实用的数据库技术。
本文分享自微信公众号 - DB宝(lhrdba)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
来源:oschina
链接:https://my.oschina.net/u/2392483/blog/4359228