安装docker

  1. # 首先卸载可能存在的旧版本
  2. sudo apt-get remove docker docker-engine docker-ce docker.io
  3. # 更新apt包索引
  4. sudo apt-get update
  5. # 安装以下包以使apt可以通过HTTPS使用存储库(repository):
  6. sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
  7. # 添加docker清华镜像源的GPG密钥
  8. curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg|sudo apt-key add -
  9. # 设置docker的stable存储库
  10. sudo add-apt-repository "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  11. # 更新apt索引
  12. sudo apt-get update
  13. # 安装最新版本的docker-ce
  14. sudo apt-get install -y docker-ce

创建oracle 11g容器

# 通过阿里云获取oracle 11g的docker镜像
sudo docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

# 将镜像重新命名
sudo docker tag 3fa112fd3642 oracle_11g:11g
sudo docker rmi registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

# 在容器外创建目录用于映射容器内的oracle数据存放目录
sudo mkdir -p /var/docker/oracle/product/11.2.0/dbhome_2

# 创建oracle 11g容器。经测试,如果使用-v将容器内的db_home2映射到容器外面,会导致容器无法正常启动
# 故创建容器时需要将-v以及后面的目录映射去掉
# 映射的三个端口,1521是oracle数据库管理的监听端口,1158是默认实例orcl的企业管理器访问端口
# 5500是实例helowin的企业管理器访问端口
sudo docker run -d -p 1521:1521 -p 1158:1158 -p 5500:5500 --privileged=true --name oracle_11g 3fa112fd3642
# > -v /var/docker/oracle/product/11.2.0/dbhome_2:/home/oracle/app/oracle/product/11.2.0/dbhome_2

oracle 11g容器配置

# 查看容器状态
(base) smallville@d0ma1n:Documents$ sudo docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED      STATUS        PORTS                                       NAMES
c168ed443c7d   3fa112fd3642   "/bin/sh -c '/home/o…"   3 days ago   Up 16 hours   0.0.0.0:1521->1521/tcp, :::1521->1521/tcp   oracle_11g

# 进入容器
(base) smallville@d0ma1n:Documents$ sudo docker exec -it c16 bash
[oracle@c168ed443c7d /]$ 

# 登录数据库
[oracle@c168ed443c7d /]$ sqlplus /nolog
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory

# 切换到root用户下,密码helowin
[oracle@c168ed443c7d /]$ su - root
Password: 
[root@c168ed443c7d ~]# 

# 编辑profile配置文件为oracle添加环境变量,然后使环境变量生效
[root@c168ed443c7d ~]# vi /etc/profile
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
export ORACLE_SID=helowin
export PATH=$ORACLE_HOME/bin:$PATH
[root@c168ed443c7d ~]# source /etc/profile

# 为sqlplus创建软链接
[root@c168ed443c7d ~]# ln -s $ORACLE_HOME/bin/sqlplus /usr/bin

# 使用su - oracle切换到oracle用户
[root@c168ed443c7d ~]# su - oracle

