linux下通过docker部署安装oracle完整操作(oracle19c和oracle12c)

时间:2024-10-13 07:21:38

一、安装oracle19c

1、拉取镜像

docker pull /zhuyijun/oracle:19c

2、启动容器

  1. docker run -p 1521:1521 -p 5500:5500 \
  2. --name oracle1 \
  3. --net=host \
  4. -e ORACLE_SID=orcl \
  5. -e ORACLE_PDB=orclpdb1 \
  6. -e ORACLE_PWD=123456 \
  7. -e ORACLE_CHARACTERSET=zhs16gbk \
  8. -e ORACLE_HOME=/opt/oracle/product/19c/dbhome_1 \
  9. -e PATH=/opt/oracle/product/19c/dbhome_1/bin:/opt/oracle/product/19c/dbhome_1/OPatch/:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
  10. -v /data/oracle/oradata:/opt/oracle/oradata \
  11. /zhuyijun/oracle:19c

注意:其中/data/oracle/oradata是宿主机上的挂载路径。

如果启动失败,会显示

这个时候就要分析原因。我是因为忘记给挂载的目录赋予写权限,导致一直失败。这个地方要注意。

# 记得给挂载路径赋予权限

chmod -R a+x+w+r  /data/oracle/oradata

如果启动失败,会留下容器进程,而且容器名字不能重复,可以用这个命令批量删除启动失败的进程。

docker rm  $(docker ps -a | grep oracle | awk '{print $1}')

成功输出:

3、这时先不要关闭终端,另外开启一个终端,进入环境修改oracle密码

docker exec oracle1 ./ 123456

修改完密码后可以关闭之前终端了,出现 DATABASE IS READY TO USE之后,后边都是显示的日志,可以关闭终端,关闭终端不会导致它停止运行。

4、进入容器

  1. docker ps | grep oracle
  2. 5bb11ac3efc7 /zhuyijun/oracle:19c "/bin/sh -c 'exec $O…" 28 minutes ago Up 28 minutes (healthy) oracle1
  3. [root@feature-platform-001 ORCL]# docker exec -it oracle1 /bin/bash
  4. sh-4.2$
  5. 输入
  6. sqlplus / as sysdba;

如果你使用成功,那么恭喜你。这篇文章到此为止。

然而我这里遇到些问题,startup也会报错,好像和我的某个系统参数设置有关,懒得解决了,打算换个oracle12c。

  1. SQL> select * from v$log;
  2. select * from v$log
  3. *
  4. ERROR at line 1:
  5. ORA-01034: ORACLE not available
  6. Process ID: 0
  7. Session ID: 0 Serial number: 0

二、安装oracle12c

下载镜像

docker pull /truevoly/oracle-12c

建立挂载目录

mkdir /data/oracle/data_temp  && chmod 777 /data/oracle/data_temp

运行镜像

docker run --restart always -d -p 8080:8080 -p 1521:1521 -v /data/oracle/data_temp:/home/oracle/data_temp   -v /etc/localtime:/etc/localtime:ro  --name oracle12c truevoly/oracle-12c

查看日志:

  1. [root@feature-platform-001 ~]# docker logs -f c81d10c1006827f4b5e0acbbba566210f5e5fa4a7d6fd7b791b1cad5d0ae8963
  2. Database not initialized. Initializing database.
  3. Starting tnslsnr
  4. Copying database files
  5. 1% complete
  6. 3% complete
  7. 11% complete
  8. 18% complete
  9. 37% complete
  10. Creating and starting Oracle instance
  11. 40% complete
  12. 45% complete
  13. 50% complete
  14. 55% complete
  15. 56% complete
  16. 60% complete
  17. 62% complete
  18. Completing Database Creation
  19. 66% complete
  20. 70% complete
  21. 73% complete
  22. 85% complete
  23. 96% complete
  24. 100% complete
  25. Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/xe/" for further details.
  26. Configuring Apex console
  27. PL/SQL procedure successfully completed.
  28. Starting import from '/':
  29. ls: cannot access //*: No such file or directory
  30. Import finished
  31. Database ready to use. Enjoy! ;)

进入容器

  1. [root@feature-platform-001 ~]# docker ps | grep oracle
  2. c81d10c10068        truevoly/oracle-12c                    "/ "        7 minutes ago       Up 7 minutes        0.0.0.0:1521->1521/tcp, 0.0.0.0:18080->8080/tcp   oracle12c
  3. [root@feature-platform-001 ~]# docker exec -it c81d10c10068 /bin/bash
  4. root@c81d10c10068:/# sqlplus /nolog
  5. SQL*Plus: Release 12.1.0.2.0 Production on Thu Sep 16 14:58:34 2021
  6. Copyright (c) 1982, 2014, Oracle.  All rights reserved.
  7. SQL> connect sys as sysdba
  8. Enter password: oracle
  9. Connected.
  10. SQL>
  11. SQL> select status from v$instance;
  12. STATUS
  13. ------------
  14. OPEN
  15. SQL> alter user system identified by 123456;          
  16. User altered.

创建用户

  1. create user 账户 identified by 密码;
  2. GRANT CONNECT, RESOURCE, DBA TO wcz;

查询数据库名称

  1. SQL> select value from v$parameter where name='service_names';
  2. VALUE
  3. --------------------------------------------------------------------------------
  4. xe

连接信息:

账号:wcz

密码:123456

端口:1521

服务名称:xe

常用操作:

  1. --首先查询一下用户的profile的类型
  2. select username ,profile from dba_users;
  3. --查看制定概要文件(默认为DEFAULT)的密码有效期:
  4. select  * from dba_profiles where profile='DEFAULT' and resource_name='PASSWORD_LIFE_TIME';
  5. --然后将密码的有效期有180天设置为“无限制”;
  6. ALTER PROFILE  DEFAULT  LIMIT PASSWORD_LIFE_TIME UNLIMITED;
  7. -- 修改密码
  8. alter user hysjy identified by 123456;
  9. -- 查询所有用户
  10. SELECT * FROM ALL_USERS;
  11. -- 创建账户
  12. create user hysjy identified by 123456;
  13. GRANT CONNECT, RESOURCE, DBA TO hysjy;
  14. --  给用户授予权限
  15. grant create session to hysjy;
  16. grant connect,resource to hysjy;
  17. -- 解除锁定
  18. alter user hysjy account unlock;
  19. commit;