如图所示:源端采用Mysql库,目标端采用Oracle库
一、OGG安装配置(源端)
1、OGG下载
https://edelivery.oracle.com/EPD/Download/get_form?egroup_aru_number=14841438
※Mysql to Oracle注意事项※
1. Supported data types for mysql
CHAR DOUBLE TINYTEXT
VARCHAR DATE MEDIUMTEXT
INT TIME LONGTEXT
TINYINT YEAR BLOB
SMALL INT DATETIME TINYBLOB
MEDIUM INT TIMESTAMP MEDIUMBLOB
BIG INT BINARY LONGBLOB
DECIMAL VARBINARY ENUM
FLOAT TEXT BIT(M)
2.Oracle GoldenGate supports InnoDB storage engine for a source MySQL database
goldengate对mysql只支持innodb引擎
所以,在创建mysql端的表的时候,要指定表为innodb引擎。
create table test.test2(id int,name varchar(10)) engine=innodb;
3.【版本问题】当前for mysql版本的ogg11.2.1.0.1,暂不支持mysql
5.0以下,以及mysql 5.6以上。
4.【配置问题】mysql跟oracle的区别是,mysql是靠各个数据库来划分表,而oracle是靠用户来划分表,所以在配置以mysql为源端的时候,
mysql端 [table test.test2] test指的是数据库的名字,但是如果是oracle做源端的时候,test指的就是用户的名字了,这里有所区分。
二、源端mysql库配置
- 创建mysql用户
*********************************************************************************************
注:创建mysql用户的目的是要把goldengate安装到mysql用户下,
否则当ogg读取mysql二进制索引文件
[log-bin-index=/var/lib/mysql/binary-log.index]
的时候没有相关权限。
***********************************************************************************************
创建mysql用户:
groupadd -g 1000 mysql
useradd -u 1000 -g mysql mysql
passwd mysql
密码:mysql
挂载镜像,配置yum源,内容如下:
[myyum]
name=myyum
baseurl=file:///mnt
enabled=1
gpgcheck=1
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7
- 安装mysql数据库(root)
安装mysql:
[root@localhost lib]# yum install -y mariadb*
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb.x86_64.1.5.5.60-1.el7_5 将被 安装
---> 软件包 mariadb-bench.x86_64.1.5.5.60-1.el7_5 将被 安装
---> 软件包 mariadb-devel.x86_64.1.5.5.60-1.el7_5 将被 安装
---> 软件包 mariadb-libs.x86_64.1.5.5.60-1.el7_5 将被 安装
---> 软件包 mariadb-server.x86_64.1.5.5.60-1.el7_5 将被 安装
--> 正在处理依赖关系 perl-DBD-MySQL,它被软件包 1:mariadb-server-5.5.60-1.el7_5.x86_64 需要
---> 软件包 mariadb-test.x86_64.1.5.5.60-1.el7_5 将被 安装
--> 正在检查事务
---> 软件包 perl-DBD-MySQL.x86_64.0.4.023-6.el7 将被 安装
--> 解决依赖关系完成
…………………………………………………………………
…………………………………….省略
已安装:
mariadb.x86_64 1:5.5.60-1.el7_5 mariadb-bench.x86_64 1:5.5.60-1.el7_5
mariadb-devel.x86_64 1:5.5.60-1.el7_5 mariadb-libs.x86_64 1:5.5.60-1.el7_5
mariadb-server.x86_64 1:5.5.60-1.el7_5 mariadb-test.x86_64 1:5.5.60-1.el7_5
作为依赖被安装:
perl-DBD-MySQL.x86_64 0:4.023-6.el7
完毕!
设置root用户登录密码:
[root@localhost lib]# /usr/bin/mysqladmin -u root -h localhost -s var/lib/mysql/mysql.sock password '123'
拷贝初始参数文件/etc下:
[root@mysql2 ~]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
配置参数文件,并开启二进制日志,日志模式为row:
[root@mysql2 ~]#vi /etc/my.cnf
# Replication Master Server (default)
# binary logging is required for replication
#log-bin=mysql-bin
log-bin-index=/var/lib/mysql/bin-log.index
# binary logging format – mixed recommended
binlog_format=row
启动mysql:
查看设置的参数是否生效:
MariaDB [(none)]> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | ON |
+---------------+-------+
1 row in set (0.00 sec)
创建即将同步的表:
查看test2表的属性:
3.安装mysql版本的goldengate
用mysql用户安装ogg:
设置环境变量:
vi .bash_profile
export PATH=/home/mysql/ggs
export LD_LIBRARY_PATH=/home/mysql/ggs
变量生效:
Source . bash_profile
创建安装目录
su - mysql
cd /home/mysql
mkdir ggs
安装ogg:
[root@localhost mysql]# cp /goldengate/ggs_Linux_x64_MySQL_64bit.tar
/home/oracle/ggs
mysql@mysql2
ggs]$ tar -xvf ggs_Linux_x64_MySQL_64bit.tar
[mysql@mysql2 ggs]$ ./ggsci
GGSCI (mysql2) 1> create subdirs
GGSCI (mysql2) 2>dblogin sourcedb test@localhost:3306, userid
root,password 123
如果报错:
2013-08-14 19:53:41WARNING OGG-00769MySQL Login failed: . SQL error (2002). Can’t connect to local
MySQL server through socket ‘/tmp/mysql.sock’ (2).
ERROR: Failed to connect to MySQL database engine for HOST localhost, DATABASE
test, USER root, PORT 3306.
解决办法:
root and mysql user add follow line into .bash_profile
export MYSQL_UNIX_PORT=/var/lib/mysql/mysql.sock
source .bash_profile
GGSCI (ogg) 2> dblogin sourcedb test@localhost:3306,userid root,password 123 Successfully logged into database.
配置mgr: GGSCI (ogg) 3> edit param mgr port 7810 dynamicportlist 7800-8000 autorestart extract *,waitminutes 2,resetminutes 5
GGSCI (ogg) 4> start mgr Manager started. GGSCI (ogg) 5> info mgr Manager is running (IP port ogg.7810).
GGSCI (ogg) 6> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING
配置extract进程组: GGSCI (ogg) 7> edit param ext_1 extract ext_1 setenv (MYSQL_HOME=”/var/lib/mysql”) tranlogoptions altlogdest /var/lib/mysql/log-bin.index sourcedb test@localhost:3306,userid root,password 123 exttrail ./dirdat/e2 dynamicresolution gettruncates table test.test2;
GGSCI (ogg) 11> add extract ext_1,tranlog,begin now EXTRACT added. GGSCI (ogg) 12> add exttrail ./dirdat/e2,extract ext_1 EXTTRAIL added.
配置pump进程组: GGSCI (ogg) 13> edit params pump_1 extract pump_1 rmthost 192.168.1.13,mgrport 7810 rmttrail /goldengate/dirdat/e2 passthru gettruncates table test.test2;
GGSCI (ogg) 14> add extract pump_1,exttrailsource ./dirdat/e2 EXTRACT added.
GGSCI (ogg) 15> add rmttrail /goldengate/dirdat/e2,extract pump_1 RMTTRAIL added.
异构平台配置defgen:
GGSCI (ogg) 16> edit params defgen defsfile ./dirdef/defgen.prm sourcedb test@localhost:3306, userid root,password 123 table test.test2;
[oracle@ogg ogg_ms]$ ./defgen paramfile dirprm/defgen.prm *********************************************************************** Oracle GoldenGate Table Definition Generator for MySQL Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230 Linux, x86, 32bit (optimized), MySQL Enterprise on Apr 23 2012 04:59:19 Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved. Starting at 2014-09-26 16:01:05 *********************************************************************** Operating System Version: Linux Version #1 SMP Wed Sep 1 01:26:34 EDT 2010, Release 2.6.32-71.el6.i686 Node: ogg Machine: i686 soft limit hard limit Address Space Size : unlimited unlimited Heap Size : unlimited unlimited File Size : unlimited unlimited CPU Time : unlimited unlimited Process id: 2606 *********************************************************************** ** Running with the following parameters ** *********************************************************************** defsfile /u01/ogg_ms/dirdef/defgen.prm sourcedb test@localhost:3306, userid root,password ****** table test.test2; Retrieving definition for test.test2 Definitions generated for 1 table in /u01/ogg_ms/dirdef/defgen.prm
传送defgen文件到目标端: [oracle@ogg ogg_ms]$ scp dirdef/defgen.prm oracle@192.168.1.13:/goldengate/dirdef GGSCI (ogg) 5> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING EXTRACT ABENDED EXT_1 00:00:00 00:21:03 EXTRACT RUNNING PUMP_1 00:00:00 00:00:06
启动extract和pump进程: GGSCI (ogg) 6> start extract ext_1 Sending START request to MANAGER ... EXTRACT EXT_1 starting GGSCI (ogg) 7> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EXT_1 00:00:00 00:21:17 EXTRACT RUNNING PUMP_1 00:00:00 00:00:09 |
以下是容易出现的故障,原因是mysql版本不支持row
extract进程启动异常(abended)!
查看日志:
GGSCI (ogg) 36> view ggsevt
2014-09-26 17:24:56 INFO OGG-01053 Oracle GoldenGate Capture for MySQL, ext_1.prm: Recovery completed for target file ./dirdat/e20
00026, at RBA 961.
2014-09-26 17:24:56 INFO OGG-01057 Oracle GoldenGate Capture for MySQL, ext_1.prm: Recovery completed for all targets.
2014-09-26 17:24:56 INFO OGG-00182 Oracle GoldenGate Capture for MySQL, ext_1.prm: VAM API running in single-threaded mode.
2014-09-26 17:24:56 INFO OGG-01515 Oracle GoldenGate Capture for MySQL, ext_1.prm: Positioning to begin time Sep 26, 2014 3:52:01
PM.
2014-09-26 17:24:56 ERROR OGG-00146 Oracle GoldenGate Capture for MySQL, ext_1.prm: VAM function VAMInitialize returned unexpected
result: error 600 - VAM Client Report <CAUSE OF FAILURE : ERROR NO 13 - Failed to access index file : Check File PATH/EXISTENCE/PERMISSI
ONS - /var/lib/mysql/mysql-bin.index
WHEN FAILED : While initializing binary log configuration
WHERE FAILED : MySQLBinLog Reader Module
CONTEXT OF FAILURE : No Information Available!>.
2014-09-26 17:24:56 ERROR OGG-01668 Oracle GoldenGate Capture for MySQL, ext_1.prm: PROCESS ABENDING.
四、目标端ogg配置
配置MGR GGSCI (rh6.cuug.net) 4> edit params mgr port 7810 dynamicportlist 7800-8000 autorestart extract *,waitminutes 2,resetminutes 5 ~ GGSCI (rh6.cuug.net) 5> start mgr Manager started. GGSCI (rh6.cuug.net) 6> info mgr Manager is running (IP port rh6.cuug.net.7810).
配置replicat进程组: [oracle@rh6 ogg]$ ./ggsci Oracle GoldenGate Command Interpreter for Oracle Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO Linux, x86, 32bit (optimized), Oracle 11g on Apr 23 2012 08:09:25 Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved. GGSCI (rh6.cuug.net) 1> GGSCI (rh6.cuug.net) 1> edit param rep_1 replicat rep_1 sourcedefs ./dirdef/defgen.prm userid goldengate,password goldengate reperror default,discard discardfile ./dirrpt/rep_1.dsc,append,megabytes 50 dynamicresolution gettruncates map test.test2, target test.test3;
GGSCI (rh6.cuug.net) 1>add replicat rep_1,exttrail ./dirdat/e2 REPLICAT added.
启动mgr和replicat进程: GGSCI (rh6.cuug.net) 3> start mgr Manager started. GGSCI (rh6.cuug.net) 4> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING REPLICAT STOPPED REP_1 00:00:00 00:00:34
GGSCI (rh6.cuug.net) 5> start replicat rep_1 Sending START request to MANAGER ... REPLICAT REP_1 starting GGSCI (rh6.cuug.net) 6> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING REPLICAT RUNNING REP_1 00:00:00 00:00:00 |
五.进行dml测试
可以分别用不同的用户对源端mysql数据库中 test库下的test2表进行insert、delete、update测试。
查看目标端oracle数据库下的itpux用户下的test3表是否同步成功。
源端insert:
目标端:
源端update:
目标端:
源端truncate(抽取,复制进程添加“gettruncates”参数)
目标端:
测试完毕。