基于OGG实现Oracle实时同步MySQL

📢📢📢📣📣📣
哈喽!大家好,我是【IT邦德】,江湖人称jeames007,10余年DBA及大数据工作经验
一位上进心十足的【大数据领域博主】!😜😜😜
中国DBA联盟(ACDU)成员,目前服务于工业互联网
擅长主流Oracle、MySQL、PG、高斯及Greenplum运维开发,备份恢复,安装迁移,性能优化、故障应急处理等。
✨ 如果有对【数据库】感兴趣的【小可爱】,欢迎关注【IT邦德】💞💞💞
❤️❤️❤️感谢各位大可爱小可爱!❤️❤️❤️

文章目录

  • 前言
    • 1.架构设计
    • 2.OGG安装部署
      • 2.1 OGG for Oracle
      • 2.2 OGG for MySQL
    • 3.Oracle相关配置
      • 3.1 参数调整
      • 3.2 新增用户
    • 4.MySQL数据初始化
    • 5.Oracle OGG设置
    • 6.MySQL OGG设置
    • 7.全量同步数据
    • 8.增量时实同步
      • 8.1 Oracle端
      • 8.2 MySQL端
    • 9.测试同步

前言

本文详细阐述了基于OGG实现Oracle实时同步MySQL全过程

1.架构设计

2.OGG安装部署

2.1 OGG for Oracle

1.OGG下载地址:
https://www.oracle.com/middleware/technologies/goldengate-downloads.html
创建OGG使用目录
chown -R oracle:oinstall /oraogg
chmod 775 -R /oraogg

2.环境变量如下
vi .bash_profileexport GG_HOME=/oraogg/goldengate
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:$GG_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
alias ggsci='cd $GG_HOME;ggsci'source .bash_profile3.静默安装
cd /oraogg/fbo_ggs_Linux_x64_Oracle_shiphome/Disk1/response
vi /oraogg/fbo_ggs_Linux_x64_Oracle_shiphome/Disk1/response/oggcore.rsp--只修改如下3个地方即可。
INSTALL_OPTION=ora19c
SOFTWARE_LOCATION=/oraogg/goldengate
INVENTORY_LOCATION=/u01/app/oraInventory
/u01/app/oracle/product/19.3.0/db_1

使用如下命令静默安装:
/oraogg/fbo_ggs_Linux_x64_Oracle_shiphome/Disk1/runInstaller -silent
-responseFile /oraogg/fbo_ggs_Linux_x64_Oracle_shiphome/Disk1/response/oggcore.rsp

OGG初始化
cd /ogg
./ggsci
create subdirs

2.2 OGG for MySQL

1.安装客户端
yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
yum install mysql-community-server --nogpgcheck

2.创建oggm用户运行OGG for MySQL软件,安装目录为/oggmysql
groupadd -g 1005 ogg
useradd -g ogg -u 1005 -m oggm
mkdir -p /oggmysql
chown oggm:ogg /oggmysql

3.解压缩安装
cd /oggmysql/
unizp 213000_ggs_Linux_x64_MySQL_64bit.zip
tar -xf ggs_Linux_x64_MySQL_64bit.tar

[root@ogg21all oggmysql]# ./ggsci -V
Oracle GoldenGate Command Interpreter for MySQL
Version 21.3.0.0.0 OGGCORE_21.3.0.0.0_PLATFORMS_210728.1047
Oracle Linux 7, x64, 64bit (optimized), MySQL on Jul 28 2021 18:17:46
Copyright © 1995, 2021, Oracle and/or its affiliates. All rights reserved.

4.配置
su - oggm
$ /oggmysql/ggsci
GGSCI (ogg21all) 1> create subdirs

5.环境变量设置
vi .bash_profileexport GG_HOME=/oggmysql
export PATH=$PATH:$HOME/bin:$GG_HOME
alias ggsci='cd $GG_HOME;ggsci'source .bash_profile

3.Oracle相关配置

3.1 参数调整

