针对MySQL的binlog的采集,笔者整理了如下解决方案。
方案1:binlog + maxwell 方式采集
步骤如下:
1、开启mysql的bin-log
开启方式,修改my.cnf(/etc/my.cnf) 添加如下内容:
server-id=1
log-bin=master(这一步开启binlog)
binlog_format=row(这里format必须是row模式)
2、重启mysql服务
3、maxwell安装配置使用
wget https://github.com/zendesk/maxwell/releases/download/v1.17.1/maxwell-1.17.1.tar.gz
tar -zxvf maxwell-1.17.1.tar.gz
bin/maxwell --user='maxwell' --password='123456' --host='127.0.0.1' --producer=stdout
示例:
{"database":"test","table":"logbin","type":"insert","ts":1532590262,"xid":231,"commit":true,"data":{"id":3,"name":"zhh2","age":23,"address":"cde"}{"database":"test","table":"logbin","type":"update","ts":1532590416,"xid":267,"commit":true,"data":{"id":3,"name":"zhh2","age":23,"address":"beijing"},"old":{"address":"cde"}}
{"database":"test","table":"logbin","type":"delete","ts":1532590427,"xid":272,"commit":true,"data":{"id":1,"name":"zz","age":23,"address":null}}
4、maxwell与dc-proxy的整合方式
可将maxwell作为dc-proxy的一个插件,当用户需要使用mysql的binlog时,将其进行安装使用。
1)、dc-proxy + maxwell producer stdout :代理通过shell 运行maxwell,获取到输出流,进行处理
2)、dc-proxy + maxwell producer file + shell tail -F file
3)、dc-proxy + maxwell producer kafka :maxwell将数据生产到kafka中,由proxy消费
5、特别说明:
maxwell可生产的数据类型
1)、stdout
2)、file
3)、kafka
4)、rabbitmq
5)、redis
6、其它:kinesis | pubsub | sqs
maxwell的filter
可对数据进行过滤:include_dbs,exclude_dbs,include_tables,exclude_tables
maxwell官方网站:http://maxwells-daemon.io/config/
方案2:binlog + canal 方式采集
步骤如下:
1、开启mysql的bin-log
开启方式,修改my.cnf(/etc/my.cnf) 添加如下内容:
server-id=1
log-bin=master(这一步开启binlog)
binlog_format=row(这里format必须是row模式)
2、重启mysql服务
3、安装部署canal server,修改配置并启动
wget https://github.com/alibaba/canal/releases/download/canal-1.0.24/canal.deployer-1.0.24.tar.gz
mkdir canal-1.0.24
tar -zxvf canal.deployer-1.0.24.tar.gz -C canal-1.0.24
vim canal-1.0.24/conf/example/instance.properties:配置监控指定数据库的
canal-1.0.24/bin/startup.sh
4、编写canal客户端canal server
方案3:利用Open Replicator解析binlog 方式采集
步骤如下:
1、开启mysql的bin-log
开启方式,修改my.cnf(/etc/my.cnf) 添加如下内容:
server-id=1
log-bin=master(这一步开启binlog)
binlog_format=row(这里format必须是row模式)
2、重启mysql服务
3、通过OpenReplicator相关API获取信息
比较原生:返回的只有列的值,没有列名称,表名称,以及数据库名称,需要自己去查询
参考1:https://blog.csdn.net/u013256816/article/details/53072560
参考2:http://www.voidcn.com/article/p-wmizafrd-nc.html