使用docker安装oracle 11gR2实践

今天上午实践了一次使用docker镜像安装oracle的操作,不得不说,过程还是很艰辛的,这里记录一下,以作后续使用。

 

docker版本: 1.17.ce

oracle版本:11.2.0

操作系统版本:ubuntu 16.04LTS

目录

第一步:docker下载镜像

第二步:启动镜像,挂载目录

第三步:进入镜像,删除原实例

第四步:创建新实例 xiuzhu

第④步:创建数据库 xiuzhu

第⑤步:创建数据字典和相关视图

第⑥步:配置监听

第⑦步:重启数据库,重启监听

第⑧步:创建表空间,创建用户

 

第一步:docker下载镜像

docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g (镜像比较大,6.5G,  但是就这也比其它的快呀,下载完成后就能使用,你还犹豫什么~)

第二步:启动镜像,挂载目录

 docker run -d --name oracle_11g -p 1521:1521  -v /iflytek/oracle/oradata/:/home/oracle/app/oracle/oradata/ registry.aliyuncs.com/helowin/oracle_11g

注意挂载端口1521, 监听端口,当然你也可以修改docker镜像, 换成别的端口

第三步:进入镜像,删除原实例

docker exec -it oracle_11g /bin/bash

进入之后,执行如下命令

source /home/oracle/.bash_profile

sqlplus /nolog

connect /as sysdba

shutdown abort (管理oralce进程)

切换至shell , 开启清理之前实例的残留文件

[oracle@f3781c5f2fee dbs]$ find $ORACLE_BASE/ -name $ORACLE_SID
/home/oracle/app/oracle/admin/helowin
/home/oracle/app/oracle/diag/rdbms/helowin
/home/oracle/app/oracle/diag/rdbms/helowin/helowin
/home/oracle/app/oracle/flash_recovery_area/helowin


[oracle@f3781c5f2fee dbs]$ rm -rf /home/oracle/app/oracle/admin/helowin
[oracle@f3781c5f2fee dbs]$ rm -rf /home/oracle/app/oracle/diag/rdbms/helowin
[oracle@f3781c5f2fee dbs]$ rm -rf /home/oracle/app/oracle/diag/rdbms/helowin/helowin
[oracle@f3781c5f2fee dbs]$ rm -rf /home/oracle/app/oracle/flash_recovery_area/helowin

最重要的一步,删除/etc/oratab文件最后一行.

 

 

第四步:创建新实例 xiuzhu

cd $ORACLE_HOME/dbs

cp init.ora initxiuzhu.ora

修改initxiuzhu.ora 如下:

db_name='xiuzhu'
# memory_target=1G docker的memory不允许这个配置,因此务必注释掉,否则实例启动不成功
processes = 150
audit_file_dest='/home/oracle/app/oracle/admin/xiuzhu/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='/home/oracle/app/oracle/flash_recovery_area/xiuzhu'
db_recovery_file_dest_size=2G
diagnostic_dest='/home/oracle/app/oracle'
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
# You may want to ensure that control files are created on separate physical
# devices
control_files = (ora_control1, ora_control2)
compatible ='11.2.0'

修改环境变量:

export ORALCE_SID=xiuzhu

进入oracle shell: 

sqlplus /nolog

connect /as sysdba

执行命令启动实例 startup nomount

 

SQL> startup nomount
ORACLE instance started.

Total System Global Area 217157632 bytes
Fixed Size 2211928 bytes
Variable Size 159387560 bytes
Database Buffers 50331648 bytes
Redo Buffers 5226496 bytes
SQL>
SQL>
SQL>
SQL>
SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
xiuzhu

至此,实例xiuzhu创建成功,记得修改/home/oracle/.bash_profile中实例的变量(ORALCE_SID)

 

第④步:创建数据库 xiuzhu

执行如下命令创建数据库,注意相关路径及数据库名称(数据库名称跟实例名称保持一致)

 

CREATE DATABASE xiuzhu
USER SYS IDENTIFIED BY sys
USER SYSTEM IDENTIFIED BY manager
LOGFILE GROUP 1 ('/home/oracle/app/oracle/oradata/xiuzhu/redo01.log') SIZE 20M,
GROUP 2 ('/home/oracle/app/oracle/oradata/xiuzhu/redo02.log') SIZE 20M,
GROUP 3 ('/home/oracle/app/oracle/oradata/xiuzhu/redo03.log') SIZE 20M
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXLOGHISTORY 1
MAXDATAFILES 100
MAXINSTANCES 1
CHARACTER SET US7ASCII
NATIONAL CHARACTER SET UTF8
DATAFILE '/home/oracle/app/oracle/oradata/xiuzhu/system01.dbf' SIZE 325M REUSE
EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE '/home/oracle/app/oracle/oradata/xiuzhu/sysaux01.dbf' SIZE 325M REUSE
DEFAULT TABLESPACE tbs_1 datafile '/home/oracle/app/oracle/oradata/xiuzhu/tbs_1.dbf' size 50m
DEFAULT TEMPORARY TABLESPACE temp
TEMPFILE '/home/oracle/app/oracle/oradata/xiuzhu/temp01.dbf'
SIZE 20M REUSE
UNDO TABLESPACE undotbs1
DATAFILE '/home/oracle/app/oracle/oradata/xiuzhu/undotbs1.dbf'
SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;


SQL> select name from v$database;

NAME
---------
XIUZHU

 

第⑤步:创建数据字典和相关视图

 

SQL>conn sys as sysdba

SQL>@?/rdbms/admin/catalog.sql;

//此过程可能需要10分钟左右

SQL>@?/rdbms/admin/catproc.sql;

/此过程可能需要15分钟左右

SQL>@?/rdbms/admin/catblock.sql;

SQL>@?/rdbms/admin/catoctk.sql;

SQL>@?/rdbms/admin/owminst.plb;

SQL>conn system/ manager

SQL>@?/sqlplus/admin/pupbld.sql;

SQL>@?/sqlplus/admin/help/hlpbld.sql helpus.sql

 

第⑥步:配置监听

进入$ORACLE_HOME/network/admin

修改tnsnames.ora,添加如下:

 

LISTENER_XIUZHU =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))


xiuzhu =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = xiuzhu)
)
)

 

修改listener.ora,添加如下:

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = 1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = xiuzhu)
(ORACLE_HOME = /home/oracle/app/oracle/product/11.2.0/dbhome_2)
(PROGRAM = extproc)
)
)
ADR_BASE_LISTENER = /home/oracle/app/oracle

第⑦步:重启数据库,重启监听

sqlplus / as sysdba
SQL> shutdown immediate --“关闭数据库实例���
SQL> startup --“启动数据库实例”
SQL>exit
$ lsnrctl stop listener -停止名为listener的监听服务
$ lsnrctl start listener -启动名为listener的监听服务
$ lsnrctl reload listener -重新加载名为listener的监听服务

 

第⑧步:创建表空间,创建用户

 

sqlplus / as sysdba

SQL>create tablespace my_tablespace datafile '/home/oracle/app/oracle/oradata/xiuzhu/my_data.dbf' size 1000M;
SQL>create user xiuzhu identified by QAZ2wsx default tablespace my_tablespace;
SQL>grant connect,resource to xiuzhu;
SQL>grant dba to xiuzhu;

 

第⑨步:登录数据库,自己玩去吧

你可能感兴趣的:(使用docker安装oracle 11gR2实践)