Oracle GoldenGate 之--异构平台同步(Mysql到Oracle)

电玩女神 2022-08-17 15:19 288阅读 0赞

Oracle GoldenGate 异构平台同步(Mysql到Oracle)

wKiom1QlL0ODAhNWAAFaapV-AeY413.jpg

如图所示:源端采用Mysql库,目标端采用Oracle库

一、OGG安装配置(源端)

1、OGG下载

https://edelivery.oracle.com/EPD/Download/get_form?egroup_aru_number=14841438

wKiom1QlMAaxj0tFAAN-tUXU3d8212.jpg

https://edelivery.oracle.com/EPD/Download/get_form?egroup_aru_number=14841440

wKiom1QlL-jg9cRiAALo7IeF6zA121.jpg

[oracle@ogg ogg_ms]$ uname -a

Linux ogg 2.6.32-71.el6.i686 #1 SMP Wed Sep 1 01:26:34 EDT 2010 i686 i686 i386 GNU/Linux

  1. [oracle@ogg ~]$ cd /u01/ogg_ms/
  2. [oracle@ogg ogg_ms]$ ls
  3. ggs_Linux_x86_MySQL_32bit.tar
  4. [oracle@ogg ogg_ms]$ tar xvf ggs_Linux_x86_MySQL_32bit.tar
  5. [oracle@ogg ogg_ms]$ ./ggsci
  6. Oracle GoldenGate Command Interpreter for MySQL
  7. Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230
  8. Linux, x86, 32bit (optimized), MySQL Enterprise on Apr 23 2012 04:29:30
  9. Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
  10. GGSCI (ogg) 1> create subdirs
  11. Creating subdirectories under current directory /u01/ogg_ms
  12. Parameter files /u01/ogg_ms/dirprm: already exists
  13. Report files /u01/ogg_ms/dirrpt: created
  14. Checkpoint files /u01/ogg_ms/dirchk: created
  15. Process status files /u01/ogg_ms/dirpcs: created
  16. SQL script files /u01/ogg_ms/dirsql: created
  17. Database definitions files /u01/ogg_ms/dirdef: created
  18. Extract data files /u01/ogg_ms/dirdat: created
  19. Temporary files /u01/ogg_ms/dirtmp: created
  20. Stdout files /u01/ogg_ms/dirout: created

二、数据库配置

