作者: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邦德 ❤️