- 下载安装包
http://maxwells-daemon.io/
# 解压
tar -zxvf maxwell-1.23.3.tar.gz -C /app/
- mysql 配置
$ vi /etc/my.cnf
[mysqld]
server_id=1
log-bin=master
binlog_format=row
3.创建maxwell 数据库 及用户
create database maxwell;
mysql> CREATE USER 'maxwell'@'%' IDENTIFIED BY '123456';
mysql> GRANT ALL ON maxwell.* TO 'maxwell'@'%';
mysql> GRANT SELECT, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'maxwell'@'%';
FLUSH PRIVILEGES;
4.运行 maxwell
#stdout
bin/maxwell --user='maxwell' --password='123456' --host='hadoop001' --producer=stdout
#kafka
bin/maxwell --user='maxwell' --password='123456' --host='hadoop001' \
--producer=kafka --kafka.bootstrap.servers=hadoop001:9092 \
--kafka_topic=maxwell
#producer
stdout 控制台输出
kafka 卡夫卡输出
--daemon 守护进程 后台运行
--filter 过滤条件,可以过滤数据库,表,列等等
- 测试
# mysql 新增信息
mysql> insert into user_domain values('1','baidu.com');
Query OK, 1 row affected (0.00 sec)
[hadoop@hadoop001 maxwell]$ bin/maxwell --user='maxwell' --password='123456' --host='hadoop001' --producer=stdout
# 注意 如使用kafka,则版本要与你的kafka版本一致
通过 --kafka_version 指定
Using kafka version: 1.0.0
09:14:11,770 WARN MaxwellMetrics - Metrics will not be exposed: metricsReportingType not configured.
09:14:12,001 INFO Maxwell - Maxwell v1.23.3 is booting (StdoutProducer), starting at Position[BinlogPosition[master.000001:4393], lastHeartbeat=0]
09:14:12,093 INFO MysqlSavedSchema - Restoring schema id 1 (last modified at Position[BinlogPosition[master.000001:4393], lastHeartbeat=0])
09:14:12,162 INFO BinlogConnectorReplicator - Setting initial binlog pos to: master.000001:4393
09:14:12,251 INFO BinaryLogClient - Connected to hadoop001:3306 at master.000001/4393 (sid:6379, cid:6)
09:14:12,251 INFO BinlogConnectorLifecycleListener - Binlog connected.
{"database":"sparkdb","table":"user_domain","type":"insert","ts":1574903833,"xid":310,"commit":true,"data":{"user_id":"1","domain":"baidu.com"}}
{"database":"sparkdb","table":"user_domain","type":"update","ts":1574903966,"xid":488,"commit":true,"data":{"user_id":"1","domain":"taobao.com"},"old":{"domain":"baidu.com"}}