这两天在空余时间实践了下debezium监控mysql,虽然最后就差一步,也还是记录下
实践环境:
centos 8 1.6G内存
mysql 5.7
zookeeper 3.5.6
kafka 2.4.1
debezium-connector-mysql 1.2.5 Final
请先安装Mysql zookeeper(看kafka版本) kafka debezium-connector,最好顺序安装吧
安装mysql不用多说,需要有一个可以访问binlog的用户
安装kafka也不用多说,网上教程很多
安装并配置debezium connector也不麻烦,可以参考 CDC系列(三)、Debezium 监控MySQL *** 作日志实时同步到Kafka(对比canal,maxwell)_王义凯 的博客-CSDN博客_debezium mysql
连接器配置参数官方说明Debezium Connector for MySQL :: Debezium documentationz
注意:database.history.kafka.topic指定的topic应实际存在,提前创建好
启动zookeeper
-daemon以后台进程启动kafka,默认是9092端口,创建topic,测试生产和消费消息没问题
启动debezium connector,cpu当时飙升
启动好像成功了
系统负载,好像是有点高
踩的坑:
1.创建topic失败。kafka replication factor 1 larger than avaiable brokers 1
排查到后面找到原因是因为没装zookeeper,kafka 2.8.0版本及以上不用单独装zookeeper,kafka和zookeeper版本对应可以参考
不过这个问题也可能有其它原因,遇到再实际排查
2.debezium-connector启动不起来
错误1 已解决
Failed to find any class that implements Connector and which name matches io.debezium.connector.mysql.MySqlConnector
解压jar包
发现明显有啊
难道是版本不匹配?查了下好像也没找到说有一定的版本对应关系,后面发现plugin文件夹指定不对:plugin.path一定要是jar包所在的文件夹
错误2 no class def 一波三折 已解决
结果真没有,我都要哭了
从maven上下了1.2.5.Final jar包看到替换后还是不行,当时官网地址Debezium Release Series 1.2 download那里点击一直脚本报错,我真是无语,后来从maven库Central Repository: io/debezium/debezium-connector-mysql
这里下的,最后实在没办法,在官网再试试,又能download了,当时一万只草泥马,再启动没有no class def问题,又有新的问题
错误3 启动后发现服务器卡了,直接动不了 未解决
然后发现debezium mysql的配置文件不对,要命名为connect-xxx.properties,因为其它配置 也是那么命名的
另外jvm配置要根据实际情况来 -Xms256M, -Xmx2G对于我这太大了,后面也没调整好。当时应该注意一下单纯启动kafka时jvm的情况。
服务器重启后top看负载,发现有click house,之前装的,统统停了,特么还是一启动connentor就卡死,无报错。
3.服务器卡死,连不上。DefaultAuthFuture[ssh-connection]: Failed to get operation result within specified timeout: 30000
没找到很好的办法,估计和装了桌面有关,真不应该装,只能重启。
还有这种
也是重启解决
建议没事不要给服务起装桌面,可能会导致服务器卡 当时是装了kafka eadge有图形化界面查看和进行kafka *** 作,后面发现没啥用,命令行也还好
最后一次搞服务器了,前后搞了7个多小时,期间服务器重启了不下10次,每次6-7分钟,心累,实在是服务器内存有点小又没设置好connector启动jvm,最后没搞好,有些遗憾,代码层面更做不了了。再见了我的云服务器,凌晨已过期
其实也可以充钱,但是好贵不想充,回想起来也没怎么好好利用,实在有些遗憾,2020年12月28号买的,当时是双12价,才186,算下来一天5毛多一点,算是好便宜了
成功的话,会给每个表创建topic,topic名称以database.server.name配置为前缀。我这边配置的database.server.name是zhazha,监控testdb库,testdb库就一张表collective_economy_project,
那连接器会创建形如zhazha.testdb.collective_economy_project
dml和ddl后database.history.kafka.topic指定的topic会收到消息,形如:
{"schema":{"type":"struct","fields":[{"type":"struct","fields":[{"type":"string","optional":false,"field":"version"},{"type":"string","optional":false,"field":"connector"},{"type":"string","optional":false,"field":"name"},{"type":"int64","optional":false,"field":"ts_ms"},{"type":"string","optional":true,"name":"io.debezium.data.Enum","version":1,"parameters":{"allowed":"true,last,false"},"default":"false","field":"snapshot"},{"type":"string","optional":false,"field":"db"},{"type":"string","optional":true,"field":"table"},{"type":"int64","optional":false,"field":"server_id"},{"type":"string","optional":true,"field":"gtid"},{"type":"string","optional":false,"field":"file"},{"type":"int64","optional":false,"field":"pos"},{"type":"int32","optional":false,"field":"row"},{"type":"int64","optional":true,"field":"thread"},{"type":"string","optional":true,"field":"query"}],"optional":false,"name":"io.debezium.connector.mysql.Source","field":"source"},{"type":"string","optional":false,"field":"databaseName"},{"type":"string","optional":false,"field":"ddl"}],"optional":false,"name":"io.debezium.connector.mysql.SchemaChangevalue"},"payload":{"source":{"version":"1.2.2.Final","connector":"mysql","name":"wyk_sandbox","ts_ms":1601016725000,"snapshot":"false","db":"testschema","table":"wyk_csdn","server_id":1,"gtid":null,"file":"mysql-bin.000016","pos":93212,"row":0,"thread":null,"query":null},"databaseName":"testschema","ddl":"createtablewyk_csdn(idint,namevarchar(20),ins_tstimestamp)"}}
感兴趣的可以试试
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)