源端:mysql库配置

  1. 数据库配置文件:
  2. [root@ogg ~]# cat /etc/my.cnf
  3. # Replication Master Server (default)
  4. # binary logging is required for replication
  5. log-bin=mysql-bin
  6. # binary logging format - mixed recommended
  7. #binlog_format=mixed
  8. binlog_format=row
  9. 启动数据库服务
  10. [root@ogg ~]# service mysql start
  11. Starting MySQL
  12. 连接数据库 [ OK ]
  13. [root@ogg ~]# mysql -h localhost -u mysql -p
  14. Enter password:
  15. Welcome to the MySQL monitor. Commands end with ; or \g.
  16. Your MySQL connection id is 1
  17. Server version: 5.6.4-m7-log Source distribution
  18. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  19. This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  20. and you are welcome to modify and redistribute it under the GPL v2 license
  21. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  22. mysql> show databases;
  23. +--------------------+
  24. | Database |
  25. +--------------------+
  26. | information_schema |
  27. | mysql |
  28. | performance_schema |
  29. | test |
  30. +--------------------+
  31. 4 rows in set (0.00 sec)
  32. mysql> use test;
  33. Database changed
  34. mysql> show tables;
  35. Empty set (0.00 sec)
  36. 创建测试表(存储引擎采用innodb
  37. mysql> create table test2 (id int,name char(10)) engine=innodb;
  38. Query OK, 0 rows affected (0.02 sec)
  39. mysql> show tables;
  40. +----------------+
  41. | Tables_in_test |
  42. +----------------+
  43. | test2 |
  44. +----------------+
  45. 1 row in set (0.00 sec)
  46. mysql> select * from test2;
  47. Empty set (0.00 sec)

目标端:Oracle 库配置:

[java] view plain copy print ?

  1. 16:06:46 SYS@ prod >create user test identified by test ;
  2. User created.
  3. 16:08:05 SYS@ prod >grant connect,resource to test;
  4. Grant succeeded.
  5. 16:08:12 SYS@ prod >conn test/test
  6. Connected.
  7. 16:08:18 TEST@ prod >create table test2 (id int,name varchar2(10));
  8. Table created.

三、OGG同步配置

源端:Mysql库配置

[oracle@ogg ogg_ms]$ ./ggsci

  1. Oracle GoldenGate Command Interpreter for MySQL
  2. Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230
  3. Linux, x86, 32bit (optimized), MySQL Enterprise on Apr 23 2012 04:29:30
  4. Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
  5. 用户登录(root):
  6. GGSCI (ogg) 2> dblogin sourcedb test@localhost:3306,userid root,password oracle
  7. Successfully logged into database.
  8. 配置mgr
  9. GGSCI (ogg) 3> edit param mgr
  10. port 7809
  11. dynamicportlist 7800-8000
  12. autorestart extract *,waitminutes 2,resetminutes 5
  13. GGSCI (ogg) 4> start mgr
  14. Manager started.
  15. GGSCI (ogg) 5> info mgr
  16. Manager is running (IP port ogg.7809).
  17. GGSCI (ogg) 6> info all
  18. Program Status Group Lag at Chkpt Time Since Chkpt
  19. MANAGER RUNNING
  20. 配置extract进程组:
  21. GGSCI (ogg) 7> edit param ext_1
  22. extract ext_1
  23. setenv (MYSQL_HOME=”/var/lib/mysql”)
  24. tranlogoptions altlogdest /var/lib/mysql/mysql-bin.index
  25. sourcedb test@localhost:3306,userid root,password oracle
  26. exttrail ./dirdat/e2
  27. dynamicresolution
  28. gettruncates
  29. table test.test2;
  30. GGSCI (ogg) 11> add extract ext_1,tranlog,begin now
  31. EXTRACT added.
  32. GGSCI (ogg) 12> add exttrail ./dirdat/e2,extract ext_1
  33. EXTTRAIL added.
  34. 配置pump进程组:
  35. GGSCI (ogg) 13> edit params pump_1
  36. extract pump_1
  37. rmthost 192.168.8.249,mgrport 7809
  38. rmttrail /u01/ogg/dirdat/e2
  39. passthru
  40. gettruncates
  41. table test.test2;
  42. GGSCI (ogg) 14> add extract pump_1,exttrailsource ./dirdat/e2
  43. EXTRACT added.
  44. GGSCI (ogg) 15> add rmttrail /u01/ogg/dirdat/e2,extract pump_1
  45. RMTTRAIL added.
  46. 异构平台配置defgen
  47. GGSCI (ogg) 16> edit params defgen
  48. defsfile /u01/ogg_ms/dirdef/defgen.prm
  49. sourcedb test@localhost:3306, userid root,password oracle
  50. table test.test2;
  51. [oracle@ogg ogg_ms]$ ./defgen paramfile dirprm/defgen.prm
  52. ***********************************************************************
  53. Oracle GoldenGate Table Definition Generator for MySQL
  54. Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230
  55. Linux, x86, 32bit (optimized), MySQL Enterprise on Apr 23 2012 04:59:19
  56. Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
  57. Starting at 2014-09-26 16:01:05
  58. ***********************************************************************
  59. Operating System Version:
  60. Linux
  61. Version #1 SMP Wed Sep 1 01:26:34 EDT 2010, Release 2.6.32-71.el6.i686
  62. Node: ogg
  63. Machine: i686
  64. soft limit hard limit
  65. Address Space Size : unlimited unlimited
  66. Heap Size : unlimited unlimited
  67. File Size : unlimited unlimited
  68. CPU Time : unlimited unlimited
  69. Process id: 2606
  70. ***********************************************************************
  71. ** Running with the following parameters **
  72. ***********************************************************************
  73. defsfile /u01/ogg_ms/dirdef/defgen.prm
  74. sourcedb test@localhost:3306, userid root,password ******
  75. table test.test2;
  76. Retrieving definition for test.test2
  77. Definitions generated for 1 table in /u01/ogg_ms/dirdef/defgen.prm
  78. 传送defgen文件到目标端:
  79. [oracle@ogg ogg_ms]$ scp dirdef/defgen.prm rh6:/u01/ogg/dirdef
  80. GGSCI (ogg) 5> info all
  81. Program Status Group Lag at Chkpt Time Since Chkpt
  82. MANAGER RUNNING
  83. EXTRACT ABENDED EXT_1 00:00:00 00:21:03
  84. EXTRACT RUNNING PUMP_1 00:00:00 00:00:06
  85. 启动extractpump进程:
  86. GGSCI (ogg) 6> start extract ext_1
  87. Sending START request to MANAGER ...
  88. EXTRACT EXT_1 starting
  89. GGSCI (ogg) 7> info all
  90. Program Status Group Lag at Chkpt Time Since Chkpt
  91. MANAGER RUNNING
  92. EXTRACT ABENDED EXT_1 00:00:00 00:21:17
  93. EXTRACT RUNNING PUMP_1 00:00:00 00:00:09

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.

附录:解决方法(参考网络文档)

GoldenGate的官方文档明确表示,GoldenGate需要将MySQL的日志格式(binlog_format)设置为ROW,其他两种格式(MIXED or STATEMENT)是不支持。

########################################################################官方描述如下

binlog_format: This parameter sets the format of the logs. It must be set to the value of ROW, which directs the database to log DML statements in binary format. Any other log format (MIXED or STATEMENT) causes Extract to abend.

########################################################################

但是MySQL在版本5.1.5之前是不支持ROW和MIXED格式(MySQL 5.1.5引入ROW,5.1.8引入MIXED)

#### 官方描述如下:http://dev.mysql.com/doc/refman/5.1/en/binary-log-formats.html

Support for row-based logging was added in MySQL 5.1.5. Mixed logging is available beginning with MySQL 5.1.8. In MySQL 5.1.12,MIXED become the default logging mode; in 5.1.29, the default was changed back to STATEMENT for compatibility with MySQL 5.0.

########################################################################

目前客户的MySQL版本是5.0.6-beta版:

D:\MySQL Server 5.0\bin>mysql -u root -p

Enter password: *****

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 111 to server version: 5.0.6-beta-nt-log

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the buffer.

mysql> select version();

+—————————-+

| version() |

+—————————-+

| 5.0.6-beta-nt-log|

+—————————-+

1 row in set (0.02 sec)

这个版本是不支持binlog_format=ROW,所以安装好GolenGate后,启动抽取进程时,进程abend

########################################################################下面是出错信息:

2014-09-16 16:55:16 ERROR OGG-00146 VAM function VAMRead returned unexpected result: error 600 - VAM Client Report <CAUSE OF FAILURE : STATEMENT or MIXED level logging found so abending

WHEN FAILED : While reading log event from binary log

WHERE FAILED : MySQLBinLog Reader Module

CONTEXT OF FAILURE : No Information Available!>

因此如果想要采用GoldenGate来实现MySQL的数据实时同步,需要将MySQL版本升级到5.1.5以上.

四、目标端ogg配置

  1. 配置MGR
  2. GGSCI (rh6.cuug.net) 4> edit params mgr
  3. port 7809
  4. dynamicportlist 7800-8000
  5. autorestart extract *,waitminutes 2,resetminutes 5
  6. ~
  7. GGSCI (rh6.cuug.net) 5> start mgr
  8. Manager started.
  9. GGSCI (rh6.cuug.net) 6> info mgr
  10. Manager is running (IP port rh6.cuug.net.7809).
  11. 配置replicat进程组:
  12. [oracle@rh6 ogg]$ ./ggsci
  13. Oracle GoldenGate Command Interpreter for Oracle
  14. Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
  15. Linux, x86, 32bit (optimized), Oracle 11g on Apr 23 2012 08:09:25
  16. Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
  17. GGSCI (rh6.cuug.net) 1>
  18. GGSCI (rh6.cuug.net) 1> edit param rep_1
  19. replicat rep_1
  20. sourcedefs /u01/ogg/dirdef/defgen.prm
  21. userid ogg,password ogg
  22. reperror default,discard
  23. discardfile /u01/ogg/dirrpt/rep_1.dsc,append,megabytes 50
  24. dynamicresolution
  25. map test.test2, target test.test2;
  26. GGSCI (rh6.cuug.net) 1> add replicat rep_1,exttrail /u01/ogg/dirdat/e2
  27. REPLICAT added.
  28. 启动mgrreplicat进程:
  29. GGSCI (rh6.cuug.net) 3> start mgr
  30. Manager started.
  31. GGSCI (rh6.cuug.net) 4> info all
  32. Program Status Group Lag at Chkpt Time Since Chkpt
  33. MANAGER RUNNING
  34. REPLICAT STOPPED REP_1 00:00:00 00:00:34
  35. REPLICAT ABENDED RORA_1 00:00:00 383:08:47
  36. GGSCI (rh6.cuug.net) 5> start replicat rep_1
  37. Sending START request to MANAGER ...
  38. REPLICAT REP_1 starting
  39. GGSCI (rh6.cuug.net) 6> info all
  40. Program Status Group Lag at Chkpt Time Since Chkpt
  41. MANAGER RUNNING
  42. REPLICAT RUNNING REP_1 00:00:00 00:00:00

由于源端extract进程异常,数据不能同步,问题未解决,欢迎指导,待续…

问题解决:

更换mysql-5.5.12的版本,目前Golden Gate 版本不支持mysql-5.6

GGSCI (ogg) 1> edit param ext_1

配置/etc/my.cnf文件:

[java] view plain copy print ?

  1. # binary logging is required for replication
  2. log-bin=/var/lib/mysql/mysql-bin
  3. log-bin-index=/var/lib/mysql/mysql-bin.index
  4. # binary logging format - mixed recommended
  5. #binlog_format=mixed
  6. binlog_format=row

并编辑extract进程组配置文件

GGSCI (ogg) 1> edit param ext_1

extract ext_1

setenv (MYSQL_HOME=”/var/lib/mysql”)

tranlogoptions altlogdest /var/lib/mysql/mysql-bin.index

sourcedb test@localhost:3306,userid root,password oracle

exttrail ./dirdat/e2

dynamicresolution

gettruncates

table test.test2;

启动extract 进程

[java] view plain copy print ?

  1. GGSCI (ogg) 2> start ext_1
  2. Sending START request to MANAGER …
  3. EXTRACT EXT_1 starting
  4. GGSCI (ogg) 3> info all
  5. Program Status Group Lag at Chkpt Time Since Chkpt
  6. MANAGER RUNNING
  7. EXTRACT ABENDED EXT_1 00:00:00 72:19:40
  8. EXTRACT RUNNING PUMP_1 00:00:00 00:00:01

仍然失败,以下为ogg日志:

[root@ogg ogg_ms]# tail ggserr.log

[java] view plain copy print ?

  1. 2014-09-29 16:29:09 INFO OGG-01026 Oracle GoldenGate Capture for MySQL, ext_1.prm: Rolling over remote file ./dirdat/e2000143.
  2. 2014-09-29 16:29:09 INFO OGG-01053 Oracle GoldenGate Capture for MySQL, ext_1.prm: Recovery completed for target file ./dirdat/e2000144, at RBA 959.
  3. 2014-09-29 16:29:09 INFO OGG-01057 Oracle GoldenGate Capture for MySQL, ext_1.prm: Recovery completed for all targets.
  4. 2014-09-29 16:29:09 INFO OGG-00182 Oracle GoldenGate Capture for MySQL, ext_1.prm: VAM API running in single-threaded mode.
  5. 2014-09-29 16:29:09 INFO OGG-01515 Oracle GoldenGate Capture for MySQL, ext_1.prm: Positioning to begin time Sep 26, 2014 3:52:01 PM.
  6. 2014-09-29 16:29:09 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 : Position time is prior then earliest time available in the log : Earliest time available in the log is 2014-09-29 15:34:40
  7. WHEN FAILED : SetInitialPosition by time stamp
  8. WHERE FAILED : MySQLBinLog Reader Module
  9. CONTEXT OF FAILURE : No Information Available!>.
  10. 2014-09-29 16:29:09 ERROR OGG-01668 Oracle GoldenGate Capture for MySQL, ext_1.prm: PROCESS ABENDING.

重新删除extract进程组,重新添加

[java] view plain copy print ?

  1. bash-4.1$ ./ggsci
  2. Oracle GoldenGate Command Interpreter for MySQL
  3. Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230
  4. Linux, x86, 32bit (optimized), MySQL Enterprise on Apr 23 2012 04:29:30
  5. Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
  6. GGSCI (ogg) 1> delete extract ext_1
  7. Deleted EXTRACT EXT_1.
  8. GGSCI (ogg) 2> add extract ext_1,tranlog,begin now
  9. EXTRACT added.
  10. GGSCI (ogg) 3> add exttrail ./dirdat/e2,extract ext_1
  11. EXTTRAIL added.
  12. GGSCI (ogg) 4> start ext_1
  13. Sending START request to MANAGER …
  14. EXTRACT EXT_1 starting
  15. GGSCI (ogg) 5> info all
  16. Program Status Group Lag at Chkpt Time Since Chkpt
  17. MANAGER RUNNING
  18. EXTRACT RUNNING EXT_1 00:00:23 00:00:03
  19. EXTRACT RUNNING PUMP_1 00:00:00 00:00:01

extract进程,启动成功!

查看日志:

-bash-4.1$ tail ggserr.log

[java] view plain copy print ?

  1. 2014-09-29 16:55:12 INFO OGG-00993 Oracle GoldenGate Capture for MySQL, ext_1.prm: EXTRACT EXT_1 started.
  2. 2014-09-29 16:55:12 INFO OGG-01055 Oracle GoldenGate Capture for MySQL, ext_1.prm: Recovery initialization completed for target file ./dirdat/e2000155, at RBA 959.
  3. 2014-09-29 16:55:12 INFO OGG-01478 Oracle GoldenGate Capture for MySQL, ext_1.prm: Output file ./dirdat/e2 is using format RELEASE 11.2.
  4. 2014-09-29 16:55:12 WARNING OGG-01438 Oracle GoldenGate Capture for MySQL, ext_1.prm: Checkpoint marked as from graceful shutdown, but records found after checkpoint in trail ./dirdat/e2. Expected EOF Seqno 0, RBA 0. Found Seqno 155, RBA 959.
  5. 2014-09-29 16:55:12 INFO OGG-01026 Oracle GoldenGate Capture for MySQL, ext_1.prm: Rolling over remote file ./dirdat/e2000155.
  6. 2014-09-29 16:55:12 INFO OGG-01053 Oracle GoldenGate Capture for MySQL, ext_1.prm: Recovery completed for target file ./dirdat/e2000156, at RBA 959.
  7. 2014-09-29 16:55:12 INFO OGG-01057 Oracle GoldenGate Capture for MySQL, ext_1.prm: Recovery completed for all targets.
  8. 2014-09-29 16:55:12 INFO OGG-00182 Oracle GoldenGate Capture for MySQL, ext_1.prm: VAM API running in single-threaded mode.
  9. 2014-09-29 16:55:12 INFO OGG-01515 Oracle GoldenGate Capture for MySQL, ext_1.prm: Positioning to begin time Sep 29, 2014 4:54:48 PM.

发表评论

表情:
评论列表 (有 0 条评论,288人围观)

还没有评论,来说两句吧...

相关阅读