Debeziumを使用したPostgreSQLCDC Kafka

  1. 安装JDK
    - #タールzxvfのjdk-8u281-linuxの-x64.tar.gz -Cは/ opt /
    - #viのは/ etc / profile
    - ####飼育係####
    輸出JAVA_HOME =は/ opt / jdk1.8.0_281
    輸出CLASSPATH = $ JAVA_HOME / jre / lib:$ JAVA_HOME / lib
    export PATH = $ JAVA_HOME / bin:$ PATH

-#source / etc / profile-
#java -version
java version "1.8.0_281"
Java(TM)SEランタイム環境(ビルド1.8.0_281-b09)
Java HotSpot(TM)64ビットサーバーVM(ビルド25.281-b09、混合モード)
-#

  1. 安装Kafka

-#tar zxvf kafka_2.13-2.7.0.tgz -C / opt /
-#cd /opt/kafka_2.13-2.7.0/config

-#vi / etc / profile

-####
zookeeper #### export JAVA_HOME = / opt / jdk1.8.0_281
export KAFKA_HOME = / opt / kafka_2.13-2.7.0
export CLASSPATH = $ JAVA_HOME / jre / lib:$ JAVA_HOME / lib:$ KAFKA_HOME / lib
export PATH = $ KAFKA_HOME / bin:$ JAVA_HOME / bin:$ PATH

-####
启PINzookeeper ##### -#cd /opt/kafka_2.13-2.7.0/-#nohup
bin / zookeeper-server-start.sh config / zookeeper.properties

-####
启PXkafka ##### -#nohup bin / kafka-server-start.sh config / server.properties&

-###创建トピック###
-#kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topictest
作成されたトピックテスト。
-#

- ###显示トピック###
- #kafka-topics.sh -list -zookeeperはlocalhost:2181
のテスト
- #


kafkaプロデューサーを作成します。-#kafka-console-producer.sh --broker-list localhost:9092 --topic test

こんにちは
test_msg
test_topic


kafkaコンシューマーを作成します。-#kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
hello
test_msg
test_topic

説明:
-broker-list:デフォルトのポートは9092です。自分で変更できます

  1. データベースの準備

postgres =#レプリケーションパスワード 'sync_user'でユーザーsync_userを作成します。
postgres =#スーパーユーザーでユーザーsync_userを変更します;
postgres =#データベースtdb01を作成します。
CREATE DATABASE
postgres =#CREATE TABLE Customers(
id SERIAL、
first_name VARCHAR(255)NOT NULL、
last_name VARCHAR(255)NOT NULL、
email VARCHAR(255)NOT NULL、
PRIMARY KEY(id)
);

pg_hba.conf

-#タイプデータベースのユーザーアドレス方式

-#「ローカル」はUnixドメインソケット接続専用です
ローカルすべてすべて信頼
-#IPv4ローカル接続:
ホストすべてすべて127.0.0.1 / 32信頼
ホストすべてすべて0.0.0.0/0 md5-
#IPv6ローカル接続:
ホストすべてすべて: :1/128 trust
-#
-#レプリケーション権限を持つユーザーによるローカルホストからのレプリケーション接続を許可します
ローカルレプリケーションすべて信頼
ホストレプリケーションすべて127.0.0.1/32信頼
ホストレプリケーションすべて192.168.1.0/24md5
$

-###構成ファイルの変更####
$ vi postgresql.conf
wal_level =論理
#max_wal_senders = 10
#max_replication_slots = 10

-####データベースの再起動####
$ pg_ctl stop –D / pgdata
$ pg_ctl start –D / pgdata

  1. 接続の構成とインストール

-#tar zxvf debezium-connector-postgres-1.4.1.Final-plugin.tar.gz -C / opt /
-#cd / opt / debezium-connector-postgres /
-#cp * .jar /opt/kafka_2.13 -2.7.0 / libs /
-#cd /opt/kafka_2.13-2.7.0/config-#vi
kafka-postgres.properties
name = postgres-connector
Connector.class = io.debezium.connector.postgresql.PostgresConnector
データベース。 hostname = 192.168.1.141
database.port = 5432
database.user = sync_user
database.password = sync_user
database.dbname = tdb01
database.server.name = tdb01
plugin.name = pgoutput
table.whitelist =
errors.log.enable = true
エラー。 logs.include.messages = true-

  1. データベース挿入データテスト

