LINUX下ADG+LVM+DOCKER
框架原理:
1.利用adg方式将基础库的数据同步到测试库所在的服务器上
2.在测试库所在的服务器上将adg备库数据文件目录利用lvm快照备份
3.利用docker挂在目录方式,将lvm快照备份卷挂在到container里,并启动数据
4.利用shell脚本来自动化这个过程
(因为资源问题,整个测试过程在一台pc机器完成,仅供参考)
一、oracle ADG实现
1.网络参数配置
[oracle@mzhang admin]$ more listener.ora # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER_STDDG1 = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = stddg1) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1) (SID_NAME = stddg1))) SID_LIST_LISTENER_DG1 = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = dg1) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1) (SID_NAME = dg1))) LISTENER_STDDG1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = mzhang)(PORT = 1522))) ADR_BASE_LISTENER_STDDG1 = /u01/app/oracle LISTENER_DG1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = mzhang)(PORT = 1521))) ADR_BASE_LISTENER_DG1 = /u01/app/oracle [oracle@mzhang admin]$ more tnsnames.ora dg1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mzhang)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = dg1))) stddg1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mzhang)(PORT = 1522))) (CONNECT_DATA = (SERVICE_NAME = stddg1))) lsnrctl start listener_dg1 lsnrctl start listener_stddg1
2.主库参数配置
alter system set log_archive_config='dg_config=(dg1,stddg1)'; alter system set log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=dg1'; alter system set log_archive_dest_2='SERVICE=stddg1 ASYNC db_unique_name=stddg1 valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE)'; alter database force logging; alter database add standby logfile ('/oradata/datafile/dg1/std_redo01.log') size 50m; alter database add standby logfile ('/oradata/datafile/dg1/std_redo02.log') size 50m; alter database add standby logfile ('/oradata/datafile/dg1/std_redo03.log') size 50m; alter database add standby logfile ('/oradata/datafile/dg1/std_redo04.log') size 50m;
3.备库参数配置
a.密码文件 orapwd file=orapwstddg1 entries=10 force=y ignorecase=y password=oracle b.参数文件 [oracle@mzhang dbs]$ more initstddg1.ora db_unique_name=stddg1 db_name=dg1 db_block_size=8192 control_files='/oradata2/datafile/ctl01.ctl' log_archive_config='DG_CONFIG=(dg1,stddg1)' db_file_name_convert='/oradata/datafile/dg1','/oradata2/datafile/stddg1' log_file_name_convert='/oradata/datafile/dg1','/oradata2/datafile/stddg1' standby_file_management='AUTO' compatible='11.2.0.4.0' log_archive_max_processes=4 remote_login_passwordfile='EXCLUSIVE' fal_server=dg1 db_recovery_file_dest='/oradata2/arc' db_recovery_file_dest_size=5218762752 c.duplicate database rman target sys/oracle@dg1 axuiliary sys/oracle@stddg1 duplicate target database for standby from active database; alter database recover managed standby database cancel; alter database recover managed standby database disconnect from session;
二、LVM快照备份还原
1.查看lv vg信息 [root@mzhang /]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert LogVol01 vg_mzhang -wi-ao---- 58.59g LogVol02 vg_mzhang -wi-ao---- 97.66g LogVol03 vg_mzhang -wi-ao---- 8.00g LogVol04 vg_mzhang -wi-ao---- 90.00g LogVolroot vg_mzhang -wi-ao---- 58.59g [root@mzhang /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_mzhang-LogVolroot 58G 9.3G 46G 17% / tmpfs 3.9G 320K 3.9G 1% /dev/shm /dev/sda1 283M 58M 207M 22% /boot /dev/mapper/vg_mzhang-LogVol02 96G 2.3G 89G 3% /oradata /dev/mapper/vg_mzhang-LogVol01 58G 4.4G 51G 8% /u01 /dev/sr0 4.2G 4.2G 0 100% /media/CentOS_6.5_Final /dev/mapper/vg_mzhang-LogVol04 89G 1.9G 83G 3% /oradata2 [root@mzhang /]# vgs VG #PV #LV #SN Attr VSize VFree vg_mzhang 1 5 0 wz--n- 465.46g 152.62g 2.首先停止备库,针对逻辑卷LogVol04进行snapshot备份 SQL> alter database recover managed standby database cancel; SQL> shutdown immediate; [root@mzhang /]# lvcreate -L 50GB -s -n LogVol05_snap /dev/vg_mzhang/LogVol04 Logical volume "LogVol05_snap" created [root@mzhang /]# mount /dev/vg_mzhang/LogVol05_snap /mnt [root@mzhang /]# df -h |grep mnt /dev/mapper/vg_mzhang-LogVol05_snap 89G 1.9G 83G 3% /mnt
三、DOCKER来创建oracle container
1、docker信息 [root@mzhang mnt]# docker version Client version: 1.7.1 Client API version: 1.19 Go version (client): go1.4.2 Git commit (client): 786b29d/1.7.1 OS/Arch (client): linux/amd64 Server version: 1.7.1l Server API version: 1.19 Go version (server): go1.4.2 Git commit (server): 786b29d/1.7.1 OS/Arch (server): linux/amd64 [root@mzhang mnt]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE oraclelinux latest 90a41cef53ee 5 days ago 225.3 MB 2、创建container docker run -dti --name oracl1 --privileged=true -v /proc:/container_proc -v /mnt:/oradata2 oraclelinux /bin/bash docker run -dti --name oracl2 --privileged=true mzhang/oraclelinux2 /bin/bash docker run -dti --name oracl3 --privileged=true -v /mnt:/oradata2 mzhang/oraclelinux2 /bin/bash a.container里安装数据库软件(-ignorePrereq) ./runInstaller -silent -force -ignorePrereq -responseFile /tmp/database/response/db_install.rsp b.copy备库的密码文件及参数文件到容器中的相关目录下 c.启动container中数据库 SQL> startup mount; ORACLE instance started. Total System Global Area 263090176 bytes Fixed Size 2252256 bytes Variable Size 205521440 bytes Database Buffers 50331648 bytes Redo Buffers 4984832 bytes Database mounted. SQL> alter database activate standby database; SQL> alter database open; SQL> select open_mode,name from v$database; OPEN_MODE NAME -------------------- --------- READ WRITE DG1 3.做个参数配置完毕,rpm包安装完毕,只安装oracle软件的images docker commit 79b74f8553ee mzhang/oraclelinux2
如果要做多个容器,需要做多个lvm snapshot。