gravity mysql_gravity 使用操作。
gravity 使用操作。
最近我司有一个比较奇葩的需求,我们的环境是主从,因为数据量较大会定期的删除数据,
最近不行了,要求新建出来一个库 同步正事环境的数据,但是要剔除 delete ,drop,truncat 等这些删除数据的语句。
因此 准备使用gravity 来进行数据操作。看看能否满足这些需求。
这个环境实现的是mysql ---------》 mysql的数据同步(剔除drop,truncate,delete语句);
mysql:192.168.17.21(主)
mysql:192.168.17.23(辅)
gravity:192.168.17.20
mysql 如果不会安装的话 可以使用 https://www.cnblogs.com/noel/p/10314125.html 脚本安装
在192.168.17.20 配置go语言环境:
https://golang.org/dl/ 下载linux 安装包
上传到服务器 /usr/local/src/ 目录下:
tar -xvzf go1.11.5.linux-amd64.tar.gz -C /usr/local/
export PATH=$PATH:/usr/local/go/bin
或者
vim /etc/profile
查看 gopath
go env
source /etc/profile
编译 (TODO: 开源后直接从 github 下载 binary)
mkdir -p $GOPATH/src/github.com/moiot/
cd $GOPATH/src/github.com/moiot/
git clone https://github.com/moiot/gravity.git
cd gravity/ && make
可能会出现以下错误:
错误1:
[root@localhost moiot]# git clone https://github.com/moiot/gravity.git
Initialized empty Git repository in /usr/local/go/bin/src/github.com/moiot/gravity/.git/
error: while accessing https://github.com/moiot/gravity.git/info/refs
fatal: HTTP request failed
这是因为系统自带的git的版本太低了 需要升级git:
升级git: 下载相应的安装包
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc
yum install gcc perl-ExtUtils-MakeMaker
移除系统自带的git
yum remove git
安装新版git
cd /usr/local/src/
wget https://www.kernel.org/pub/software/scm/git/git-2.9.5.tar.xz
tar -xvz git-2.9.5.tar.xz
cd git-2.9.5
./configure --prefix=/usr/local/git
make && make install
echo "export PATH=$PATH:/usr/local/git/bin" >>/etc/profile
source /etc/profile
错误2:
[root@localhost moiot]# git clone https://github.com/moiot/gravity.git
Cloning into 'gravity'...
fatal: unable to access 'https://github.com/moiot/gravity.git/': SSL connect error
[root@localhost moiot]#
解决办法 yum update nss
分别在mysql:192.168.17.21(主) mysql:192.168.17.23(辅)执行一下命令
CREATE USER _gravity IDENTIFIED BY '_gravity';
GRANT SELECT, RELOAD, LOCK TABLES, REPLICATION SLAVE, REPLICATION CLIENT, CREATE, INSERT, UPDATE, DELETE ON *.* TO '_gravity'@'%';
GRANT ALL PRIVILEGES ON _gravity.* TO '_gravity'@'%';
flush privileges;
创建如下配置文件 mysql-mysql.toml
cat > mysql-mysql.toml << "EOF"
name = "mysql-mysql"
#
# Input 插件的定义,此处定义使用 mysql
#
[input]
type = "mysql"
mode = "replication" ##全量+增量(replication),增量(stream),全量(batch)
[input.config]
#是否忽略双向同步产生的内部数据,默认是false
ignore-bidirectional-data = false
# 总体扫描的并发线程数
# - 默认为 10,表示最多允许 10 个表同时扫描
# - 可选
nr-scanner = 10
# 单次扫描所去的行数
# - 默认为 10000,表示一次拉取 10000 行
# - 可选
table-scan-batch = 10000
# 全局限制,每秒所允许的 batch 数
# - 默认为 1
# - 可选
#
batch-per-second-limit = 1
# 全局限制,没有找到单列主键、唯一索引时,最多多少行的表可用全表扫描方式读取,否则报错退出。
# - 默认为 100,000
# - 可选
#
max-full-dump-count = 10000
[input.config.source]
host = "192.168.17.21"
username = "_gravity"
password = "_gravity"
port = 3306
# 需要扫描的表
# - 必填 多个schema的话 写多个configs
[[input.config.table-configs]]
schema = "test_gravity"
table = "*"
#
# Output 插件的定义,此处使用 mysql
#
[output]
type = "mysql"
#
[output.config]
enable-ddl = true #当前支持 create & alter table 语句。库表名会根据路由信息调整。
[output.config.target]
host = "192.168.17.23"
username = "_gravity"
password = "_gravity"
port = 3306
# 路由规则的定义
[[output.config.routes]]
match-schema = "test_gravity"
match-table = "*"
target_schema = "test_gravity"
target-table = "*"
[output.config.execution-engine]
# 开启双向同步标识的写入
use-bidirection = false
[[filters]]
type = "reject"
[filters.config]
match-schema = "test_gravity"
match-dml-op = "delete"
EOF
然后启动 :
bin/gravity --config mysql-mysql.toml
########遇到的一个坑:
binlog_row_image 必须设置成FULL
create database 操作需要两边都做
delete 可以剔除
drop,truncate 不支持 很好用
gravity mysql_gravity 使用操作。相关推荐
- 详解Android布局中gravity与layout_gravity属性
在android布局中,我们经常会用到"重心"-gravity这个属性.但是gravity有不同的类型: gravity layout_gravity 相对布局中的layout_c ...
- 关于大型网站技术演进的思考
关于大型网站技术演进的思考(一)--存储的瓶颈(1) 前不久公司请来了位互联网界的技术大牛跟我们做了一次大型网站架构的培训,两天12个小时信息量非常大,知识的广度和难度也非常大,培训完后我很难完整理出 ...
- android:layout_gravity 和 android:gravity 的区别
gravity 这个英文单词是重心的意思,在这里就表示停靠位置的意思. android:layout_gravity 和 android:gravity 的区别 从名字上可以看到,android:gr ...
- 非常详细的测试unity与android之间的通讯操作
非常详细的测试unity与android之间的通讯操作 博客分类: unity3dandroid 非常详细的测试unity与android之间的通讯操作 转载自 http://www.narkii.c ...
- Android在listview添加checkbox实现单选多选操作问题
android根据View的不同状态更换不同的背景 http://www.eoeandroid.com/thread-198029-1-1.html android 模仿朋友网推出的菜单效果[改进版] ...
- js 包含某个字符串_[译] 5 大 JavaScript 字符串操作库
原文地址:5 String Manipulation Libraries for JavaScript 原文作者:Mahdhi Rezvi 译文出自:掘金翻译计划 本文永久链接:https://git ...
- 【Android 应用开发】 自定义组件 宽高适配方法, 手势监听器操作组件, 回调接口维护策略, 绘制方法分析 -- 基于 WheelView 组件分析自定义组件
博客地址 : http://blog.csdn.net/shulianghan/article/details/41520569 代码下载 : -- GitHub : https://github.c ...
- Android数据存储之SharedPreferencesSave存储(保存数据,读取数据的操作)
GitHub项目地址: https://github.com/Skymqq/SharedPreferencesSave.git 不同于文件的存储方式,SharedPreferences是使用键值对的方 ...
- Android开发:操作UI线程4种方法
我们经常会在后台线程中去做一些耗时的操作,比如去网络取数据.但是当数据取回来,需要显示到页面上的时候,会遇到一些小麻烦,因为我们都知道,android的UI页面是不允许在其他线程直接操作的.下面总结4 ...
最新文章
- Vue的模板语法学习
- mysql常用语句列表
- Swift3.0语言教程删除字符与处理字符编码
- python 增删列表_python 列表的增删改查
- SpringBoot 包含处理
- wordcount linux java_linux下在eclipse上运行hadoop自带例子wordcount
- BZOJ 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
- 【python】【openCV】分水岭算法
- iOS 自定义字体设置
- lan8720a自协商启动_惠及18个小区17851户!今年海曙老旧小区改造启动,重点内容包括…...
- oracle 计算母亲节日期,致母亲节:云和数据 一个满满是爱的地方
- 怎么找到电脑的打印机
- linux thinkphp5 php7.0禁用eval
- 提取特征点和特征点描述
- 函数——IIFE、作用域、函数调用、函数应用、闭包
- 彻底掌握 Javascript(二十一)async 函数-曾亮-专题视频课程
- 字符串匹配问题(信息学奥赛一本通 - T1355)
- 2.BJDCTF(2020第二届)——Misc杂项题
- 设计模式(四)适配器
- Python 修复 ImportError: cannot import name Markup from jinja2