Goldengate安装
OS:CentOS Linux release 7.3.1611 (Core)
mysql:5.6.28-log,企业版和社区版均支持
GoldenGate:12.2.0.1.1
源库:192.168.118.129:3306
目标库:192.168.118.130:3306
表存储引擎:InnoDB
前提条件:
源端必须开启log-bin和log-bin-index
mysql> show VARIABLES like '%log_bin%';
+---------------------------------+--------------------------------------------+
| Variable_name | Value |
+---------------------------------+--------------------------------------------+
| log_bin | ON |
| log_bin_basename | /data/mysql/mysql3306/data/mysql-bin |
| log_bin_index | /data/mysql/mysql3306/data/mysql-bin.index |
| log_bin_trust_function_creators | ON |
| log_bin_use_v1_row_events | OFF |
| sql_log_bin | ON |
+---------------------------------+--------------------------------------------+
源和目标库均执行
1.解压ogg安装包
mkdir /u01/app/ggs -p
tar -xvf ggs_Linux_x64_MySQL_64bit.tar -C /u01/app/ggs
2.初始化ogg目录
cd /u01/app/ggs
./ggsci
create subdirs
3.建ogg数据库及账号
create database ogg;
grant all on \*.* to ogg@'192.168.118.%' identified by 'ggs';
flush privileges;
分库分表进程配置
源端
注意格式,表名与分号;之间不要有空格!!!!
1.管理进程
edit param mgr ##编辑管理进程mgr,输入下面内容
port 8809
DYNAMICPORTLIST 8840-8850
ACCESSRULE, PROG *, IPADDR 192.168.118.130, ALLOW --允许目标端ip访问
2.抓取进程
dblogin sourcedb ogg@192.168.118.129:3306 userid ogg password ggs
add extract exttp,tranlog,begin now
add exttrail ./dirdat/tp,extract exttp, megabytes 500
edit params exttp ##编辑进程exttp,输入下面内容
extract exttp
sourcedb ogg@192.168.118.129:3306 userid ogg password ggs
tranlogoptions altlogdest /data/mysql/mysql3306/logs/mysql-bin.index
exttrail ./dirdat/tp
dynamicresolution
gettruncates
table test_user.goods_time_price,KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID); --需要主键和分区字段同时作为keycols
3.传递进程
ADD EXTRACT dpetp, EXTTRAILSOURCE ./dirdat/tp
ADD RMTTRAIL ./dirdat/tp, EXTRACT dpetp, megabytes 500
edit params dpetp ##编辑进程dpetp,输入下面内容
extract dpetp
rmthost 192.168.118.130,mgrport 8809
rmttrail ./dirdat/tp
PASSTHRU
gettruncates
table test_user.goods_time_price;
4.数据初始化抓取进程
--初始化数据进程,也可用其他方式同步初始数据,此方法同步速度约10000条/秒(机械盘)
--若有多个大表,可分开配置多个,同时进行初始化
add extract inittp1,sourceistable
edit params inittp1 ##编辑进程inittp1,输入下面内容
extract inittp1
sourcedb ogg@192.168.118.129:3306 userid ogg password ggs
rmthost 192.168.118.130,mgrport 8809
rmttask replicat,group reptp1 --reptp1需要与目标端初始化应用进程名对应
table test_user.goods_time_price;
目标端
注意格式,表名与分号;之间不要有空格!!!!
1.管理进程
edit param mgr ##编辑管理进程mgr,输入下面内容
port 8809
DYNAMICPORTLIST 8840-8850
ACCESSRULE, PROG *, IPADDR 192.168.118.129, ALLOW --允许源端ip访问
2.登陆目标库,创建checkpoint table
dblogin sourcedb ogg@192.168.118.130:3306 userid ogg password ggs
add checkpointtable ogg.ckp_table
3.应用进程:
add replicat reptp,exttrail /u01/app/ggs/dirdat/tp,checkpointtable ogg.ckp_table
edit params reptp ##编辑进程reptp,输入下面内容,此案例是按照SUPP_GOODS_ID取余来分片,注意map的格式,空格不可改动,直接复制修改表名即可
replicat reptp
targetdb ogg@192.168.118.130:3306 userid ogg password ggs
discardfile /u01/app/ggs/dirrpt/reptp.dsc,purge
handlecollisions
map test_user.goods_time_price,target test_user_0.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=0),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_1.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=1),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_2.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=2),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_3.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=3),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_4.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=4),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_5.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=5),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_6.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=6),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_7.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=7),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
5.数据初始化应用进程
add replicat reptp1,specialrun
edit param reptp1 ##编辑进程reptp1,对应前面的抓取进程里的reptp1,注意map的格式,空格不可改动,直接复制修改表名即可
replicat reptp1
targetdb ogg@192.168.118.130:3306 userid ogg password ggs
discardfile /u01/app/ggs/dirrpt/reptp1.dsc,purge
sqlexec "SET FOREIGN_KEY_CHECKS=0"
map test_user.goods_time_price,target test_user_0.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=0),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_1.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=1),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_2.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=2),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_3.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=3),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_4.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=4),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_5.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=5),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_6.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=6),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
map test_user.goods_time_price,target test_user_7.goods_time_price,FILTER (@compute( SUPP_GOODS_ID \ 8)=7),KEYCOLS(SUPP_GOODS_ID,TIME_PRICE_ID);
启动进程,开始同步
1.启动源端和目标端管理进程
cd /u01/app/ggs
./ggsci
start mgr
2.启动源端抓取和传递进程
cd /u01/app/ggs
./ggsci
start exttp
start dpetp
info all
3.启动源端初始化进程同步全量数据,目标端应用进程随之启动,无需处理
cd /u01/app/ggs
./ggsci
start inittp1
info ini*,tasks ###查看初始化进程状态
EXTRACT INITTP1 Last Started 2018-11-12 17:21 Status RUNNING
Checkpoint Lag Not Available
Log Read Checkpoint Table test_user.goods_time_price
2018-11-12 17:21:39 Record 51007
Task SOURCEISTABLE
4.待第三步完成后启动目标端应用进程
cd /u01/app/ggs
./ggsci
start reptp
5.检查数据是否分库分表正确
6.检查dml是否正确同步
范围分区参考
抓取:
table hotel.com_photo,KEYCOLS(PHOTO_ID,OBJECT_ID);
传递:
table hotel.com_photo;
应用(注意条件的括号、表小写、字段大写):
map hotel.com_photo,target hotel0.com_photo,FILTER ( (OBJECT_ID>0) AND (OBJECT_ID<=5000000) ),KEYCOLS(PHOTO_ID,OBJECT_ID);
map hotel.com_photo,target hotel1.com_photo,FILTER ( (OBJECT_ID>5000000) AND (OBJECT_ID<=10000000) ),KEYCOLS(PHOTO_ID,OBJECT_ID);
map hotel.com_photo,target hotel2.com_photo,FILTER ( (OBJECT_ID>10000000) AND (OBJECT_ID<=20000000) ),KEYCOLS(PHOTO_ID,OBJECT_ID);
网友评论