这篇文章是对
https://blog.csdn.net/kkHMou/article/details/115749725
补充,部分配置直接沿用了这篇文章
下篇文章,StreamSets同步kafka数据至kudu:
https://blog.csdn.net/kkHMou/article/details/116931422
oracle ogg官方最新版本为19.1,旧版本需要到oracle云下载:
https://edelivery.oracle.com/osdc/faces/SoftwareDelivery
组件:
软件 | 版本 |
---|---|
CentOS | CentOS 7.5 |
JAVA | 1.8 |
源端Oracle | 11g for linux |
源端Ogg | 12.2.02 for oracle on linux |
目标端Ogg | 12.2.01 big data |
kafka | kafka_2.12-2.00 |
名词解释
OGG Manager用于配置和管理其它OGG组件,配置数据抽取、数据推送、数据复制,启动和停止相关组件,查看相关组件的运行情况。
抽取源端数据库的变更(DML, DDL)。数据抽取主要分如下几种类型:
本地抽取
从本地数据库捕获增量变更数据,写入到本地Trail文件
数据推送(Data Pump)
从本地Trail文件读取数据,推送到目标端。
初始数据抽取
从数据库表中导出全量数据,用于初次数据加载
Data Pump是一种特殊的数据抽取(Extract)类型,从本地Trail文件中读取数据,并通过网络将数据发送到目标端OGG
数据抽取从源端数据库抓取到的事物变更信息会写入到Trail文件。
数据接收程序运行在目标端机器,用于接收Data Pump发送过来的Trail日志,并将数据写入到本地Trail文件。
数据复制运行在目标端机器,从Trail文件读取数据变更,并将变更数据应用到目标端数据存储系统。本案例中,数据复制将数据推送到kafka消息队列。
检查点用于记录数据库事物变更。
linux.x64_11gR2_database_1of2.zip
linux.x64_11gR2_database_2of2.zip
切到oracle用户
sqlplus / as sysdba
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 22
Current log sequence 24
如果是Disable,则打开
#立即关闭数据库
shutdown immediate
#启动实例并加载数据库
startup mount
#更改数据库为归档模式
alter database archivelog
#打开数据库
alter database open
#启用自动归档
alter system archive log start
再执行一下
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 22
Next log sequence to archive 24
Current log sequence 24
已经是Enabled,说明归档模式已打开
select force_logging, supplemental_log_data_min from v$database;
FORCE_ SUPPLEMENTAL_LOG
------ ----------------
NO NO
若都为No,则进行修改
#强制日志
alter database force logging;
#附加日志
alter database add supplemental log data;
然后再查看一下
SQL> select force_logging, supplemental_log_data_min from v$database;
FOR SUPPLEME
--- --------
YES YES
说明补充日志打开成功
创建GoldenGate表空间
可以通过此命令查看当前的表空间和位置
select tablespace_name,file_id,bytes/1024/1024,file_name from dba_data_files order by file_id;
create tablespace ogg_data datafile '/app/ora/oracle/oradata/orcl/ogg01.dbf' size 1000M autoextend on;
创建用户并赋权
create user ogg identified by ogg default tablespace ogg_data;
grant connect,resource,dba,create table,create sequence to ogg;
这里是root用户
V861007-01.zip
mkdir /app/ogg
cd /app/ogg
unzip V861007-01.zip
chown -R oracle:oinstall /app/ogg
这里切换到oracle用户
sudo su oracle
cd /app/ogg/fbo_ggs_Linux_x64_shiphome/Disk1/response
修改参数,这里修改好了,供参考
[oracle@master response]$ grep -Ev "^$|[#;]" oggcore.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt_ogginstall_response_schema_v19_1_0
INSTALL_OPTION=ORA11g
SOFTWARE_LOCATION=/app/ogg
START_MANAGER=
MANAGER_PORT=
DATABASE_LOCATION=/app/ora/oracle/product/11.2.0
INVENTORY_LOCATION=/app/ora/oraInventory
UNIX_GROUP_NAME=oinstall
修改完成执行静默安装
cd /app/ogg/fbo_ggs_Linux_x64_shiphome/Disk1
./runInstaller -silent -nowait -responseFile /app/ogg/fbo_ggs_Linux_x64_shiphome/Disk1/response/oggcore.rsp
注意:如果有报错
[FATAL] [INS-75012] Software Location specified is already an existing Oracle home and does not contain the selected Oracle Golden Gate install type
因为此前这台机器安装过ogg19,这次安装ogg12需要更改oracle一项配置
vim /app/ora/oraInventory/ContentsXML/inventory.xml
cd /app/ogg/fbo_ggs_Linux_x64_shiphome/Disk1
./runInstaller -silent -nowait -responseFile /app/ogg/fbo_ggs_Linux_x64_shiphome/Disk1/response/oggcore.rsp
添加环境变量
vim /home/oracle/.bash_profile
增加:
export OGG_HOME=/app/ogg
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$OGG_HOME:$PATH
使变量生效:
source /home/oracle/.bash_profile
初始化
ggsci
如果这里提示:
[oracle@master ogg]$ ggsci
ggsci: error while loading shared libraries: libnnz11.so: cannot open shared object file: No such file or directory
请检查你的环境变量有没有配置:LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
上一步正常运行ggsci应该是下面这样
[oracle@master ogg]$ ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 19.1.0.0.4 OGGCORE_19.1.0.0.0_PLATFORMS_191017.1054_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Oct 17 2019 23:13:12
Operating system character set identified as US-ASCII.
Copyright (C) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
GGSCI (mirror-node1) 1>
创建目录
GGSCI (master) 1> create subdirs
Creating subdirectories under current directory /app/ogg
Parameter file /app/ogg/dirprm: created.
Report file /app/ogg/dirrpt: created.
Checkpoint file /app/ogg/dirchk: created.
Process status files /app/ogg/dirpcs: created.
SQL script files /app/ogg/dirsql: created.
Database definitions files /app/ogg/dirdef: created.
Extract data files /app/ogg/dirdat: created.
Temporary files /app/ogg/dirtmp: created.
Credential store files /app/ogg/dircrd: created.
Masterkey wallet files /app/ogg/dirwlt: created.
Dump files /app/ogg/dirdmp: created.
GGSCI (master) 2>
kafka_2.12-2.0.0.tar.gz
zookeeper-3.4.13.tar.gz
V100447-01.zip
这里是root用户
新建ogg_home:
cd /app
mkdir ogg
将ogg目标端文件上传至 /app/ogg目录下:
cd /app/pgg
V100447-01.zip
解压完生成3个文件:
ggs_Adapters_Linux_x64.tar
OGG_BigData_12.2.0.1.0_Release_Notes.pdf
OGG_BigData_12.2.0.1_README.txt
对 ggs_Adapters_Linux_x64.tar 再解压:
tar xvf ggs_Adapters_Linux_x64.tar
vim /vim /etc/profile
export OGG_HOME=/app/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:$OGG_HOME/lib
export PATH=$OGG_HOME:$PATH
source /etc/profile
上一步环境变量如果生效了。
ggsci
GGSCI (kafka) 1> create subdirs
这里是oracle用户
注意:这里除了mgr名称是固定属性,其余进程名都可以自定义,建议在配置过程中将进程名记录在别的文档中,以免忘记。
GGSCI (master) 1> edit params mgr
GGSCI (master) 2> view param mgr
PORT 7809
DYNAMICPORTLIST 7810-7909
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 3
PORT即mgr的默认监听端口;
DYNAMICPORTLIST动态端口列表,当指定的mgr端口不可用时,会在这个端口列表中选择一个,最大指定范围为256个;
AUTORESTART重启参数设置表示重启所有EXTRACT进程,最多5次,每次间隔3分钟;
PURGEOLDEXTRACTS即TRAIL文件的定期清理
查看mgr状态:
GGSCI (master) 3> start mgr
Manager started.
GGSCI (master) 4> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
GGSCI (master) 5> sh netstat -ntpl | grep 7809
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::7809 :::* LISTEN 13666/./mgr
如果出现:
MANAGER STOPPED
使用:view report mgr
查看mgr报错
GGSCI (master) 6> dblogin userid ogg,password ogg
Successfully logged into database.
GGSCI (master as ogg@ORCL) 7> add trandata test_ogg.test_ogg
如果需要添加整个库,可以使用 add trandata test_ogg.*
说明添加复制表成功
GGSCI (master as ogg@ORCL) 8> info trandata test_ogg.test_ogg
Logging of supplemental redo log data is enabled for table TEST_OGG.TEST_OGG.
Columns supplementally logged for table TEST_OGG.TEST_OGG: ID.
Prepared CSN for table TEST_OGG.TEST_OGG: 2590115
GGSCI (master as ogg@ORCL) 9> edit params extkaf01
EXTRACT extkaf01
DYNAMICRESOLUTION
SETENV (NLS_LANG= "AMERICAN_AMERICA.AL32UTF8")
SETENV (ORACLE_SID = "orcl")
USERID ogg, PASSWORD ogg
EXTTRAIL /app/ogg/dirdat/to
GETUPDATEBEFORES
NOCOMPRESSDELETES
NOCOMPRESSUPDATES
TABLE test_ogg.test_ogg;
第一行指定extract进程名称,注意不能超过8个字符(ERROR: Invalid group name (must be at most 8 characters).);
DYNAMICRESOLUTION 动态解析;
SETENV设置数据库环境变量,SID注意大小写;
userid ggs,password ggs即OGG连接Oracle数据库的帐号密码;
exttrail定义trail文件的保存位置以及文件名,注意这里文件名只能是2个字母,其余部分OGG会补齐;
table即复制表的表名,支持*通配,必须以 ; 结尾;
添加extract进程:
GGSCI (master as ogg@ORCL) 10> add extract extkaf01,tranlog,begin now
EXTRACT added.
添加trail文件的定义与extract进程绑定:
GGSCI (master as ogg@ORCL) 11> add exttrail /app/ogg/dirdat/to,extract extkaf01
EXTTRAIL added.
pump进程本质上来说也是一个extract,只不过他的作用仅仅是把trail文件传递到目标端,配置过程和extract进程类似
GGSCI (master as ogg@ORCL) 12> edit param pukaf01
EXTRACT pukaf01
PASSTHRU
DYNAMICRESOLUTION
userid ogg,password ogg
RMTHOST 192.168.10.180 MGRPORT 7809
RMTTRAIL /app/ogg/dirdat/to
TABLE test_ogg.test_ogg;
第一行指定extract进程名称;
passthru即禁止OGG与Oracle交互,我们这里使用pump逻辑传输,禁止即可;
dynamicresolution动态解析;
userid ogg,password ogg即OGG连接Oracle数据库的帐号密码
rmthost和mgrhost即目标端(kafka)OGG的mgr服务的地址以及监听端口;
rmttrail即目标端trail文件存储位置以及名称。
分别将本地trail文件和目标端的trail文件绑定到extract进程:
GGSCI (master as ogg@ORCL) 13> add extract pukaf01,exttrailsource /app/ogg/dirdat/to
EXTRACT added.
GGSCI (master as ogg@ORCL) 14> add rmttrail /app/ogg/dirdat/to,extract pukaf01
RMTTRAIL added.
Oracle与MySQL,Hadoop集群(HDFS,Hive,kafka等)等之间数据传输可以定义为异构数据类型的传输,需要定义表之间的关系映射。
在OGG命令行执行:
GGSCI (master as ogg@ORCL) 15> edit param ogg_test
defsfile /app/ogg/dirdef/test_ogg.test_ogg
userid ogg,password ogg
table test_ogg.test_ogg;
新开窗口,在OGG_HOME目录下执行,注意这里是使用oracle用户:
[oracle@master ogg]$ ./defgen paramfile dirprm/ogg_test.prm
***********************************************************************
Oracle GoldenGate Table Definition Generator for Oracle
Version 19.1.0.0.4 OGGCORE_19.1.0.0.0_PLATFORMS_191017.1054
Linux, x64, 64bit (optimized), Oracle 11g on Oct 17 2019 14:27:47
Copyright (C) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
Starting at 2021-04-21 10:28:43
***********************************************************************
Operating System Version:
Linux
Version #1 SMP Fri Dec 18 16:34:56 UTC 2020, Release 3.10.0-1160.11.1.el7.x86_64
Node: mirror-node1
Machine: x86_64
soft limit hard limit
Address Space Size : unlimited unlimited
Heap Size : unlimited unlimited
File Size : unlimited unlimited
CPU Time : unlimited unlimited
Process id: 26393
***********************************************************************
** Running with the following parameters **
***********************************************************************
defsfile /app/ogg/dirdef/test_ogg.test_ogg
userid ogg,password ***
table test_ogg.test_ogg;
Retrieving definition for TEST_OGG.TEST_OGG.
Definitions generated for 1 table in /app/ogg/dirdef/test_ogg.test_ogg.
将生成的 /app/ogg/dirdef/test_ogg.test_ogg 发送的目标端kafka机器ogg目录下的dirdef里:
scp -r /app/ogg/dirdef/test_ogg.test_ogg [email protected]:/app/ogg/dirdef/
注意:这里除了mgr名称是固定属性,其余进程名都可以自定义,建议在配置过程中将进程名记录在别的文档中,以免忘记。
GGSCI (kafka) 1> create subdirs
GGSCI (kafka) 2> edit param mgr
PORT 7809
DYNAMICPORTLIST 7810-7909
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 3
checkpoint即复制可追溯的一个偏移量记录,在全局配置里添加checkpoint表:
GGSCI (kafka) 1> edit param ./GLOBALS
CHECKPOINTTABLE OGG.checkpoint
GGSCI (kafka) 2> edit param rekaf01
REPLICAT rekaf01
sourcedefs /app/ogg/dirdef/test_ogg.test_ogg
TARGETDB LIBFILE libggjava.so SET property=dirprm/kafka01.props
REPORTCOUNT EVERY 1 MINUTES, RATE
GROUPTRANSOPS 10000
MAP test_ogg.test_ogg, TARGET test_ogg.test_ogg;
REPLICATE 定义rep进程名称;
sourcedefs 是在源端服务器上做的表映射文件;
TARGETDB LIBFILE即定义kafka一些适配性的库文件以及配置文件,配置文件位于OGG主目录下的dirprm/kafka01.props (需要自己编辑生成);
REPORTCOUNT即复制任务的报告生成频率;
GROUPTRANSOPS为以事务传输时,事务合并的单位,减少IO操作;
MAP即源端与目标端的映射关系;
cd /app/ogg/dirprm
vim kafka01.props
#handler类型
gg.handlerlist=kafkahandler
gg.handler.kafkahandler.type=kafka
#kafka相关配置
gg.handler.kafkahandler.KafkaProducerConfigFile=custom_kafka_producer_01.properties
#kafka的topic
gg.handler.kafkahandler.topicName=test_oracle_ogg_kafka_01
#传输文件的格式,支持json,xml等
gg.handler.kafkahandler.format=json
#OGG for Big Data中传输模式,即op为一次SQL传输一次,tx为一次事务传输一次
gg.handler.kafkahandler.mode=op
gg.classpath=dirprm/:/app/soft/kafka_2.12-2.0.0/libs/*:/app/ogg/:/app/ogg/lib/*
注:如果有报错提示为:Unable to set property on handler ‘kafkahandler’ + topicName:=“test_oracle_ogg_kafka_01”
将kafka配置修改为:gg.handler.kafkahandler.topicMappingTemplate=
vim custom_kafka_producer_01.properties
#kafka 地址
bootstrap.servers=192.168.10.180:9092
acks=1
#压缩类型
compression.type=gzip
#重连延迟
reconnect.backoff.ms=1000
value.serializer=org.apache.kafka.common.serialization.ByteArraySerializer
key.serializer=org.apache.kafka.common.serialization.ByteArraySerializer
batch.size=102400
linger.ms=10000
添加trail文件到replicate进程:
GGSCI (kafka) 2> add replicat rekaf01 exttrail /app/ogg/dirdat/to,checkpointtable OGG.checkpoint
REPLICAT added.
在源端和目标端的OGG命令行下使用start [进程名]的形式启动所有进程。
启动顺序按照源mgr——目标mgr——源extract——源pump——目标replicate来完成。
全部需要在ogg目录下执行ggsci目录进入ogg命令行。
注意启动的用户!!!
注意启动ggsci必须是在$OGG_HOME目录下!!!
源端启动命令:
start mgr
start extkaf01
start pukaf01
目标端启动命令:
start mgr
start rekaf01
这里我直接用Navicat连接oracle写数据
用kafka tool软件查看kafka数据
可以看数据是正常写入到kafka
如果报错提示为:
[FATAL] [INS-75012] Software Location specified is already an existing Oracle home and does not contain the selected Oracle Golden Gate install type
因为此前这台机器安装过ogg19,这次安装ogg12需要更改oracle一项配置
vim /app/ora/oraInventory/ContentsXML/inventory.xml
GGSCI (master) 16> view report EXTKAF01
发现报错提示为:
2021-05-10 09:42:22 ERROR OGG-00664 OCI Error beginning session (status = 1034-ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory).
2021-05-10 09:42:22 ERROR OGG-01668 PROCESS ABENDING.
原因:由于ogg连接不上数据库导致
可能原因有:
1、Extract 配置中有关ORACLE配置有问题,例如SID、用户名密码等等
查看SID命令:echo $ORACLE_SID
2、重启数据库,一般情况不会是oracle问题
切换oracle用户
sudo su oracle
查看监听
lsnrctl status
连接
sqlplus / as sysdba
关闭数据库
shutdown immediate
关闭监听
lsnrctl stop
启动监听
lsnrctl start
sqlplus / as sysdba
启动数据库
startup
在目标端机器(kafka)上,ggserr.log 文件可以看到每一步执行的日志,
如果kafka提示:
Unable to set property on handler ‘kafkahandler’ (oracle.goldengate.handler.kafka.KafkaHandler). Failed to set property: topicMappingTemplate:=“test_oracle_ogg_kafka_01” (class: oracle.goldengate.handler.kafka.KafkaHandler).
将kafka01.props配置中:
gg.handler.kafkahandler.topicMappingTemplate=test_oracle_ogg_kafka_01
改为:gg.handler.kafkahandler.topicName=test_oracle_ogg_kafka_01
这是由于kafka版本导致的问题,反之亦然