– oracle数据库配置
1.开启数据库归档–如果没有开启
2.开启数据库级别附加日志–如果没有开始最小附加日志
3.开启强制日志–如果没有开启强制日志
4.设置ENABLE_GOLDENGATE_REPLICAT参数为TRUE
5.创建OGG用户包括包括源端用户、目标端用户以及OGG抽取用户

alter database add supplemental log data;
alter database add supplemental log data (all) columns;
alter database force logging;
alter system set enable_goldengate_replication=TRUE;

##修改归档路径
mkdir -p /home/oracle/arch
SYS@oradb> alter system set log_archive_dest_1=‘location=/home/oracle/arch’;
System altered.
SYS@oradb> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/arch
Oldest online log sequence 3
Next log sequence to archive 5
Current log sequence 5

SYS@oradb> select name,supplemental_log_data_min , force_logging, log_mode from v$database;
NAME               SUPPLEMENTAL_LOG FORCE_LOGGING     LOG_MODE
------------------ ---------------- ----------------- ------------------------
ORCLCDB            YES              YES               ARCHIVELOG

##关闭回收站
SQL> SHOW PARAMETER recyclebin;
SQL> ALTER SYSTEM SET recyclebin = OFF SCOPE = SPFILE;
SQL> show recyclebin;
SQL> PURGE recyclebin;

3.2 新增用户

-- OGG管理用户
SYS@oradb> alter session set container=ORCLPDB1;CREATE USER ogg identified by oracle;
GRANT DBA to ogg;
grant SELECT ANY DICTIONARY to ogg;
GRANT EXECUTE ON SYS.DBMS_LOCK TO ogg;
grant select any transaction to ogg;
grant select any table to ogg;
grant flashback any table to ogg;
grant alter any table to ogg;exec dbms_goldengate_auth.grant_admin_privilege('OGG','*',TRUE); -- 业务用户
CREATE USER rptuser identified by oracle;
GRANT DBA to rptuser ;
grant SELECT ANY DICTIONARY to rptuser;
GRANT EXECUTE ON SYS.DBMS_LOCK TO rptuser;

4.MySQL数据初始化

1.生成MySQL端DDL语句
可以使用Navicat的数据传输功能或其它工具直接从Oracle端生成MySQL类型的建表语句如下:mysql -uroot -proot
create database rptdb;mysql -uroot -proot -h 172.18.12.91 -D rptdb -f < ddl.sql2.DDL语句如下
SET NAMES utf8; 
SET FOREIGN_KEY_CHECKS = 0; DROP TABLE IF EXISTS `ADDRESSES`; 
CREATE TABLE `ADDRESSES` 
( `ADDRESS_ID` decimal(12, 0) NOT NULL, 
`CUSTOMER_ID` decimal(12, 0) NOT NULL, 
`DATE_CREATED` datetime NOT NULL, 
`HOUSE_NO_OR_NAME` varchar(60) NULL, 
`STREET_NAME` varchar(60) NULL, 
`TOWN` varchar(60) NULL, 
`COUNTY` varchar(60) NULL, 
`COUNTRY` varchar(60) NULL, 
`POST_CODE` varchar(12) NULL, 
`ZIP_CODE` varchar(12) NULL, 
PRIMARY KEY (`ADDRESS_ID`), 
INDEX `ADDRESS_CUST_IX`(`CUSTOMER_ID` ASC) 
);----- Table structure for CARD_DETAILS ----
DROP TABLE IF EXISTS `CARD_DETAILS`; 
CREATE TABLE `CARD_DETAILS` 
( `CARD_ID` decimal(12, 0) NOT NULL, 
`CUSTOMER_ID` decimal(12, 0) NOT NULL, 
`CARD_TYPE` varchar(30) NOT NULL, 
`CARD_NUMBER` decimal(12, 0) NOT NULL, 
`EXPIRY_DATE` datetime NOT NULL, 
`IS_VALID` varchar(1) NOT NULL, 
`SECURITY_CODE` decimal(6, 0) NULL, 
PRIMARY KEY (`CARD_ID`), 
INDEX `CARDDETAILS_CUST_IX`(`CUSTOMER_ID` ASC) 
);---- Table structure for CUSTOMERS ----
DROP TABLE IF EXISTS `CUSTOMERS`; 
CREATE TABLE `CUSTOMERS` 
( `CUSTOMER_ID` decimal(12, 0) NOT NULL, 
`CUST_FIRST_NAME` varchar(40) NOT NULL, 
`CUST_LAST_NAME` varchar(40) NOT NULL, 
`NLS_LANGUAGE` varchar(3) NULL, 
`NLS_TERRITORY` varchar(30) NULL, 
`CREDIT_LIMIT` decimal(9, 2) NULL, 
`CUST_EMAIL` varchar(100) NULL, 
`ACCOUNT_MGR_ID` decimal(12, 0) NULL, 
`CUSTOMER_SINCE` datetime NULL, 
`CUSTOMER_CLASS` varchar(40) NULL, 
`SUGGESTIONS` varchar(40) NULL, 
`DOB` datetime NULL, `MAILSHOT` varchar(1) NULL, 
`PARTNER_MAILSHOT` varchar(1) NULL, 
`PREFERRED_ADDRESS` decimal(12, 0) NULL, 
`PREFERRED_CARD` decimal(12, 0) NULL, 
PRIMARY KEY (`CUSTOMER_ID`), 
INDEX `CUST_ACCOUNT_MANAGER_IX`(`ACCOUNT_MGR_ID` ASC), 
INDEX `CUST_DOB_IX`(`DOB` ASC), 
INDEX `CUST_EMAIL_IX`(`CUST_EMAIL` ASC) 
);

