继上篇 docker系列7:使用nginx 反向代理docker-mysql,安装好mysql后, 继续搭建oracle环境,流程如下:
1, client —> 远程windows服务器:1521 —> 虚拟机的oracle:1521
2, 虚拟机的oracle:1521----> docker-oracle容器:1521
最终: client ----> 远程windows服务器的虚拟机的docker-oracle容器:1521
镜像
用户登录
helowin/oracle_11g
sid: helowin, system/helowin
sath89/oracle-12c
sid: xe, system/oracle
1, 安装 helowin/oracle_11g
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
docker tag registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g oracle_11g
docker rmi registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
docker run -d -p 1521:1521 --name oracle_11g oracle_11g
#数据持久化:
# docker volume create oracle-11g
# docker run -d -p 1521:1521 --name oracle_11g -v oracle-11g:/home/oracle/app/oracle/data/ oracle_11g
#====默认配置如下
#hostname: localhost
#port: 1521
#sid: helowin
#username: system
#password: helowin
docker exec -it oracle_11g bash
su root # 密码: helowin
#====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
ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
#====登录oracle数据库 ,修改密码
su oracle ;
sqlplus
# username: system
# password: helowin
alter user system identified by oracle;
alter user sys identified by oracle;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
exit #退出oracle 命令行
exit; # 退出容器
#===使用navicat 登录oracle
hostname: localhost
port: 1521
sid: helowin
username: system
password: oracle
2, 配置nginx: 反向代理oracle服务
编辑nginx.conf, 配置反向代理,使得外网可以访问服务器内部的服务
# nginx 反向代理
stream {
upstream mysql{
hash $remote_addr consistent;
server 192.168.99.101:3306 max_fails=3 fail_timeout=30s;
}
upstream oracle{
hash $remote_addr consistent;
server 192.168.99.101:1521 max_fails=3 fail_timeout=30s;
}
server {
listen 3306;
proxy_connect_timeout 3000s;
proxy_timeout 6000s;
proxy_pass mysql3;
}
server {
listen 1521;
proxy_connect_timeout 3000s;
proxy_timeout 6000s;
proxy_pass oracle;
}
}
# http { ... }
3, oracle 语法
#1,使用system用户登陆,创建普通用户
create user test identified by 123456;
grant connect,dba to test;
#2,使用普通用户登陆,创建表,插入数据
--查询数据库名, 表名
-- select name from v$database;
-- select table_name from all_tables -- where table_name like '%PER' ; --where ROWNUM <10 ;
--===================================
--创建表
-- create table per(id int, name varchar(10));
--增加数据【两种方式, insert into /insert all into ..into ..select ..】
-- insert into per(id,name) values(1 ,'a');
-- insert all into per values( 2,'b')
-- into per values (3,'c')
-- select 1 from dual;
--删除数据
-- delete from per where id=1;
--修改数据
--update per set name='c2' where id=3;
--查询表数据
-- select * from per;