一、前言
(1)捕获进程
(2)传输进程
(3)复制进程
二、OGG安装
源端和目标端安装方法相同,注意在使用时源端需要配置数据库开启归档日志。
1. 检查服务器配置:
(1) 主目录存储空间建议不低于500G;
(2) 需开通7809端口;
(3) 需要预先安装java;
2. 下载OGG程序并解压:
# mkdir /opt/ogg # cd /opt/ogg # unzip OGG_BigData_Linux_x64_12.3.2.1.0.zip # tar xf ggs_Adapters_Linux_x64.tar -C /opt/ogg/
3. 配置环境变量:
# vim /etc/profile export OGG_HOME=/opt/ogg export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/amd64:$JAVA_HOME/jre/lib/amd64/server export PATH=$OGG_HOME:$PATH # source /etc/profile
4. 进入GG程序:
# ./ggsci
5. 初始化程序:
GGSCI> create subdirs
6. 配置管理进程:
GGSCI> edit param mgr PORT 7809 DYNAMICPORTLIST 7809-7820 AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3, RESETMINUTES 60 PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 3 ACCESSRULE, PROG *, IPADDR *, PRI 1, ALLOW
7. 启动管理管理进程:
GGSCI> start mgr
8. 检查管理进程启动情况:
GGSCI > info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING
三、源端配置:
1. 查看归档模式是否开启:
$ sqlplus / as sysdba SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /opt/archivelog Oldest online log sequence 7090 Next log sequence to archive 7092 Current log sequence 7092
2. 查看归档日志是否开启:
SQL> select force_logging, supplemental_log_data_min from v$database; FOR SUPPLEME --- -------- YES YES
3. 添加表级附加日志。注①add trandata操作必须在主库上完成;②所有需要监控的表都必须执行该操作。
# ./ggsci GGSCI> dblogin userid [ggadmin]@主库tns, password [ggadmin密码] GGSCI> add trandata [schema].[tablename]
4. 编辑捕获进程参数文件。注①该文件生成后将被放置在ogg主目录下的prm文件夹中。②该文件中的trail文件名xx需确认是否已被使用,如果已被使用,请修改,保证唯一性。
EXTRACT syek DYNAMICRESOLUTION SETENV (ORACLE_SID = "myoracle") SETENV (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK) userid oggadmin, password oggadmin DISCARDFILE ./dirrpt/syek.dsc, APPEND, MEGABYTES 1024 DBOPTIONS ALLOWUNUSEDCOLUMN TRANLOGOPTIONS DBLOGREADER GETUPDATEBEFORES NOCOMPRESSDELETES COMPRESSUPDATES exttrail ./dirdat/sy FETCHOPTIONS NOUSESNAPSHOT GETTRUNCATES table OGG.T_OGG_TEST;
5. 新增捕获进程,注①添加捕获进程,如果是RAC,需要加threads 2。:
GGSCI> add extract syek, tranlog, begin now, threads 2
6. 添加trail文件和捕获进程绑定:
GGSCI> add exttrail ./dirdat/sy, extract syek, megabytes 200
7. 启动捕获进程:
GGSCI> start syek
8. 查看捕获进程是否正常启动:
GGSCI> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING SYEK 00:00:04 00:00:01
9. 编辑传输进程参数文件:
EXTRACT sypk PASSTHRU DYNAMICRESOLUTION RMTHOST 192.168.001.001, MGRPORT 7809, COMPRESS, COMPRESSTHRESHOLD 0 RMTTRAIL ./dirdat/sy table OGG.T_OGG_TEST;
10. 添加本地trail文件和目标端trail文件:
GGSCI> add extract sypk, exttrailsource ./dirdat/sy GGSCI> add rmttrail ./dirdat/sy, extract sypk, megabytes 200
11. 启动传输进程:
GGSCI> start sypk
12. 查看传输进程是否正常启动:
GGSCI> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING SYEK 00:00:04 00:00:01 EXTRACT RUNNING SYPK 00:00:03 00:00:00
四、目标端配置:
1. 配置复制进程参数文件:
GGSCI> edit param syrk REPLICAT syrk TARGETDB LIBFILE libggjava.so SET property=dirprm/kafka.props REPORTCOUNT EVERY 1 MINUTES, RATE GROUPTRANSOPS 10000 MAP OGG.*, TARGET OGG.*, COLMAP(USEDEFAULTS);
2. 创建kafka.props配置文件,注①该文件放在与复制进程同目录下,方便使用:
gg.handlerlist=kafkahandler gg.handler.kafkahandler.type=kafka gg.handler.kafkahandler.KafkaProducerConfigFile=producer.properties gg.handler.kafkahandler.topicMappingTemplate=mytest-topic gg.handler.kafkahandler.format=json gg.handler.kafkahandler.BlockingSend =false gg.handler.kafkahandler.includeTokens=false gg.handler.kafkahandler.mode=op goldengate.userexit.timestamp=utc goldengate.userexit.writers=javawriter javawriter.stats.display=TRUE javawriter.stats.full=TRUE gg.log=log4j gg.log.level=INFO gg.report.time=30sec gg.classpath=*:dirprm/:lib/*:/home/kafka_2.11-2.5.1/libs/* javawriter.bootoptions=-Xmx512m -Xms32m -Djava.class.path=ggjava/ggjava.jar
3. 建producer.properties配置文件:
bootstrap.servers=192.168.001.001:9092,192.168.001.002:9092,192.168.001.003:9092 acks=1 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
4. 添加trail文件:
GGSCI> add replicat syrk, exttrail ./dirdat/sy
5. 启动复制进程:
GGSCI> start syrk
6. 检查复制进程启动情况:
GGSCI> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING REPLICAT RUNNING SYRK 00:00:00 00:00:04