5.Oracle OGG设置

[root@ogg21all /]# su - oracle
[oracle@ogg21all ~]$ ggsci
GGSCI (ogg21all) 2> edit params mgr
PORT 7809

add credentialstore
alter credentialstore add user ogg@172.18.12.90/oradb, password oracle alias ora19c
INFO CREDENTIALSTORE

GGSCI (ogg21all) 7> INFO CREDENTIALSTORE
Reading from credential store:
Default domain: OracleGoldenGate
Alias: ora19c
Userid: ogg@172.18.12.90/oradb

dblogin useridalias ora19c
ADD SCHEMATRANDATA RPTUSER
INFO SCHEMATRANDATA RPTUSER
list tables RPTUSER.*

6.MySQL OGG设置

GGSCI (ogg21all) 1> edit params mgr
port 8809

GGSCI (ogg21all) 2> start mgr
Manager started.

GGSCI (ogg21all) 3> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING

7.全量同步数据

Oracle全量同步到MySQL
注意:在此阶段,源端需要停业务,不能产生新数据。-- oracle端
edit params ext0
EXTRACT ext0
USERIDALIAS ora19c
rmthost 127.0.0.1,mgrport 8809
rmttask replicat,group rep0
TABLE RPTUSER.ADDRESSES;
TABLE RPTUSER.CARD_DETAILS;
TABLE RPTUSER.CUSTOMERS;add extract ext0 ,sourceistable
delete extract ext0-- MySQL端
edit params rep0
replicat rep0
targetdb rptdb@172.18.12.91:3306 userid root password root
map RPTUSER.ADDRESSES, target rptdb.ADDRESSES;
map RPTUSER.CARD_DETAILS, target rptdb.CARD_DETAILS;
map RPTUSER.CUSTOMERS, target rptdb.CUSTOMERS;add replicat rep0 ,specialrun
delete replicat rep0-- 直接启动源端ext0即可,rep0不用启动,MGR会自动启动它,等同步结束,它会自动关闭
start ext0-- 查看日志
info rep0,showch
view report rep0--登录验证数据
mysql -uroot -proot -h 172.18.12.91 -D rptdbmysql> select count(*) from ADDRESSES;
+----------+
| count(*) |
+----------+
|      150 |
+----------+
1 row in set (0.04 sec)mysql> select count(*) from CARD_DETAILS;
+----------+
| count(*) |
+----------+
|      150 |
+----------+
1 row in set (0.05 sec)mysql> select count(*) from CUSTOMERS;
+----------+
| count(*) |
+----------+
|      100 |
+----------+
1 row in set (0.04 sec)GGSCI (ogg21all as ogg@oradb) 21> info ext0Extract    EXT0      Last Started 2023-11-25 18:58   Status STOPPED
Checkpoint Lag       Not Available
Log Read Checkpoint  Table RPTUSER.CUSTOMERS2023-11-25 18:58:46  Record 100
Task                 SOURCEISTABLE

