docker安装oracle过程及一些问题

附录 docker容器自启:

docker已启动的情况下:docker update --restart=always oracle

 

第一步 拉取和下载docker镜像


[root@localhost ~]# docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
Using default tag: latest
latest: Pulling from helowin/oracle_11g
ed5542b8e0e1: Pull complete 
a3ed95caeb02: Pull complete 
1e8f80d0799e: Pull complete 
Digest: sha256:4c12b98372dfcbaafcd9564a37c8d91456090a5c6fb07a4ec18270c9d9ef9726
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g:latest

第二步 查看docker中的镜像文件

[root@localhost ~]# docker images
REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZEregistry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g   latest              3fa112fd3642        3 years ago         6.85GB

然后运行镜像

 docker run -d -p 1521:1521 --name oracle registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

第三步 检查容器是否运行成功

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                                      COMMAND                  CREATED              STATUS              PORTS                    NAMES
a151f9478f94        registry.aliyuncs.com/helowin/oracle_11g   "/bin/sh -c '/home/o…"   About a minute ago   Up 30 seconds       0.0.0.0:1521->1521/tcp   oracle

启动oracle

[root@localhost ~]# docker start oracle 

第四步 进入并设置oracle 

  4.1 [root@localhost ~]# docker exec -it oracle bash

  4.2  

  1. [oracle@a151f9478f94 /]$ exit

  2. exit

  3. [root@localhost ~]#

 4.3切换回root用户

编辑环境变量 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

  4.4 使这个配置修改生效

  [root@localhost ~]# source /etc/profile

4.5进入容器(此处的id就是第一个命令下的id),加载一下用户环境变量,进入容器后,自动是oracle用户

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS              PORTS                    NAMES
a151f9478f94        registry.aliyuncs.com/helowin/oracle_11g   "/bin/sh -c '/home/o…"   3 hours ago         Up 3 hours          0.0.0.0:1521->1521/tcp   oracle
 
[root@localhost ~]# docker exec -it a151f9478f94 /bin/bash
[oracle@a151f9478f94 /]$ source ~/.bash_profile
 

[oracle@a151f9478f94 /]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 4 14:44:44 2019
Copyright (c) 1982, 2009, Oracle.  All rights reserved.

 
SQL> conn / as  sysdba                                ## 使用sysdba 连接oracle,最大权限,os认证,只能在本机上登陆使用。
Connected.
SQL> alter user system identified by system;          ## 修改用户 system 的密码为 oracle ,可以自定义
User altered.
SQL> alter user sys identified by sys;
User altered.
SQL> create user ETS identified by ETS;
User created.
SQL> grant connect,resource,dba to ETS ;
Grant succeeded.


SQL> exit      ##退出编辑SQL
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@a151f9478f94 /]$ exit    ##回到root用户
exit
[root@localhost ~]#

上面的步骤都完成后,尝试用plSql连接

ORACLE_DOCKER =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.103)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = helowin)
    )
  )

 连接完成后,会报错,client编码和数据库编码格式不一致?

把oracle数据编码格式

1.cmd

2.输入set ORACLE_SID=你想进入的数据库的那个sid

3.输入 sqlplus /nolog

4.将数据库启动到RESTRICTED模式下做字符集更改: 

SQL> conn /as sysdba 

Connected. 

SQL> shutdown immediate; 

Database closed. 

Database dismounted. 

ORACLE instance shut down. 

SQL> startup mount 

ORACLE instance started. 

Total System Global Area  236000356 bytes 

Fixed Size                   451684 bytes 

Variable Size             201326592 bytes 

Database Buffers           33554432 bytes 

Redo Buffers                 667648 bytes 

Database mounted. 

SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION; 

System altered. 

SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0; 

System altered. 

SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0; 

System altered. 

SQL> alter database open; 

Database altered. 

SQL> ALTER DATABASE CHARACTER SET ZHS16GBK; 

ALTER DATABASE CHARACTER SET ZHS16GBK 

ERROR at line 1: 

ORA-12712: new character set must be a superset of old character set 

 

提示我们的字符集:新字符集必须为旧字符集的超集,这时我们可以跳过超集的检查做更改: 

SQL> ALTER DATABASE character set INTERNAL_USE ZHS16GBK; 

Database altered. 

SQL> select * from v$nls_parameters; 

略 

19 rows selected. 

重启检查是否更改完成: 

SQL> shutdown immediate; 

Database closed. 

Database dismounted. 

ORACLE instance shut down. 

SQL> startup 

ORACLE instance started. 

Total System Global Area  236000356 bytes 

Fixed Size                   451684 bytes 

Variable Size             201326592 bytes 

Database Buffers           33554432 bytes 

Redo Buffers                 667648 bytes 

Database mounted. 

Database opened. 

SQL> select * from v$nls_parameters; 

你可能感兴趣的:(Linux相关,Oracle相关)