使用Debezium Binlog同步es
使用Debezium Binlog同步es
Alex使用debezium binlog同步es
- 步骤
- 安装zookeeper
- 安装kafka
- 安装插件
- kafka mysql binlog收集插件
- kafka推送es插件
zookeeper安装、运行
- 下载
1 | # 下载,(需要前置jdk运行环境) |
- 运行
1
2
3
4# 配置
cp conf/zoo_sample.cfg conf/zoo.cfg
# 单点不配置
./bin/zkServer.sh start
kafka安装、运行
- 安装、运行
1
2
3
4
5# 下载,(需要前置jdk运行环境)
wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.8.0/kafka_2.13-2.8.0.tgz
tar -zxf kafka_2.13-2.8.0.tgz
cd kafka_2.13-2.8.0
./bin/kafka-server-start.sh -daemon /opt/debezium/kafka_2.13-2.8.0/config/server.properties
连接器插件配置
mysql连接器下载
- https://www.confluent.io/hub/debezium/debezium-connector-mysql
1
2wget https://d1i4a15mxbxib1.cloudfront.net/api/plugins/debezium/debezium-connector-mysql/versions/1.5.0/debezium-debezium-connector-mysql-1.5.0.zip
unzip debezium-debezium-connector-mysql-1.5.0.zip
- https://www.confluent.io/hub/debezium/debezium-connector-mysql
es链接器下载
- https://www.confluent.io/hub/confluentinc/kafka-connect-elasticsearch
1
2wget https://d1i4a15mxbxib1.cloudfront.net/api/plugins/confluentinc/kafka-connect-elasticsearch/versions/11.0.4/confluentinc-kafka-connect-elasticsearch-11.0.4.zip
unzip confluentinc-kafka-connect-elasticsearch-11.0.4.zip
- https://www.confluent.io/hub/confluentinc/kafka-connect-elasticsearch
配置插件路径
vi kafka_2.13-2.8.0/config/connect-distributed.properties
添加配置1
2# 多个路径,隔开指向插件解压目录即可
plugin.path=/opt/debezium/kafka_2.13-2.8.0/lib_conn/debezium-debezium-connector-mysql-1.5.0,/opt/debezium/kafka_2.13-2.8.0/lib_conn/confluentinc-kafka-connect-elasticsearch-11.0.4启动连接器
1
bin/connect-distributed.sh config/connect-distributed.properties
使用Api添加链接器
- mysql连接器
1 | { |
- es连接器
1 | { |
创建链接器
curl -X POST -H "Content-Type:application/json" --data @es-role.json http://localhost:8083/connectors
相关命令
1
2
3
4
5# kafa 查看topic列表
kafka-topics.sh --list --zookeeper localhost:2181
# 从头读取
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic devops.devops.role --from-beginning参考连接: