Maxwell 笔记

原理

把自己模仿成一个 mysql slave 读取mysql的 mysql-bin-log 二进制文件 并转为 json

MySQL Bin的三种模式

  • statement

记录每句操作语句 相对节省空间 但是可能导致数据不一致

比如执行now() 函数

他只会保存now() 不会保存当时的结果

  • row*

保持数据绝对一致性

保留操作后的结果

占用空间较大

  • mixed

默认是statement 但是调用now() 或其他函数式 就会保存结果

开启MySQL BinLog

vim /etc/my.cnf

bin-log=mysql-binlog
# 可以多行 指定要监控的数据库
log-bin-to-db=<DB_NAME>

maxwell 到 kafka

将修改用json推送到kafka的某个topic中

不指定topic默认到maxwelltopic中

producer=kafka
kafka.bootstrap.servers=<服务器地址:PORT;>
kafka_topic=<topic_name>

filter 过滤监控

# 白名单
filter='exclude: *.*, include: <DB.TABLE>'

# 黑名单
filter='exclude: <DB.TABLE>, include: *.*'

# 多表筛选
filter='exclude: <DB.TABLE1>, <DB.TABLE2>, <DB.TABLE3>, include: *.*'
filter='exclude: *.*, include: <DB.TABLE1>, <DB.TABLE2>, <DB.TABLE3>'

Maxwell 部署

上传并解压

scp xxx /opt/softs/
cd /opt/softs
tar -xvf 
tar -xvf maxwell-1.29.0.tar.gz
mv maxwell-1.29.0 ../module/
cd /opt/module/maxwell-1.29.0/

创建环境变量

vim /etc/profile

# maxwell
export MAXWELL_HOME=/opt/module/maxwell-1.29.0
export PATH=$PATH:$MAXWELL_HOME/bin

source /etc/profile

配置 maxwell

cp config.properties.example config.properties
vim config.properties

kafka.bootstrap.servers=master:9092

host=<mysql-ip>
user=<mysql-user>
password=<mysql-password>

修改MySQL 配置

vim /etc/my.cnf

server_id=1
log-bin=mysql-bin
binlog_format=row
# log-bin-to-db=<DB_NAME>

启动

cd /opt/module/maxwell-1.29.0
bin/maxwell --config ./config.properties
# 或者 $MAXWELL_HOME/bin/maxwell -config $MAXWELL_HOME/config.properties 需要环境变量
# 启动kafka自带的消费者检查是否成功
kafka-console-consumer.sh --bootstrap-server bigdata1:9092 --topic maxwell
Comment