kafka connect +debezium实时采集postgresql

该博客详细介绍了如何通过pgoutput插件设置PostgreSQL的逻辑复制,以及利用Kafka Connect和Debezium连接器将数据流式传输到Kafka。首先,修改postgresql.conf和pg_hba.conf文件以启用逻辑复制和设置权限。然后,为用户和表分配必要的权限。接着,配置Kafka Connect,包括放置jar包、重启服务和编写连接器配置JSON。最后,通过HTTP提交JSON并验证Kafka主题。这个过程对于实时数据管道和数据库变更捕获至关重要。

使用pgoutput的方式

设置postgresql

修改postgresql.conf添加或者修改以下字段

wal_level = logical            

max_wal_senders = 1            

max_replication_slots = 1      

修改pg_hba.conf

local   replication     <youruser>                          trust  

host    replication     <youruser>  127.0.0.1/32            trust  

host    replication     <youruser>  ::1/128                 trust

需要权限

表Select权限  GRANT SELECT on public.[table] to [user];

Publication 权限 ALTER USER test_dbz REPLICATION;

表的PUBLICATION 权限 CREATE PUBLICATION [publication_name] FOR TABLE [table1,table2](需要表的owner或者管理员)

配置kafka connect

1.将kafka connect的jar报放在plugn 目录(config/connect-distributed.properties的plugin.path)目录下

2.重启kafka connect

3.编写connect json

{
  "name": "postgres-connect",  
  "config": {
    "connector.class": "io.debezium.connector.postgresql.PostgresConnector", 
    "database.hostname": "ip", 
    "database.port": "5432", 
    "database.user": "user", 
    "database.password": "pass", 
    "database.dbname" : "test_owner", 
    "database.server.name": "postgres-test-owner", 
    "table.include.list": "public.test1,public.test2,public.test3",
    "publication.autocreate.mode":"filtered",
    "plugin.name":"pgoutput",
  }
}

4.post 提交json 到http://ip:8083/connectors

5.查看kafka topic postgres-test-owner.public.test1

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值