-####データベース库端####
postgres =#\ c tdb01
tdb01 =#customers(first_name、last_name、email)の値( 'he'、 'mia'、 '[email protected]');に挿入します。
INSERT 0 1
tdb01 =#

-#### kafka端 #####

-#kafka-topics.sh -list -zookeeper localhost:2181
tdb01.public.customers-
#kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic tdb01.public.customers --from-beginning
{"schema":{"type": "struct"、 "fields":[{"type": "struct"、 "fields":[{"type": "int32"、 "optional":false、 "field ":" id "}、{" type ":" string "、" options ":false、" field ":" first_name "}、{" type ":" string "、" optional ":false、" field ": "last_name"}、{"type": "string"、 "optional":false、 "field": "email"}]、 "optional":true、 "name": "tdb01.public.customers.Value"、 "field": "before"}、{"type": "struct"、 "fields":[{"type": "int32"、 "optional":false、 "field": "id"}、{"type ":"ストリング"、"optional":false、 "field": "first_name"}、{"type": "string"、 "optional":false、 "field": "last_name"}、{"type": "string"、 "optional ":false、" field ":" email "}]、" options ":true、" name ":" tdb01.public.customers.Value "、" field ":" after "}、{" 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 "、" options ":false、" field ":" db "}、{" type " : "string"、 "optional":false、 "field": "schema"}、{"type": "string"、 "optional":false、 "field": "table"}、{"type": " int64 "、" optional ":true、" field ":" txId "}、{" type ":" int64 "、" optional ":true、" field ":" lsn "}、{" type ":" int64 " 、 "オプション":true、 "field ":" xmin "}]、" optional ":false、" name ":" io.debezium.connector.postgresql.Source "、" field ":" source "}、{" type ":" string "、"オプション ":false、"フィールド ":" op "}、{"タイプ ":" int64 "、"オプション ":true、"フィールド ":" ts_ms "}、{"タイプ ":"構造体 "、"フィールド " :[{"type": "string"、 "optional":false、 "field": "id"}、{"type": "int64"、 "optional":false、 "field": "total_order"}、 {"type": "int64"、 "optional":false、 "field": "data_collection_order"}]、 "optional":true、 "field": "transaction"}]、 "optional":false、 "name" : "tdb01.public.customers.Envelope "}、" payload ":{" before ":null、" after ":{" id ":1、" first_name ":" he "、" last_name ":" mia "、" email ":" [email protected] "}、" source ":{" version ":" 1.4.1.Final "、" connector ":" postgresql "、" name ":" tdb01 "、" ts_ms ":1612544437937、 "snapshot": "false"、 "db": "tdb01"、 "schema": "public"、 "table": "customers"、 "txId":493、 "lsn":23092184、 "xmin":null} 、 "op": "c"、 "ts_ms":1612515639176、 "transaction":null}}first_name ":" he "、" last_name ":" mia "、" email ":" [email protected] "}、" source ":{" version ":" 1.4.1.Final "、" connector ":" postgresql "、" name ":" tdb01 "、" ts_ms ":1612544437937、" snapshot ":" false "、" db ":" tdb01 "、" schema ":" public "、" table ":" customers "、" txId ":493、" lsn ":23092184、" xmin ":null}、" op ":" c "、" ts_ms ":1612515639176、" transaction ":null}}first_name ":" he "、" last_name ":" mia "、" email ":" [email protected] "}、" source ":{" version ":" 1.4.1.Final "、" connector ":" postgresql "、" name ":" tdb01 "、" ts_ms ":1612544437937、" snapshot ":" false "、" db ":" tdb01 "、" schema ":" public "、" table ":" customers "、" txId ":493、" lsn ":23092184、" xmin ":null}、" op ":" c "、" ts_ms ":1612515639176、" transaction ":null}}ts_ms ":1612544437937、" snapshot ":" false "、" db ":" tdb01 "、" schema ":" public "、" table ":" Customers "、" txId ":493、" lsn ":23092184、" xmin ":null}、" op ":" c "、" ts_ms ":1612515639176、" transaction ":null}}ts_ms ":1612544437937、" snapshot ":" false "、" db ":" tdb01 "、" schema ":" public "、" table ":" Customers "、" txId ":493、" lsn ":23092184、" xmin ":null}、" op ":" c "、" ts_ms ":1612515639176、" transaction ":null}}

おすすめ

転載: blog.51cto.com/heyiyi/2621287