写在前面
前段时间在实时获取SQLServer数据库变化时候,整个过程可谓是坎坷。然后就想在这里记录一下。
本文的技术栈: Debezium SQL Server Source Connector+Kafka+Spark+MySQL
ps:后面应该会将数据放到Kudu上。
然后主要记录一下,整个组件使用和组件对接过程中一些注意点和坑。
开始吧
在处理实时数据时,需要即时地获得数据库表中数据的变化,然后将数据变化发送到Kafka中。不同的数据库有不同的组件进行处理。
常见的MySQL数据库,就有比较多的支持 canal ,maxwell等,他们都是类似 MySQL binlog 增量订阅&消费组件这种模式 。那么关于微软的SQLServer数据库,好像整个开源社区 支持就没有那么好了。
1.选择Connector
Debezium的SQL Server连接器是一种源连接器,可以获取SQL Server数据库中现有数据的快照,然后监视和记录对该数据的所有后续行级更改。每个表的所有事件都记录在单独的Kafka Topic中,应用程序和服务可以轻松使用它们。然后本连接器也是基于MSSQL的change data capture实现。
2.安装Connector
我参照官方文档安装是没有问题的。
2.1 Installing Confluent Hub Client
Confluent Hub客户端本地安装为Confluent Platform的一部分,位于/ bin目录中。
Linux
Download and unzip the Confluent Hub tarball.
[root@hadoop001 softs]# ll confluent-hub-client-latest.tar
-rw-r--r--. 1 root root 6909785 9月 24 10:02 confluent-hub-client-latest.tar
[root@hadoop001 softs]# tar confluent-hub-client-latest.tar -C ../app/conn/
[root@hadoop001 softs]# ll ../app/conn/
总用量 6748
drwxr-xr-x. 2 root root 27 9月 24 10:43 bin
-rw-r--r--. 1 root root 6909785 9月 24 10:02 confluent-hub-client-latest.tar
drwxr-xr-x. 3 root root 34 9月 24 10:05 etc
drwxr-xr-x. 2 root root 6 9月 24 10:08 kafka-mssql
drwxr-xr-x. 4 root root 29 9月 24 10:05 share
[root@hadoop001 softs]#
配置bin目录到系统环境变量中
export CONN_HOME=/root/app/conn
export PATH=$CONN_HOME/bin:$PATH
确认是否安装成功
[root@hadoop001 ~]# source /etc/profile
[root@hadoop001 ~]# confluent-hub
usage: confluent-hub <command> [ <args> ]
Commands are:
help Display help information
install install a component from either Confluent Hub or from a local file
See 'confluent-hub help <command>' for more information on a specific command.
[root@hadoop001 ~]#
2.2 Install the SQL Server Connector
使用命令confluent-hub
[root@hadoop001 ~]# confluent-hub install debezium/debezium-connector-sqlserver:0.9.4
The component can be installed in any of the following Confluent Platform installations:
1. / (installed rpm/deb package)
2. /root/app/conn (where this tool is installed)
Choose one of these to continue the installation (1-2): 2
Do you want to install this into /root/app/conn/share/confluent-hub-components? (yN) n
Specify installation directory: /root/app/conn/share/java/confluent-hub-client
Component's license:
Apache 2.0
https://github.com/debezium/debezium/blob/master/LICENSE.txt