Docker快速搭建Oracle服务,导入dmp文件
代码审计遇到oracle数据库,记录一下如何快速的搭建,然后导入dmp数据库备份文件
0x01 前置环境
- macos
- Docker
0x02 搭建Oracle服务
1、拉取Oracle镜像
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
2、运行镜像
docker run -p 1521:1521 --name oracle_11g --restart=always -v /Users/zy/Desktop/logs:/home/oracle/app/oracle/oradata/mydata registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
-v /Users/zy/Desktop/logs:/home/oracle/app/oracle/oradata/mydata
前面/Users/zy/Desktop/logs 是物理机器的路径
/home/oracle/app/oracle/oradata/mydata 是docker里面的路径
3、进入容器设置用户信息
docker exec -it oracle_11g bash
4、切换root用户,密码:helowin
[oracle@8a494f051f36 /]$ su
Password:
[root@8a494f051f36 /]#
5、配置oracle环境变量
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
刷新配置
source /etc/profile
创建建立sqlplus软连接
ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
切换到oracle用户
[root@8a494f051f36 /]# exit
exit
[oracle@8a494f051f36 /]$
刷新配置(如果找不到命令,就多刷新配置)
source /etc/profile
登录sqlplus
sqlplus / as sysdba
修改sys和system用户密码
alter user system identified by 123456;
alter user sys identified by 123456;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
连接配置
//创建用户、用户授权
//创建用户
create user test identified by 123456;
//用户授权
grant connect, resource,dba to test;
登陆测试
[oracle@8a494f051f36 /]$ sqlplus
SQL*Plus: Release 11.2.0.1.0 Production on Thu Mar 4 17:03:17 2021
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Enter user-name: test
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
0x03 数据库文件拷
从宿主机拷文件 uc.dmp到容器里面
docker cp /Users/zy/Desktop/dbtemp.dmp oracle_11g:/home
改一下权限
[root@8a494f051f36 home]# chmod 777 temp.dmp
恢复数据库
imp test/123456 file=/home/dbtemp.dmp ignore=y full=y
imp //是oracle自带的导入工具
test/123456 //使用的用户名密码
file=/home/dbtemp.dmp //备份文件路径
ignore=y full=y //模式