Docker 安装oracle12c容器并创建新用户

Docker 安装oracle12c容器并创建新用户

  1. 下载镜像

    docker pull truevoly/oracle-12c
    
  2. 启动镜像 8080和22端口没有映射出来,有需要自己

    docker run -d -p 8123:1521 -restart=always --privileged=true -v /data/docker/Oracle12c_sichuan:/u01/app/oracle/ --name oracle12c-sichuan truevoly/oracle-12c
    
    • 正常日志

      Database not initialized. Initializing database.
      Starting tnslsnr
      Copying database files
      1% complete
      3% complete
      11% complete
      18% complete
      37% complete
      Creating and starting Oracle instance
      40% complete
      62% complete
      Completing Database Creation
      96% complete
      100% complete
      Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/xe/xe.log" for further details.
      Configuring Apex console
      Database initialized. Please visit http://#containeer:8080/em http://#containeer:8080/apex for extra configuration if needed
      Starting web management console
      PL/SQL procedure successfully completed.
      Starting import from '/docker-entrypoint-initdb.d':
      ls: cannot access /docker-entrypoint-initdb.d/*: No such file or directory
      Import finished
      Database ready to use. Enjoy! ;)
      
    • 启动报错日志

      atabase not initialized. Initializing database.
      Starting tnslsnr
      Cannot create directory "/u01/app/oracle/cfgtoollogs/dbca".
      Unique database identifier check passed.
      Error writing into silent log -- /u01/app/oracle/cfgtoollogs/dbca/silent.log_2023-10-17_03-29-34-AM (No such file or directory)
      /u01/app/oracle/ has enough space. Required space is 6140 MB , available space is 128006 MB.
      File Validations Successful.
      Error writing into silent log -- /u01/app/oracle/cfgtoollogs/dbca/silent.log_2023-10-17_03-29-34-AM (No such file or directory)
      Cannot create directory "/u01/app/oracle/cfgtoollogs/dbca/xe".
      Error writing into silent log -- /u01/app/oracle/cfgtoollogs/dbca/silent.log_2023-10-17_03-29-34-AM (No such file or directory)
      Error in file copy from </u01/app/oracle/cfgtoollogs/dbca/silent.log_2023-10-17_03-29-34-AM> to </u01/app/oracle/cfgtoollogs/dbca/xe.log>
      Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/silent.log_2023-10-17_03-29-34-AM" for further details.
      

      原因 容器没有操作主机文件夹权限

      主机内执行

      chmod -R a+w /data/docker/Oracle12c_sichuan
      
  3. 进入容器内并以dba登录Oracle

    # 进入oracle-12c容器内
    docker exec -it oracle-12c /bin/bash
    # 切换成oracle用户
    su oracle
    # 进入sqlplus
    $ORACLE_HOME/bin/sqlplus / as sysdba
    
  4. 创建表空间及用户和赋权

    # 设置密码有效期为无限制
    # 默认有sys和system两个用户,密码都是oracle,默认的一个SID/服务名是xe
    
    SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
    
    # 解锁system用户
    SQL> alter user SYSTEM account unlock;
    SQL> alter user SYS account unlock;
    
    创建四川表空间
    --表空间
    --不限制表空间大小用:maxsize unlimited
    --限制表空间大小用:maxsize 1024m
    --自动扩充表空间:一次50m 
    --注意表空间名实际会变成大写 SICHUAN_DATA
    create tablespace sichuan_data 
    logging 
    datafile '/u01/app/oracle/oradata/xe/sichuan_data.dbf' 
    size 50m 
    autoextend on 
    next 50m maxsize unlimited
    extent management local;
    
    --创建临时表空间
    create temporary tablespace sichuan_temp 
    tempfile '/u01/app/oracle/oradata/xe/sichuan_temp.dbf' 
    size 50m 
    autoextend on 
    next 50m maxsize unlimited
    extent management local;
    
    
    alter user system identified by "6#rKXq24@1"; 
     alter user sys identified by "6#rKXq24@1"; 
    
    
    # 创建用户
    # 密码带特殊符号 password 需要双引号 "password"
    create user username identified by password;
    
    
    # 依次给各用户赋权
    
    SQL> GRANT ALTER ANY PROCEDURE TO username;
    SQL> GRANT ALTER ANY TABLE TO username;
    SQL> GRANT ALTER ANY TRIGGER TO username;
    SQL> GRANT ALTER ANY TYPE TO username;
    SQL> GRANT CREATE ANY TABLE TO username;
    SQL> GRANT DELETE ANY TABLE TO username;
    SQL> GRANT DROP ANY PROCEDURE TO username;
    SQL> GRANT DROP ANY SEQUENCE TO username;
    SQL> GRANT DROP ANY TABLE TO username;
    SQL> GRANT DROP ANY TRIGGER TO username;
    SQL> GRANT DROP ANY TYPE TO username;
    SQL> GRANT DROP ANY VIEW TO username;
    SQL> GRANT SELECT ANY DICTIONARY TO username;
    SQL> GRANT SELECT ANY SEQUENCE TO username;
    SQL> GRANT SELECT ANY TABLE TO username;
    SQL> GRANT UNDER ANY TABLE TO username;
    SQL> GRANT UNDER ANY TYPE TO username;
    SQL> GRANT UNDER ANY VIEW TO username;
    SQL> GRANT UNLIMITED TABLESPACE TO username;
    SQL> GRANT UPDATE ANY TABLE TO username;
    SQL> GRANT CONNECT TO username;
    SQL> GRANT DBA TO username;
    SQL> GRANT RESOURCE TO username;
    
    
    
    修改用户的默认表空间为sichuan_data:
    SQL> alter user XZXK default tablespace sichuan_data;
    SQL> alter user XZXK_JL default tablespace sichuan_data;
    SQL> alter user ESF default tablespace sichuan_data;
    SQL> alter user DIC default tablespace sichuan_data;
    

你可能感兴趣的:(服务器,docker,docker,容器,运维,oracle)