# 再次登录数据库,成功
[oracle@c168ed443c7d ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Fri Aug 20 14:26:31 2021

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

SQL> 

# 登录并修改sys/system用户密码
SQL> conn /as sysdba
Connected.
SQL> alter user system identified by system;

User altered.

SQL> alter user sys identified by sys;

User altered.

# sqlplus中常用快捷键
l    查看sql buffer中的历史sql语句
/ 执行sql buffer中的sql语句
a 在sql buffer中的sql语句后面追加字符串

SQL> select username,account_status from dba_users;

USERNAME               ACCOUNT_STATUS
------------------------------ --------------------------------
MGMT_VIEW               OPEN
SYS                            OPEN
SYSTEM                   OPEN
DBSNMP                   OPEN
SYSMAN                   OPEN
SCOTT                        OPEN
OUTLN                        EXPIRED & LOCKED
FLOWS_FILES             EXPIRED & LOCKED
MDSYS                     EXPIRED & LOCKED
ORDSYS                   EXPIRED & LOCKED
EXFSYS                   EXPIRED & LOCKED
....
36 rows selected.

SQL> l
  1* select username,account_status from dba_users
SQL> a  order by 1;
  1* select username,account_status from dba_users order by 1
SQL> /

USERNAME               ACCOUNT_STATUS
------------------------------ --------------------------------
ANONYMOUS               EXPIRED & LOCKED
APEX_030200             EXPIRED & LOCKED
APEX_PUBLIC_USER     EXPIRED & LOCKED
APPQOSSYS               EXPIRED & LOCKED
BI                       EXPIRED & LOCKED
CTXSYS                   EXPIRED & LOCKED
DBSNMP                   OPEN
DIP                       EXPIRED & LOCKED
EXFSYS                   EXPIRED & LOCKED
FLOWS_FILES             EXPIRED & LOCKED
HR                       EXPIRED & LOCKED
...

企业管理器

oracle 11g没有提供企业管理器客户端,而是提供了一个b/s版本的企业管理器,需要通过浏览器打开。在oracle容器中使用emctl start dbconsole启动企业管理器。

# 启动企业管理器            emctl start dbconsole
# 停止企业管理器       emctl stop dbconsole
# 查看企业管理器状态    emctl status dbconsole

# 首先尝试使用start来启动企业管理器
[oracle@c168ed443c7d ~]$ emctl start dbconsole
Environment variable ORACLE_UNQNAME not defined. Please set ORACLE_UNQNAME to database unique name.

# 出现上面的错误,表示没有设置ORACLE_UNQNAME环境变量,需要切换到root,然后编辑/etc/profile,加入配置
[oracle@c168ed443c7d ~]$ exit           
logout
[root@c168ed443c7d ~]# vi /etc/profile
...
export ORACLE_UNQNAME=helowin

# 再次启动企业管理器
[root@c168ed443c7d ~]# su - oracle
[oracle@c168ed443c7d ~]$ emctl start dbconsole
OC4J Configuration issue. /home/oracle/app/oracle/product/11.2.0/dbhome_2/oc4j/j2ee/OC4J_DBConsole_c168ed443c7d_helowin not found.

# 需要手动配置emctl
[oracle@c1cf707a1ba4 ~]$ emca -config dbcontrol db

STARTED EMCA at Aug 20, 2021 3:47:32 PM
EM Configuration Assistant, Version 11.2.0.0.2 Production
Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Enter the following information:
Database SID: helowin
Listener port number: 1521
Listener ORACLE_HOME [ /home/oracle/app/oracle/product/11.2.0/dbhome_2 ]: 
Password for SYS user:  
Password for DBSNMP user:  
Password for SYSMAN user:  
Email address for notifications (optional): 
Outgoing Mail (SMTP) server for notifications (optional): 
......

***********************************************************
Enterprise Manager configuration completed successfully
FINISHED EMCA at Aug 20, 2021 3:53:07 PM
[oracle@c1cf707a1ba4 ~]$ emctl status dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0 
Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
https://c1cf707a1ba4:5500/em/console/aboutApplication
Oracle Enterprise Manager 11g is running. 
------------------------------------------------------------------
Logs are generated in directory /home/oracle/app/oracle/product/11.2.0/dbhome_2/c1cf707a1ba4_helowin/sysman/log


# 如果创建容器的时候建立了正确的端口映射,可以在物理机浏览器中输入
# https://虚拟机ip:5500/em/console/aboutApplication来访问容器内的oracle企业管理器

企业管理器按钮文本乱码问题

  1. 从windows中获取字体文件simsum.ttcimage.png
  2. 在目录$oracle_home/jdk/jre/lib/fonts中创建fallback文件夹

    [oracle@c1cf707a1ba4 fonts]$ mkdir fallback
    
  3. 将字体文件simsun.ttc拷贝到刚刚创建的fallback目录下,并更改权限为755

    [oracle@c1cf707a1ba4 fonts]$ mv ~/simsun.ttc fallback/
    [oracle@c1cf707a1ba4 fonts]$ cd fallback/
    [oracle@c1cf707a1ba4 fallback]$ chmod 755 simsun.ttf
    
  4. 清理em缓存

    [oracle@c1cf707a1ba4 fallback]$ rm /home/oracle/app/oracle/product/11.2.0/dbhome_2/oc4j/j2ee/oc4j_applications/applications/em/em/cabo/images/cache/zhs/*.gif
    
  5. 重新启动dbconsole ```sql [oracle@c1cf707a1ba4 fallback]$ emctl stop dbconsole Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0 Copyright (c) 1996, 2009 Oracle Corporation. All rights reserved. https://c1cf707a1ba4:5500/em/console/aboutApplication Stopping Oracle Enterprise Manager 11g Database Control … … Stopped. [oracle@c1cf707a1ba4 fallback]$ emctl start dbconsole Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0 Copyright (c) 1996, 2009 Oracle Corporation. All rights reserved. https://c1cf707a1ba4:5500/em/console/aboutApplication Starting Oracle Enterprise Manager 11g Database Control …….. started.


```