使用Oracle GoldenGate同步oracle变化到kafka
1. 版本说明
- Oracle版本:
11.2.0.1.0
- Linux版本:
Centos 7.3
- Oracle GoldenGate版本:
122022_fbo_ggs_Linux_x64_shiphome
- Oracle GoldenGate for Big Data版本:
12.3.2.1.0
- 官方文档地址:https://www.oracle.com/middleware/technologies/goldengate.html
2. Oracle环境准备工作
启动oracle监听器
1
lsnrctl start
sqlplus命令行登录方法
1
sqlplus / as sysdba
查看数据库版本信息
1
select * from v$version;
确认会话时区是否正确(如果是北京时间的话就是+8)
1
2select sessiontimezone from dual;
select tz_offset(sessiontimezone), tz_offset(dbtimezone) from dual;设置时区为北京时间
1
alter database set time_zone='+8:00';
打开控制文件
1
startup mount;
查看语言ogg设置
1
2select * from v$nls_parameters;
select userenv('language') from dual;查看是否归档
1
2
3
4
5
6
7archive log list;
Database log mode No Archive Mode #数据库日志模式 非存档模式
Automatic archival Disabled #自动存档 禁用
Archive destination USE_DB_RECOVERY_FILE_DEST #存档终点 USE_DB_RECOVERY_FILE_DES
Oldest online log sequence 13 #最早的联机日志序列 13
Current log sequence 15 #当前日志序列 15开启数据库日志归档模式
1
alter database archivelog;
调整归档文件大小(为了压测)
1
2
3alter system set db_recovery_file_dest_size = 50g;
alter system set db_recovery_file_dest = '/home/oracle/app/oradata/recovery_area' scope=spfile;查看闪回恢复区的信息
1
show parameter db_recove;
查看当前数据库强制日志模式的状态
1
select force_logging from v$database;
强制记录日志,确保Oracle无论什么操作都进行redo的写入
1
alter database force logging;
打开数据库
1
alter database open;
将OGG绑定到DB中
1
alter system set enable_goldengate_replication=true scope=both;
查看最小补全日志是否已经开启
1
select supplemental_log_data_min FROM v$database;
开启最小补全日志功能
1
alter database add supplemental log data (PRIMARY KEY,UNIQUE) COLUMNS;
查看是否开启ddl记录功能,默认是不开启的
1
show parameter enable_ddl_logging;
开启DDL日志记录功能
1
alter system set ENABLE_DDL_LOGGING=TRUE;
关闭回收站里的每个会话,只适用于当前会话窗口(回收站是数据文件里面的动态参数,需要添加spoce=spfile,重启数据库才能修改成功)
1
alter system SET recyclebin = OFF scope=spfile;
2. 创建表空间和用户
创建namespace
1
create tablespace ogg2 datafile '/home/oracle/app/oradata/ogg/ogg2.dbf' size 100m autoextend on next 10m;
创建用户并指定表空间以及临时表空间
1
create user ogg2 identified by ogg2 default tablespace ogg2 temporary tablespace TEMP quota unlimited on ogg2;
给刚刚创建好的用户授权
1
2
3
4grant dba to ogg2;
grant select any table to ogg2;
GRANT CREATE SESSION TO ogg2;
GRANT connect, resource TO ogg2;
4. OGG的安装与配置-silent
修改oggcore.rsp文件
1
2
3
4
5
6
7
8
9
10vi /home/oracle/app/install/response/oggcore.rsp
#设置ogg对应的数据库版本为11g
INSTALL_OPTION=ORA11g
#设置ogg的安装目录
SOFTWARE_LOCATION=/home/oracle/app/ogg
#设置mgr默认不初始化启动
START_MANAGER=false
#设置组名
UNIX_GROUP_NAME=oinstall静默安装
1
/home/oracle/app/install/runInstaller -silent -responseFile /home/oracle/app/install/response/oggcore.rsp
root用户执行(安装补丁包)
1
2rpm -ivh oracle-instantclient19.3-basic-19.3.0.0.0-1.x86_64.rpm
/home/oracle/app/oracle/product/11.2.0/dbhome_1/lib登录oracle用户,添加环境变量
1
2
3
4
5
6
7export LD_LIBRARY_PATH=/usr/lib/oracle/19.3/client64/lib:$ORACLE_HOME/lib:/usr/lib
source ~/.bash_profile
ln -s /usr/lib/oracle/19.3/client64/lib/libnnz19.so /usr/lib/oracle/19.3/client64/lib/libnnz11.so
#ln -s /usr/lib/oracle/19.3/client64/lib/libociei.so /usr/lib/oracle/19.3/client64/lib/libociei.so
#ln -s /usr/lib/oracle/19.3/client64/lib/libclntsh.so.11.1 $ORACLE_HOME/lib/libclntsh.so.11.1
#ln -s /usr/lib/oracle/19.3/client64/lib/libclntshcore.so $ORACLE_HOME/lib/libclntshcore.so
5. 源端的配置
为11g创建ogg checkpoint需要的表(使用Oracle用户进行操作)
1 | #必须到ogg目录,即与ddl_setup.sql文件同目录下 |
注意:这里如果报错:INITIALSETUP used, but DDLREPLICATION package exists under different schema (OGG)
需要移除之前的设置:
参考文档:https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/uninstall.htm#GIORA466
Log on as the system administrator or as a user with permission to issue Oracle GoldenGate commands and delete files and directories from the operating system.
Run GGSCI from the Oracle GoldenGate directory.
Stop all Oracle GoldenGate processes.
1 STOP ER *Log in to SQL*Plus as a user that has
SYSDBA
privileges.Disconnect all sessions that ever issued DDL, including those of Oracle GoldenGate processes, SQL*Plus, business applications, and any other software that uses Oracle. Otherwise the database might generate an ORA-04021 error.
Run the
ddl_disable
script to disable the DDL trigger.Run the
ddl_remove
script to remove the Oracle GoldenGate DDL trigger, the DDL history and marker tables, and other associated objects. This script produces addl_remove_spool.txt
file that logs the script output and addl_remove_set.txt
file that logs environment settings in case they are needed for debugging.Run the
marker_remove
script to remove the Oracle GoldenGate marker support system. This script produces amarker_remove_spool.txt
file that logs the script output and amarker_remove_set.txt
file that logs environment settings in case they are needed for debugging.
6. 配置EXTRACT抽取脚本
6.1 ggsci初始化
通过ogg命令行模式登录orcl数据库
DBLOGIN USERID ogg2@orcl, PASSWORD ogg2
1
2
3
4
5
- 初始化,创建OGG的子目录
- ```
create subdirs
创建检查点表
add CHECKPOINTTABLE ogg.checkpointtable
1
2
3
4
5
- 编辑mgr
- ```
edit param mgrPORT 7809 --动态端口范围 DYNAMICPORTLIST 7810-7860 --指定在mgr启动时自动启动那些进程 --自动启动所有的EXTRACT进程 AUTOSTART EXTRACT * --指定在mgr可以定时重启那些进程.可以在网络中断等故障恢复后自动重起,避免人工干预 --每隔3分钟尝试启动一次,尝试5次,等待10分钟后再尝试 AUTORESTART EXTRACT *, RETRIES 5, WAITMINUTES 3, RESETMINUTES 10 --定义自动删除过时的队列以节省硬盘空间.本处设置表示对于超过3天的trail文件进行删除。 PURGEOLDEXTRACTS ./dirdat/*, usecheckpoints, minkeepdays 3 --每隔1小时检查一次传输延迟情况 LAGREPORTHOURS 1 --传输延时超过30分钟将写入错误日志 LAGINFOMINUTES 30 --传输延时超过45分钟将写入警告日志 LAGCRITICALMINUTES 45
1
2
3
4
5
- 创建ogg的检查点(checkpoint)表
- ```
ADD CHECKPOINTTABLE ogg.checkpointtable
设置数据库表级补全日志,注意需要在最小补全日志打开的情况下才起作用
add trandata TEST001.* info trandata TEST001.*
1
2
3
4
5
6
7
## 6.2 全量抽取的配置(简易)
编辑全量(init load)抽取进程配置文件
```shell
edit params send
配置全量抽取脚本
1 | --SOURCEISTABLE |
增加send为extract(sourceIsTable全量)类型
1 | ADD EXTRACT send,sourceistable |
6.3增量抽取的配置(较复杂)
编辑增量抽取脚本:exta1
1 | edit params exta1 |
配置脚本:
1 | --指定是EXTRACT类型和名称exta1 |
创建一个新的增量抽取进程,从redo日志中抽取数据
集成抽取(Integrated Capture)模式与传统抽取模式(Classic Capture)间的切换
1 | ADD EXTRACT ext2hd, INTEGRATED TRANLOG, BEGIN NOW |
传统抽取:
1 | add extract exta1, tranlog, begin now |
创建一个抽取进程抽取的数据保存路径并与新建的抽取进程进行关联
注意目录要两个字符
1 | add exttrail ./dirdat/ll, extract exta1, MEGABYTES 200 |
7.目标端BigData的安装配置
7.1.OGG For BigData的安装
将OGG_BigData_Linux_x64_12.3.2.1.0.zip传输到kafka端并解压缩
导入环境变量
1
2
3
4
5
6
7vi /etc/profile
export OGG_HOME=/opt/ogg
export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/amd64:$JAVA_HOME/jre/lib/amd64/server:$JAVA_HOME/jre/lib/amd64/libjsig.so:$JAVA_HOME/jre/lib/amd64/server/libjvm.so:$ORACLE_HOME/lib:$OGG_HOME/lib
export PATH=$OGG_HOME:$PATH
source /etc/profile
7.2.BigData的初始化和接收进程配置
初始化OGG子目录
1 | 执行ggsci命令,进入ogg控制台 |
7.2.1.Mgr进程的配置
1 | edit prarm mgr |
设置接收端的checkpoint
1 | add CHECKPOINTTABLE ogg.checkpointtable |
7.2.2.增量接收脚本的配置
1 | edit params btkfk |
编辑增量接收数据脚本
1 | REPLICAT btkfk |
添加一个回放线程并与源端pump进程传输过来的trail文件关联,并使用checkpoint表确保数据不丢失
1 | add replicat btkfk, exttrail ./dirdat/rr, checkpointtable ogg2.checkpointtable |
7.2.3.启动kafka消费进程消费数据
1 | /opt/confluent/bin/kafka-topics --zookeeper localhost:2181 --list |
7.2.4.全量接收脚本的配置
增加send为extract(sourceIsTable全量)类型
1 | REPLICAT allRe |
添加脚本,bigdata端只运行一次
1 | #SpecialRun表示只运行一次 |
Example说明:
1 | REPLICAT bb |
1 | /opt/confluent/bin/kafka-topics --zookeeper localhost:2181 --list |
8.Ogg12上同时捕获CDB&PDB数据的实践
1 | edit params exta2 |