大白话讲解 :debezium 搭建的使用
(说的不好见谅)
原理讲解:debezium 提供了 kafka连接器(官网下载)。该连接器可以连接数据库,然后监听数据库的变化并把数据推送到kafka。
sudo wget https://mirrors.bfsu.edu.cn/apache/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
tar -zxvf apache-zookeeper-3.7.0-bin.tar.gz
cd apache-zookepeper
复制一个配置文件来修改
cd conf && cp zoo_sample.cfg zoo.cfg
vi zoo.conf
修改 dataDir 目录配置--(注意是否有权限创建改目录)
修改 clientPort 端口号--用于连接
cd ../bin
启动zookeeper时需要带上参数 --config 告诉它配置文件在哪
sudo ./zkServer.sh --config ../conf start
wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.8.0/kafka_2.12-2.8.0.tgz
tar -zxvf kafka_2.12-2.8.0.tgz
cd kafka_2.22-2.8.0。
cd ../conf
vi server.proerties
设置listeners
listeners=PLAINTEXT://192.168.56.102:9092
设置 advertised.listeners(外网要通过这个访问kafka,记得配置)
advertised.listeners=PLAINTEXT://192.168.56.102:9092
指定配置启动kafka
../bin/kafka-server-start.sh ../config/server.properties
-
Install debezium-connect-postgresql
大白话:你需要知道的是,kafka连接器是要启动的,外部数据库连接kafka需要对应的连接器,所以我下载完之后我要把配置告诉kafka,然后启动成功的时候我就能用kafka的连接器api啦。easy
//下载postgresql连接器
wget https://repo1.maven.org/maven2/io/debezium/debezium-connector-postgres/1.5.4.Final/debezium-connector-postgres-1.5.4.Final-plugin.tar.gz
tar -zxvf debezium-connector-postgres-1.5.4.Final-plugin.tar.gz
// 等会我要单机模式启动连接器,所以我要 修改kafka config 里面的connect-standlone.properties 这个配置,修改boostrap.servers = 192.168.56.102:9092 修改plugin.path(你下载的连接器位置)
vi connect-standlone.properties
//现在你已经完成单机模式下启动连接器的配置,但是启动的时候你仍需要告诉kafka你的数据库配置是啥,所以下面是数据库的配置
vi postgresql.conf //(这是我自己创建的配置文件,配置内容如下)
##
name=inventory
connector.class=io.debezium.connector.postgresql.PostgresConnector
database.hostname=192.168.56.103
database.port=5435
database.user=postgres
database.password=postgres
plugin.name = pgoutput
database.dbname=postgres
database.history.kafka.bootstrap.servers=192.168.56.102:9092
database.server.name=server-name
#database.whitelist=public.test1
run the debezium-connect
现在你已经可以单击模式启动了
cd /kafka/bin
//单机模式启动。 指定单机的配置,指定你要连接数据库的配置
./connect-standalone.sh ../config/connect-standalone.properties ../config/postgres.propertie
s
now you can see the data’s change on kafka and can use the connector’s api
1.get the connectors
GET : 192.168.56.102:8083/connectors
2.create a connector
POST: 192.168.56.102:8083/connectors
raw:
{
"name": "inventory",
"config": {
"connector.class": "io.debezium.connector.postgresql.PostgresConnector",
"tasks.max": "1",
"database.hostname": "192.168.56.103",
"database.port": "5435",
"database.dbname": "postgres",
"hstore.handling.mode":"json",
"database.user": "postgres",
"database.password": "postgres",
"database.server.name" : "server-name",
"plugin.name":"pgoutput"
}
}
3.get the status of connectors
GET : 192.168.56.102:8083/connectors/inventory/status