8.增量时实同步

8.1 Oracle端

ADD EXTRACT exto INTEGRATED TRANLOG BEGIN NOW
ADD EXTTRAIL ./dirdat/eo EXTRACT exto

dblogin useridalias ora19c
REGISTER EXTRACT exto DATABASE

edit params exto
EXTRACT exto
USERIDALIAS ora19c
TRANLOGOPTIONS FETCHPARTIALLOB
EXTTRAIL ./dirdat/eo
TABLE RPTUSER.ADDRESSES;
TABLE RPTUSER.CARD_DETAILS;
TABLE RPTUSER.CUSTOMERS;

启动exto
start exto
GGSCI (ogg21all as ogg@oradb) 12> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING EXTO 00:02:19 00:00:08

8.2 MySQL端

edit params repm
replicat repm
targetdb rptdb@172.18.12.91:3306 userid root password root
map RPTUSER.ADDRESSES, target rptdb.ADDRESSES;
map RPTUSER.CARD_DETAILS, target rptdb.CARD_DETAILS;
map RPTUSER.CUSTOMERS, target rptdb.CUSTOMERS;

add rep repm, exttrail /oraogg/goldengate/dirdat/eo, NODBCHECKPOINT
delete rep repm

start repm

9.测试同步

1.Oracle端测试产生数据
SYS@oradb> DELETE FROM RPTUSER.ADDRESSES WHERE ADDRESS_ID=150;GGSCI (ogg21all as ogg@oradb) 21> stats exto,totalSending STATS request to Extract group EXTO ...Start of statistics at 2023-11-25 19:36:13.Output to ./dirdat/eo:Extracting from RPTUSER.ADDRESSES to RPTUSER.ADDRESSES:*** Total statistics since 2023-11-25 19:25:02 ***Total inserts                              0.00Total updates                              0.00Total deletes                              1.00Total upserts                              0.00Total discards                             0.00Total operations                           1.00End of statistics.2.mysql端插入数据
mysql -uroot -proot -h 172.18.12.91 -D rptdb
mysql> select count(*) from ADDRESSES;GGSCI (ogg21all) 18> stats repm,totalSending STATS request to Replicat group REPM ...Start of statistics at 2023-11-25 19:56:10.Replicating from RPTUSER.ADDRESSES to rptdb.ADDRESSES:*** Total statistics since 2023-11-25 19:54:49 ***Total inserts                              0.00Total updates                              0.00Total deletes                              1.00Total upserts                              0.00Total discards                             0.00Total operations                           1.00End of statistics.mysql> SELECT * FROM ADDRESSES WHERE ADDRESS_ID=150;
Empty set (0.00 sec)mysql> select database();
+------------+
| database() |
+------------+
| rptdb      |
+------------+
1 row in set (0.00 sec)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/217881.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于Pytest+Requests+Allure实现接口自动化测试

一、整体结构 框架组成&#xff1a;pytestrequestsallure 设计模式&#xff1a; 关键字驱动 项目结构&#xff1a; 工具层&#xff1a;api_keyword/ 参数层&#xff1a;params/ 用例层&#xff1a;case/ 数据驱动&#xff1a;data_driver/ 数据层&#xff1a;data/ 逻…

上新!2023年汉字小达人市级比赛在线模拟题增加2个刷题试卷

各位小学三年级到五年级的上海学霸孩子们&#xff0c;刚刚结束了上海小学生古诗文大会的复赛&#xff0c;就紧锣密鼓地全身心投入到上海小学生汉字小达人的市级比赛的备赛中了。 为了助各位孩子一臂之力&#xff0c;我把在线模拟题进行了更新&#xff0c;新增了两个可以刷题的试…

