netnr/ docker-oracle.sh 2020-08-21 11:12
基于 docker 快速安装 oracle
wget -qO- get.docker.com | bash # 一键安装 docker 容器
systemctl start docker  # 启动服务

docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:2.0
docker run -itd --restart=always --name lhrora11204 -h lhrora11204 --shm-size=1G -p 1521:1521 --privileged=true lhrbest/oracle_11g_ee_lhr_11.2.0.4:2.0 init
docker exec -it lhrora11204 bash # 进入容器
su - oracle
lsnrctl start
sqlplus / as sysdba
startup
exit
lsnrctl status

# 连接字符串
# Server Name / SID: LHR11G
# 账号密码 sys/lhr

# 进入容器 oracle 用户配置开机启动
echo $ORACLE_HOME # 查看路径
vi /etc/oratab # 修改为末尾为 Y ,LHR11G:/u01/app/oracle/product/11.2.0.4/dbhome_1:Y
vi $ORACLE_HOME/bin/dbstart # ORACLE_HOME_LISTNER=$1 改为 ORACLE_HOME_LISTNER=$ORACLE_HOME
# 切回容器 root 配置开机脚本
vi /etc/rc.d/rc.local # 加入以下启动脚本
su - oracle -c "/u01/app/oracle/product/11.2.0.4/dbhome_1/bin/lsnrctl start"
su - oracle -c "/u01/app/oracle/product/11.2.0.4/dbhome_1/bin/dbstart"
# su - oracle -c "/u01/app/oracle/product/11.2.0.4/dbhome_1/bin/emctl start dbconsole"
chmod 755 /etc/rc.d/rc.local # 赋予 rc.loacl 执行权限

# 启动错误 "ORA-03113: end-of-file on communication channel" on startup
# https://dba.stackexchange.com/questions/49682
$ sqlplus /nolog
SQL> connect / as sysdba
SQL> startup mount
SQL> alter system set db_recovery_file_dest_size = 75G scope=both


docker pull loliconneko/oracle-ee-11g # 镜像
docker run -d -p 8080:8080 -p 1521:1521 --restart=always --name oracle11 loliconneko/oracle-ee-11g # 启动 oracle
docker run -d -p 8080:8080 -p 1521:1521 --restart=always --name oracle11 --shm-size=1G -v /package/oracle:/u01/app/oracle loliconneko/oracle-ee-11g # 启动 oracle 指定路径
docker logs -f oracle11 # 查看输出日志

# 连接字符串
# hostname: localhost
# port: 1521
# sid: EE
# service name: EE.oracle.docker
# username: system
# password: oracle


docker run -d --shm-size 2GB -p 1524:1521 --restart=always --name oracle12 fluigfws/oracle12c # 12C xe

select * from global_name; -- 查看服务名(service name)

# 建表空间、用户
https://www.netnr.com/gist/code/4871611063472502154

# help
https://hub.docker.com/r/loliconneko/oracle-ee-11g


# 修改 Docker 容器内的时间 ,进入容器后执行:
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo "Asia/Shanghai" > /etc/timezone

docker exec -it oracle11 /bin/bash # 进入正在运行的某个容器
docker exec -it oracle11 /bin/bash -c "sqlplus sys/oracle as sysdba" # 宿主执行命令

# Oracle 11g 修改字符集 为 ZHS16GBK
sqlplus sys/oracle as sysdba; # sqlplus "用户/密码 as sysdba"
shutdown immediate;
startup mount;
ALTER SYSTEM ENABLE RESTRICTED SESSION;
ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
ALTER SYSTEM SET AQ_TM_PROCESSES=0;
alter database open;
ALTER DATABASE CHARACTER SET ZHS16GBK;

# ORA-12712: new character set must be a superset of old character set
# 提示我们的字符集:新字符集必须为旧字符集的超集,这时我们可以跳过超集的检查做更改:
ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
# 查询字符集
SELECT VALUE FROM Nls_Database_Parameters WHERE PARAMETER = 'NLS_CHARACTERSET';
select userenv('language') from dual;

# 修改最大连接数,查询:
select value from v$parameter where name = 'processes';
select value from v$parameter where name = 'sessions';
# 或者:终端执行
show parameter processes;
show parameter sessions

# 修改连接数(sessions=1.1*process+5)
alter system set processes = 1000 scope = spfile;
alter system set sessions=1105 scope=spfile;

# 启动服务
shutdown immediate;
startup;
# 重置SGA_TARGET
# ORA-00821
create spfile from pfile;
startup
# ORA-00093
exit
sqlplus/as sysdba
startup


# 变更存档模式,在 mount 实例中且数据库处于非 open 状态
# 查询数据库状态
select status from v$instance;
# 关闭数据库
shutdown immediate;
# 启动 mount 实例
startup mount;

# 改为非存档模式
alter database noarchivelog;

# 修改系统的日志方式为存档模式
alter system set log_archive_start=true scope=spfile;
# 改为存档模式
alter database archivelog;

# 查看存档模式
archive log list;
# 打开数据库
alter database open;

# 清理存档日志 ORA-00257
rman target /
delete archivelog all;
# 查看归档路径及大小限制
show parameter recover;

# help
https://www.linuxidc.com/linux/2013-01/78286.htm
https://blog.csdn.net/ilifei/article/details/94129307
https://mp.weixin.qq.com/s/xet_HIUXSja5egI4OAPb-w