项目背景
客户环境和同步需求是:源端oracle11g到目标端SQL Server2019的部分业务表实时同步。在这之前,我们做过SQL Server2012到Oracle11g的同步,本以为直接套用方案即可完成任务,但配置过程异常复杂,主要原因是:目前Oracle官方的ogg版本尚不支持SQL Server2019那么新,最高支持版本是SQL Server2017,为了确保项目的顺利开展,后面与客户协商,将当前数据库降级到SQL SERVER2016 SP2版本,降级后,我们两端都分别选择了OGG的最新版本19C进行安装配置,下面是整个方案的详细配置步骤。
项目详情
服务器信息:
IP地址 | 操作系统 | 数据库版本 | |
源端 | 172.16.0.151 | linux redhat6 x64 | Oracle11.2.0.4 |
目标端 | 172.16.0.152 | windows server 2016 x64 | SQL Server 2016 |
GoldenGate下载地址:
http://www.oracle.com/technetwork/cn/middleware/goldengate/downloads/index.html
https://edelivery.oracle.com/osdc/faces/SearchSoftware
如没有MOS账号,可直接在我方网站下载,地址:
https://dbs-service.cn/a/147.html
本次下载的两个 OGG版本 :
191004_fbo_ggs_Linux_x64_oracle_shiphome.zip
适用于 linux(64 位)上 Oracle11g
19100200204_SQLserver_MSWIN-x86-64.zip
适用于 Windows(64 位)上 SQL 2016
/*####################################################################
Oracle11g 源端配置
#####################################################################*/
源库配置
数据库设置为归档模式
ALTER DATASBASE ARCHIVELOG;
开启强制日志
ALTER DATABASE FORCE LOGGING;
开启附加日志
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
修改参数
ALTER SYSTEM SET ENABLE_GOLDENGATE_REPLICATION=TRUE;
创建用户
–创建用户表空间
create tablespace ogg datafile ‘/u01/app/oracle/oradata/dbbackup/ogg/software.dbf’ size 2G autoextend off;
–创建用户
create user goldengate identified by goldengate;
–添加权限
grant dba to goldengate;
静默安装OGG:
goldengate自12c版本开始也开始采用oui方式进行安装,但是有很多情况下操作系统没有图形化,这种情况下可以采用静默方式安装,具体步骤如下:
1.上传ogg 19C介质
2.解压介质
3.配置自动应答文件
静默安装需要配置一个自动应答文件,位置在刚才解压出来的介质目录中,具体如下:
[oracle@rac1 software]$ cd fbo_ggs_Linux_x64_shiphome/Disk1/response/
[oracle@rac1 response]$ ls
oggcore.rsp
这个oggcore.rsp就是静默安装的配置模板,照着这个模板修改即可。
[oracle@rac1 response]$ cat oggcore.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt_ogginstall_response_schema_v12_1_2
不要修改这个值
################################################################################
## ##
## Oracle GoldenGate installation option and details ##
## ##
################################################################################
#-------------------------------------------------------------------------------
# Specify the installation option.
# Specify ORA12c for installing Oracle GoldenGate for Oracle Database 12c and
# ORA11g for installing Oracle GoldenGate for Oracle Database 11g
#-------------------------------------------------------------------------------
INSTALL_OPTION=ORA11g
根据系统是12c还是11g选择ORA12c或者ORA11g
#-------------------------------------------------------------------------------
# Specify a location to install Oracle GoldenGate
#-------------------------------------------------------------------------------
SOFTWARE_LOCATION=/dbbackup/ogg/software/
写上goldengate的安装目录
#-------------------------------------------------------------------------------
# Specify true to start the manager after installation.
#-------------------------------------------------------------------------------
START_MANAGER=false
是否在配置完成后自动启动mgr进程,是就选true,否就选false
#-------------------------------------------------------------------------------
# Specify a free port within the valid range for the manager process.
# Required only if START_MANAGER is true.
#-------------------------------------------------------------------------------
MANAGER_PORT=
在start_manager为true时添加,选择mgr启动端口号
#-------------------------------------------------------------------------------
# Specify the location of the Oracle Database.
# Required only if START_MANAGER is true.
#-------------------------------------------------------------------------------
DATABASE_LOCATION=
在start_manager为true时添加,写上$ORACLE_HOME的值
################################################################################
## ##
## Specify details to Create inventory for Oracle installs ##
## Required only for the first Oracle product install on a system. ##
## ##
################################################################################
如果在安装goldengate前没有安装过其他Oracle产品再填写以下两个参数
#-------------------------------------------------------------------------------
# Specify the location which holds the install inventory files.
# This is an optional parameter if installing on
# Windows based Operating System.
#-------------------------------------------------------------------------------
INVENTORY_LOCATION=
指定inventory目录的位置,在使用windows操作系统时是一个可选参数。
#-------------------------------------------------------------------------------
# Unix group to be set for the inventory directory.
# This parameter is not applicable if installing on
# Windows based Operating System.
#-------------------------------------------------------------------------------
UNIX_GROUP_NAME=
指定一个组,windows系统时不需要写
4.启动静默安装
./runInstaller -silent -responseFile /dbbackup/ogg/fbo_ggs_Linux_x64_shiphome/Disk1/response/oggcore.rsp
之后开始安装
这时候会提示一个安装日志,
You can find the log of this install session at:
/oracle/app/oraInventory/logs/installActions2016-07-08_11-26-16AM.log
可以使用 tail -100f /oracle/app/oraInventory/logs/installActions2016-07-08_11-26-16AM.log来查看安装情况
安装完成后,安装命令执行页面会输出以下内容:
The installation of Oracle GoldenGate Core was successful.
Please check '/oracle/app/oraInventory/logs/silentInstall2016-07-08_11-26-16AM.log' for more details.
Successfully Setup Software.
5.进入到goldengate目录创建子目录
GGSCI (rac1) 2> create subdirs
Creating subdirectories under current directory /goldengate
Parameter files /goldengate/dirprm: already exists
Report files /goldengate/dirrpt: created
Checkpoint files /goldengate/dirchk: created
Process status files /goldengate/dirpcs: created
SQL script files /goldengate/dirsql: created
Database definitions files /goldengate/dirdef: created
Extract data files /goldengate/dirdat: created
Temporary files /goldengate/dirtmp: created
Credential store files /goldengate/dircrd: created
Masterkey wallet files /goldengate/dirwlt: created
Dump files /goldengate/dirdmp: created
至此goldengate12c静默安装完成
配置MGR进程
GGSCI>edit params mgr
port 7809
DYNAMICPORTLIST 7820-7850
purgeoldextracts /dbbackup/ogg/software/dirdat/e_tab/*,usecheckpoints, minkeepdays 7
创建defgen文件
a.编辑defgen参数
GGSCI> edit params defgen
defsfile /dbbackup/ogg/software/dirdef/tab.def
userid goldengate,password goldengate
table EAS7.CT_DSY_REPORTSYN001;
table EAS7.CT_DSY_REPORTSYN002;
table EAS7.CT_DSY_REPORTSYN003;
table EAS7.CT_DSY_REPORTSYN004;
table EAS7.CT_DSY_REPORTSYN005;
b.生成defgen文件
./defgen paramfile /dbbackup/ogg/software/dirprm/defgen.prm
c.将tab.def复制到目标端dirdef目录下
d.添加表附加日志
GGSCI>dblogin userid goldengate, password goldengate
add trandata EAS7.CT_DSY_REPORTSYN001
add trandata EAS7.CT_DSY_REPORTSYN002
add trandata EAS7.CT_DSY_REPORTSYN003
add trandata EAS7.CT_DSY_REPORTSYN004
add trandata EAS7.CT_DSY_REPORTSYN005
配置抽取进程
a.创建trail文件目录
mkdir -p /dbbackup/ogg/software/dirdat/e_tab
b.添加抽取进程
GGSCI>add extract e_tab,tranlog,threads 2,begin now
GGSCI>add exttrail /dbbackup/ogg/software/dirdat/e_tab/ex,extract e_tab,megabytes 200
GGSCI>edit param e_tab
extract e_tab
SETENV (ORACLE_HOME = "/u01/app/oracle/product/11.2.0/db_1")
SETENV (ORACLE_SID = "jyeas1")
SETENV (NLS_LANG = "AMERICAN_CHINA.AL32UTF8")
userid goldengate,password goldengate
exttrail /dbbackup/ogg/software/dirdat/e_tab/ex
TRANLOGOPTIONS DBLOGREADER
EOFDELAYCSECS 50
FLUSHCSECS 50
dynamicresolution
userid goldengate,password goldengate
table EAS7.CT_DSY_REPORTSYN001;
table EAS7.CT_DSY_REPORTSYN002;
table EAS7.CT_DSY_REPORTSYN003;
table EAS7.CT_DSY_REPORTSYN004;
table EAS7.CT_DSY_REPORTSYN005;
配置投递进程
GGSCI >add extract p_tab,EXTTRAILSOURCE /dbbackup/ogg/software/dirdat/e_tab/ex
GGSCI >add rmttrail E:\ogg\software\dirdat\r_tab\re,ext p_tab,megabytes 200
GGSCI >edit param p_tab
extract p_tab
userid goldengate,password goldengate
rmthost 172.16.0.152,mgrport 7809,compress
FLUSHCSECS 40
EOFDELAYCSECS 10
rmttrail E:\ogg\software\dirdat\r_tab\re
table EAS7.CT_DSY_REPORTSYN001;
table EAS7.CT_DSY_REPORTSYN002;
table EAS7.CT_DSY_REPORTSYN003;
table EAS7.CT_DSY_REPORTSYN004;
table EAS7.CT_DSY_REPORTSYN005;
/*####################################################################
SQL Server2016 目标端配置
#####################################################################*/
安装OGG19C软件
安装过程很简单,直接解压即可,这里我们选择了目录E:/OGG/software进行安装,解压后,我们通过
CMD命令行进入安装目录并登陆ggsci
创建OGG各进程目录:create subdirs
登录SQL server数据库创建goldengate用户,用户映射页设置要映射的数据库,并添加db_ower权限:
创建ODBC数据源:
登录OGG模式,编辑GLOBALS
GGSCI >edit param ./GLOBALS
checkpointtable dbo.ckpttab
创建checkpoint表
GGSCI >dblogin sourcedb ogg_odbc userid goldengate password goldengate
GGSCI >add checkpointtable dbo.ckpttab
配置MGR进程
GGSCI >edit params mgr
port 7809
purgeoldextracts E:\OGG\software\dirdat\r_tab\*,usecheckpoints, minkeepdays 7
配置复制进程
a. 创建trail存放目录
E:\OGG\software\dirdat\REMSSQL
在目标端 ./GLOBALS 里面添加
edit params ./GLOBALS
ALLOWOUTPUTDIR E:\OGG\software\dirdat\r_tab
b.添加复制进程
–delete checkpointtable dbo.ckpttab
–delete replicat r_tab
GGSCI >add replicat r_tab,exttrail E:\OGG\software\dirdat\r_tab\re,begin now,checkpointtable dbo.ckpttab
GGSCI >edit param r_tab
replicat r_tab
sourcedefs E:\OGG\software\dirdef\tab.def
targetdb OGG_ODBC userid goldengate , password goldengate
reperror default,discard
discardfile E:\OGG\software\dirrpt\remssql.dsc,append,megabytes 100
HANDLECOLLISIONS
map EAS7.CT_DSY_REPORTSYN001, target dbo.CT_DSY_REPORTSYN001;
map EAS7.CT_DSY_REPORTSYN002, target dbo.CT_DSY_REPORTSYN002;
map EAS7.CT_DSY_REPORTSYN003, target dbo.CT_DSY_REPORTSYN003;
map EAS7.CT_DSY_REPORTSYN004, target dbo.CT_DSY_REPORTSYN004;
map EAS7.CT_DSY_REPORTSYN005, target dbo.CT_DSY_REPORTSYN005;
再次回到ORACLE源端,进行初始化数据
a.在SQLSERVER创建相应表(这一步相对比较繁琐,需要结合Oracle同步的业务表结构进行比较,在MSSQL端创建同样的表结构,注意数据类型的转换)
b.源端导出相应表初始化数据
GGSCI> edit param exinit
SOURCEISTABLE
userid goldengate , password goldengate
rmthost 172.16.0.152, mgrport 7809
RMTFILE e:\ogg\software\dirdat\r_tab\ex,MAXFILES 1024, MEGABYTES 1024
table EAS7.CT_DSY_REPORTSYN001;
table EAS7.CT_DSY_REPORTSYN002;
table EAS7.CT_DSY_REPORTSYN003;
table EAS7.CT_DSY_REPORTSYN004;
table EAS7.CT_DSY_REPORTSYN005;
在源端OGG目录下执行:
$ ./extract paramfile ./dirprm/exinit.prm reportfile ./dirrpt/exinit.rpt
c.启动源端各进程
GGSCI>start *
切换到SQL SERVER目标端: 初始加载配置
GGSCI(MSSQL)> EDIT PARAMS INLOAD
SPECIALRUN
END RUNTIME
targetdb ogg_odbc userid goldengate , password goldengate
EXTFILE E:\OGG\software\dirdat\r_tab\ex
SOURCEDEFS E:\OGG\software\dirdef\tab.def
map EAS7.CT_DSY_REPORTSYN001, target dbo.CT_DSY_REPORTSYN001;
map EAS7.CT_DSY_REPORTSYN002, target dbo.CT_DSY_REPORTSYN002;
map EAS7.CT_DSY_REPORTSYN003, target dbo.CT_DSY_REPORTSYN003;
map EAS7.CT_DSY_REPORTSYN004, target dbo.CT_DSY_REPORTSYN004;
map EAS7.CT_DSY_REPORTSYN005, target dbo.CT_DSY_REPORTSYN005;
目标段导入相应初始化数据并启动进程
进入OGG目录执行:
replicat paramfile ./dirprm/INLOAD.prm reportfile ./dirrpt/INLOAD.rpt
最后启动复制进程即完成任务:
GGSCI>start *
发表评论 取消回复