环境:
源端: 192.168.11.12 oracle11g单实例 RHEL6
目标端:192.168.166.39 mysql单实例 RHEL6
一:源端oracle ogg安装:
ogg软件下载:http://www.oracle.com/technetwork/cn/middleware/goldengate/downloads/index.html
1.源端目建立表空间和用户:
create tablespace ggs datafile '/data/oradata/mcpdts1/ggs01.dbf' size 200m;
create user ggs identified by ggs default tablespace ggs;
grant resource, connect, dba to ggs;
Oracle 11.1 and 11.2.0.1:
exec dbms_goldengate_auth.grant_admin_privilege('ggs');
grant become user to ggs;
Oracle 11.2.0.2 and later:
exec dbms_goldengate_auth.grant_admin_privilege('ggs');
3.ntp
Oracle ggs 对源端数据的抽取跟时序有依赖,所以在源端为RAC环境的系统,强烈建议在RAC节点间使用NTP进行时钟同步,以减少时序错乱而导致ggs Extract意外停止的风险。
4.数据库归档:
数据库应处于归档模式:
archive log list
归档目录:
RAC各个节点的归档目录在GoldenGate运行实例上是否读。可以通过NFS方式设置。使在goldengate运行节点上可以读到所有节点的归档日志。或将归档目标指向ASM 空间中。如果需要双向复制或反向回切,GoldenGate目标端也同样设置。
打开force logging:
alter database force logging;
5.数据库参数设置:
源主机ORACLE数据库为11.2.0.4或以后的版本,需要设置以下参数:
源端:
alter system set enable_goldengate_replication=true scope=both;
打开源端的补充日志(DBA 执行):
alter database add supplemental log data;
select supplemental_log_data_min from v$database;
注:打开补充日志最好在夜里业务很少的时候进行。如果是RAC 需要在每个节点上都执行。
完成后建议执行一次归档操作:
alter system archive log current;
6.环境变量:
6.1:确保为Oracle和OracleGoldengate运行用户配置动态库路径。确保Oracle数据库的运行库(
6.2:为 GoldenGate 运行用户配置内存限制,将GoldenGate 运行系统用户对内存大小(memory)、文件大小(fsize)、DATA、STACK 等参数的值设置为-1(ulimited),在/etc/security/limits 文件中进行配置。
如果需要双向复制或反向回切,GoldenGate 目标端也同样设置。
6.3:添加oracle用户的环境变量(在生产端和容灾端均要进行以下操作):
export GG_HOME=/apps/ggs
export LD_LIBRARY_PATH=$GG_HOME:$ORACLE_HOME/lib:/usr/bin:/lib
export PATH=$GG_HOME:$PATH
6.4:AIX 系统的特殊要求:
Oracle GoldenGate on AIX 5.3 需要XL C/C++ Runtime v10.1 or later 以及libpthreads version 5.3.0.51 or later,如不符合以上条件需先进行XLC 和libpthreads 库的升级。
注:收集 xlC 和libpthreads 版本,方法如下:
查看 xlC 版本:
# xlC –qversion
Or
# lslpp -l | grep -i xlc
查看libpthreads 版本:
#lslpp -h bos.rte.libpthreads
7.网络设置:
Oracle GoldenGate 只需要复制两端的IP 地址之间能够建立TCP 连接,一个Goldengate 复制链路需要10 个TCP 动态端口,具体端口建议使用7839~7849
8. 操作系统用户:
使用oracle安装、管理GoldenGate。
9.创建文件系统:
为 GoldenGate 创建文件系统,要求:
1、Oracle GoldenGate 安装空间应当全部位于共享阵列;
2、每个数据库对应一个Oracle GoldenGate 安装,如果是一个数据库上有多个Oracle 实例同样安装一套GoldenGate;
3、在阵列上为每个Oracle GoldenGate 安装划分单独空间,所需空间大小可以参照源端数据库每天产生的归档日志量。例如源数据库每天产生150G 归档,则为该数据库对应的Oracle GoldenGate分配150G 空间;建议为Oracle GoldenGate 分配的空间不小于150G 左右。
对于 Unix/Linux 系统:
将所有 Oracle GoldenGate 的文件系统统一挂载到/goldengate点,Oracle GoldenGate 安装位置统一为/goldengate 目录。将/goldengate 及其下目录的Owner 设为Oracle GoldenGate 运行用户。
对于 Windows 系统:建议统一安装到E 盘,推荐采用NTFS文件系统格式,Oracle GoldenGate 统一安装在e:\goldengate目录下
10.GoldenGate源端的安装:
安装 GoldenGate for Oracle x.x 必须遵循以下步骤:
在 RAC 两个节点的任意节点以oracle 身份登录;
运行如下命令完成GoldenGate 的安装:
解压:
[oracle@lddbd app]$ unzip 123012_fbo_ggs_Linux_x64_shiphome.zip
图形化安装:
./runInstaller
静默安装:(修改好oggcore.rsp文件,只需修改:INSTALL_OPTION=ORA11g;SOFTWARE_LOCATION=/u01/app/ogg;START_MANAGER=false)
./runInstaller -ignoreSysPrereqs -silent -responseFile /tmp/fbo_ggs_Linux_x64_shiphome/Disk1/response/oggcore.rsp
此时,GoldenGate 源端产品安装部分已经完成。
11. 创建 GoldenGate 运行时目录:
在安装 GoldenGate 的节点上以oracle 用户身份登录;
在源端执行:
[oracle@BJ-FT-VM-123-15 apps]$ chown -R oracle:oinstall oracle
[oracle@BJ-FT-VM-123-15 apps]$ cd /apps/oracle/ogg
[oracle@BJ-FT-VM-123-15 ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Dec 12 2015 00:54:38
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
创建subdir(此版本不用执行,目录都已经创建好了)
GGSCI (BJ-FT-VM-123-15) 1> create subdirs
Creating subdirectories under current directory /apps/oracle/ogg
Parameter files /apps/oracle/ogg/dirprm: already exists
Report files /apps/oracle/ogg/dirrpt: already exists
Checkpoint files /apps/oracle/ogg/dirchk: already exists
Process status files /apps/oracle/ogg/dirpcs: already exists
SQL script files /apps/oracle/ogg/dirsql: already exists
Database definitions files /apps/oracle/ogg/dirdef: already exists
Extract data files /apps/oracle/ogg/dirdat: already exists
Temporary files /apps/oracle/ogg/dirtmp: already exists
Credential store files /apps/oracle/ogg/dircrd: already exists
Masterkey wallet files /apps/oracle/ogg/dirwlt: already exists
Dump files /apps/oracle/ogg/dirdmp: already exists
各目录用途:
Name Purpose
dirchk Checkpoint files
dirdat GoldenGate trails
dirdef Data definition files
dirprm Parameter files
dirpcs Process status files
dirrpt Report files
dirsql SQL script files
dirtmp Temporary files
二:目标端mysql ogg安装:
下载:http://www.oracle.com/technetwork/cn/middleware/goldengate/downloads/index.html
解压即可使用:
[root@hzdb03 u01]# unzip /u01/app/ogg/123012_ggs_Linux_x64_MySQL_64bit.zip
[root@hzdb03 u01]# mv ggs_Linux_x64_MySQL_64bit.tar /u01/app/ogg
[root@hzdb03 u01]# cd /u01/app/ogg
[root@hzdb03 ogg]# tar -xf ggs_Linux_x64_MySQL_64bit.tar
[root@hzdb03 ogg]# ./ggsci
Oracle GoldenGate Command Interpreter for MySQL
Version 12.3.0.1.2 OGGCORE_12.3.0.1.0_PLATFORMS_171208.0005
Linux, x64, 64bit (optimized), MySQL Enterprise on Dec 8 2017 11:42:23
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
GGSCI (hzdb03) 1> create subdirs
三、配置:
源端:
1.源端使用defgen生成表定义文件,并将定义的文件scp到目标机器的.dirdef目录下:
1.1:
[oracle@lddbd ggs]$ ./ggsci
GGSCI (lddbd) 2> edit params defgen
userid ggs,password ggs
defsfile /u01/app/ggs/dirdef/shop88.def
table shop88.TB_AG003;
table shop88.TB_AG001_BY_DLR_ID;
[oracle@lddbd ggs]$ ./defgen paramfile ./dirprm/defgen.prm
[oracle@lddbd ggs]$ scp ./dirprm/shop88.def 192.168.166.39:/u01/app/ggs/dirdef/
2.源端将需要迁移的表添加trandata,否则update操作有可能出问题:
GGSCI (lddbd) 1> dblogin userid ggs,password ggs
GGSCI (lddbd) 1> add trandata shop88.TB_AG003
GGSCI (lddbd) 1> add trandata shop88.TB_AG001_BY_DLR_ID
3.配置源端mgr参数文件:
GGSCI (lddbd) 1> edit params mgr
PORT 7809
DYNAMICPORTLIST 7810-7909
--AUTOSTART ER *
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
4.配置源端extract参数文件:
GGSCI (lddbd) 1> add extract e1,sourceistable
GGSCI (lddbd) 1> edit params e1
extract e1
setenv (NLS_LANG = "AMERICAN_AMERICA.ZHS16GBK")
setenv (ORACLE_HOME = "/u01/app/oracle/product/11.2/db_1")
setenv (ORACLE_SID = "lddbd")
userid ggs,password ggs
rmthost 192.168.166.39, mgrport 7809
rmttask replicat,group r1
table shop88.TB_AG003;
table shop88.TB_AG001_BY_DLR_ID;
目标端ogg配置:
1.把相应的table和database创建好,注意字段类型长度等,举例:
oracle-->mysql
number-->float
number(7)-->decimal(7,0)
number(7,2)-->decimal(7,2)
varchar2(5)-->varchar(5)
date-->datetime
2.配置mgr参数文件:
GGSCI (hzdb03) 6> edit params mgr
PORT 7809
DYNAMICPORTLIST 7810-7909
--AUTOSTART ER *
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 3
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
ACCESSRULE, PROG *, IPADDR 192.168.*.*, ALLOW
3.配置目标端replication参数文件:
GGSCI (hzdb03) 5> add replicat r1,specialrun #表示只执行一次
GGSCI (hzdb03) 5> edit params r1
replicat r1
sourcecharset ZHS16GBK
setenv (NLS_LANG=AMERICAN_AMERICA.zhs16gbk)
sourcedefs ./dirdef/shop88.def
targetdb jyld,userid root,password passwd
discardfile ./dirrpt/disc,purge
map shop88.TB_AG003, target jyld.tb_ag003 REPERROR (1403, discard);
map shop88.TB_AG001_BY_DLR_ID, target jyld.tb_ag001_by_dlr_id REPERROR (1403, discard);
四、同步数据:
都配置完之后,源端启动extract进程:
[oracle@lddbd ggs]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 23 2012 20:20:21
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
GGSCI (lddbd) 1> start e1
Sending START request to MANAGER ...
EXTRACT E1 starting
源端查看同步日志:
[oracle@lddbd dirrpt]$ tailf /u01/app/ogg/dirrpt/E1.rpt
CACHEMGR virtual memory values (may have been adjusted)
CACHESIZE: 64G
CACHEPAGEOUTSIZE (normal): 8M
PROCESS VM AVAIL FROM OS (min): 128G
CACHESIZEMAX (strict force to disk): 96G
Database Version:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Database Language and Character Set:
NLS_LANG = "AMERICAN_AMERICA.ZHS16GBK"
NLS_LANGUAGE = "AMERICAN"
NLS_TERRITORY = "AMERICA"
NLS_CHARACTERSET = "ZHS16GBK"
Processing table SHOP88.TB_AG003
Processing table SHOP88.TB_AG001_BY_DLR_ID