LeetCode Hot100 105.从前序与中序遍历序列构造二叉树

题目&#xff1a;给定两个整数数组 preorder 和 inorder &#xff0c;其中 preorder 是二叉树的先序遍历&#xff0c; inorder 是同一棵树的中序遍历&#xff0c;请构造二叉树并返回其根节点。 代码&#xff1a; class Solution {private Map<Integer, Integer> indexM…

burp suite 2023.10 Intruder模块详解)

burp suite 2023 Intruder模块详解 Intruder 模块是Burp suite的一个重要功能&#xff0c;用于自动化攻击和对目标应用程序进行大规模的攻击测试。 其主要功能包括&#xff1a; Payloads 设置&#xff1a; 用户可以定义不同类型的 payload&#xff0c;例如字典、数字范围、定…

spring本地事务与单/多线程

请直接看原文 原文链接:多线程与数据库事务以及数据库连接之间的关系 - 知乎 (zhihu.com) -------------------------------------------------------------------------------------------------------------------------------- 今天我们来梳理一下&#xff0c; 多线程、数…

Selenium+Pytest自动化测试框架实战

&#x1f4e2;专注于分享软件测试干货内容&#xff0c;欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; 如有错误敬请指正&#xff01;&#x1f4e2;交流讨论&#xff1a;欢迎加入我们一起学习&#xff01;&#x1f4e2;资源分享&#xff1a;耗时200小时精选的「软件测试」资…

java集合,ArrayList、LinkedList和Vector,多线程场景下如何使用 ArrayList

文章目录 Java集合1.2 流程图关系1.3 底层实现1.4 集合与数组的区别1.4.1 元素类型1.4.2 元素个数 1.5 集合的好处1.6 List集合我们以ArrayList集合为例1.7 迭代器的常用方法1.8 ArrayList、LinkedList和Vector的区别1.8.1 说出ArrayList,Vector, LinkedList的存储性能和特性1.…

1、Mysql架构与历史

Mysql逻辑架构 最上层是服务并不是Mysql所独有的&#xff0c;大多数基于网络的客户端/服务器的工具或者服务都有类似的架构&#xff0c;比如连接处理&#xff0c;授权认证&#xff0c;安全等。 第二层是Mysql比较有意思的部分。大多数Mysql的核心服务都在这一层&#xff0c;…

2024北京理工大学计算机考研分析

24计算机考研|上岸指南 北京理工大学 计算机学院始建于1958年&#xff0c;是全国最早设立计算机专业的高校之一。2018年4月&#xff0c;计算机学院、软件学院、网络科学与技术研究院合并成立新的计算机学院。学院累计为国家培养各类人才15000余名。计算机科学学科ESI排名进入全…

AD9528学习笔记

前言 AD9528是ADI的一款时钟芯片&#xff0c;由2-stage PLL组成&#xff0c;并且集成JESD204B/JESD204C SYSREF信号发生器&#xff0c;SYSREF发生器输出单次、N次或连续信号&#xff0c;并与PLL1和PLL2输出同步&#xff0c;从而可以实现多器件之间的同步。 AD9528总共有14路输…

QT visual stdio加载动态库报错126问题

报错126是找不到指定的模块 QT 查看构建目录&#xff0c;将依赖的动态库放到该目录下即可成功 visual stdio将依赖的动态库放到运行目录 在vs中使用导出类的动态库时&#xff0c;不但需要将对应的.dll放到对应的目录下&#xff0c;还需要将该动态库对应的.lib添加到如下配置才…

强化学习,快速入门与基于python实现一个简单例子(可直接运行)

文章目录 一、什么是“强化学习”二、强化学习包括的组成部分二、Q-Learning算法三、迷宫-强化学习-Q-Learning算法的实现全部代码&#xff08;复制可用&#xff09;可用状态空间检查是否超出边界epsilon 的含义更新方程 总结 一、什么是“强化学习” 本文要记录的大概内容&am…