Maxwell简介&使用
时间:2023-11-02 21:37:02
Maxwell 介绍
Maxwell 和 canal 工具对比
安装使用
前提开启了mysql的binlog在cannel使用的时候已经讲解
前提
创建保存断点续传的数据库,创建maxwell123456用户密码shishimaxwell数据库给maxwell授予权限
mysql -uroot -p123456 CREATE DATABASE shishimaxwell ; #maxwell是用户名 GRANT ALL ON shishimaxwell.* TO 'maxwell'@'%' IDENTIFIED BY '123456'; #maxwell是用户名 GRANT SELECT ,REPLICATION SLAVE , REPLICATION CLIENT ON *.* TO maxwell@'%';
tar -zxvf maxwell-1.25.0.tar.gz
修改配置
cp config.properties.example
vi config.properties
producer=kafka kafka.bootstrap.servers=master:9092,node1:9092,node2:9092 #需要添加 kafka_topic=gmall_db # mysql login info,这里的mysql既是开启binlog的mysql,也是自己创建保存读取位置shishimaxwell的mysql #数据库host host=master #数据库用户 user=maxwell #数据库密码 password=123456 #需要添加 后续bootstrap初始化会用 client_id=maxwell_1 ##保存在指定消费位置的数据库 schema_database=shishimaxwell
注:默认或输出到指定: Kafka 主题的一个 kafka 因为多个分区并行可能会被打乱
binlog 的顺序
要提高平行度,首先设置 kafka 的分区数>1,然后设置 producer_partition_by 属性
可选值 producer_partition_by=database|table|primary_key|random| column
启动
/home/bigdata/shishishell/maxwell/maxwell-1.25.0/bin/maxwell --config /home/bigdata/shishishell/maxwell/maxwell-1.25.0/config.properties >/dev/null 2>&1 &
检查数据库是否生成表格
数据生成的格式
增
{ "database": "gmall", "table": "comment_info", "type": "insert", "ts": 1657694285, "xid": 79219, "commit": true, "data": { "id": 1547108081146556427, "user_id": 682, "nick_name": null, "head_img": null, "sku_id": 24, "spu_id": 8, "order_id": 6897, "appraise": "1204", "comment_txt": "评论内容:82154639985516955573787189871861313164594735727667", "create_time": "2022-06-28 14:38:04", "operate_time": null } }
删
{ "database": "gmall", "table": "base_dic", "type": "delete", "ts": 1657694385, "xid": 111301, "commit": true, "data": { "dic_code": "1101", "dic_name": "支付宝", "parent_code": "11", "create_time": null, "operate_time": null } }
改
{ "database": "gmall", "table": "base_dic", "type": "update", "ts": 1657694417, "xid": 111341, "commit": true, "data": { "dic_code": "1103", "dic_name": "银联1", "parent_code": "11", "create_time": null, "operate_time": null }, "old": { "dic_name": "银联" } }
bootstap全量
--client_id maxwell_1是上面配置的东西,它的作用是bootstap只查询数据,--client_id maxwell_1.在指标配置文件中使用maxwell客户端同步数据
bin/maxwell-bootstrap --user maxwell --password 123456 --host master --database gmall --table user_info --client_d maxwell_1
生成的数据如下
开始的一条数据为空
{
"database": "gmall",
"table": "user_info",
"type": "bootstrap-start",
"ts": 1657718813,
"data": {}
}
{
"database": "gmall",
"table": "user_info",
"type": "bootstrap-insert",
"ts": 1657718505,
"data": {
"id": 6800,
"login_name": "m9ml9e7xq4bx",
"nick_name": "寒寒",
"passwd": null,
"name": "元寒",
"phone_num": "13132628314",
"email": "m9ml9e7xq4bx@yeah.net",
"head_img": null,
"user_level": "1",
"birthday": "1998-05-28",
"gender": "F",
"create_time": "2022-06-29 04:49:45",
"operate_time": null,
"status": null
}
}