同步其他DB数据到ClickHouse,目前支持postgres和mysql,支持full和increment ETL。
项目描述
同步
介绍
同步其他DB数据到ClickHouse,目前支持postgres和mysql,支持full和increment ETL。
特征
- 完整数据 etl 和实时增量 etl。
- 支持 DDL 和 DML 同步,当前支持DDL 的
add column和drop column和change column,也完全支持 DML。 - 电子邮件错误报告。
- 支持 kafka 和 redis 作为 broker。
- 多源db同时同步到ClickHouse。
- 支持 ClickHouse
MergeTree,CollapsingMergeTree,VersionedCollapsingMergeTree,ReplacingMergeTree. - 支持 ClickHouse 集群。
要求
- 蟒蛇> = 3.7
- redis,缓存mysql binlog文件和位置,作为broker,也支持redis集群。
- kafka,如果您使用 kafka 作为代理,则需要。
- clickhouse-jdbc-bridge,如果您使用 postgres 和 set
auto_full_etl = true或 execsynch etl命令,则需要。
安装
> pip install synch
用法
配置文件synch.yaml
同步将从中读取默认配置./synch.yaml,或者您可以使用synch -c指定配置文件。
请参阅 中的完整示例配置synch.yaml。
完整数据等
也许您需要在将数据从 MySQL 连续同步到 ClickHouse 或重做数据 etl 之前制作完整的数据 etl --renew。
> synch --alias mysql_db etl -h
Usage: synch etl [OPTIONS]
Make etl from source table to ClickHouse.
Options:
--schema TEXT Schema to full etl.
--renew Etl after try to drop the target tables.
-t, --table TEXT Tables to full etl.
-h, --help Show this message and exit.
表中的完整 etl test.test:
> synch --alias mysql_db etl --schema test --table test --table test2
生产
监听所有 MySQL binlog 并生成到 broker。
> synch --alias mysql_db produce
消耗
使用来自代理的消息并插入到 ClickHouse,您可以使用 跳过错误行--skip-error。在配置中设置时,同步首先会执行完整的 etl auto_full_etl = true。
> synch --alias mysql_db consume -h
Usage: synch consume [OPTIONS]
Consume from broker and insert into ClickHouse.
Options:
--schema TEXT Schema to consume. [required]
--skip-error Skip error rows.
--last-msg-id TEXT Redis stream last msg id or kafka msg offset, depend on
broker_type in config.
-h, --help Show this message and exit.
使用模式test并插入ClickHouse:
> synch --alias mysql_db consume --schema test
监视器
设置true为core.monitoring,将自动创建数据库synch并ClickHouse插入监控数据。
表结构:
create table if not exists synch.log
(
alias String,
schema String,
table String,
num int,
type int, -- 1:producer, 2:consumer
created_at DateTime
)
engine = MergeTree partition by toYYYYMM
(
created_at
) order by created_at;
ClickHouse 表引擎
现在同步支持MergeTree, CollapsingMergeTree, VersionedCollapsingMergeTree, ReplacingMergeTree.
MergeTree, 默认常用选项。CollapsingMergeTree,请参阅CollapsingMergeTree中的详细信息。VersionedCollapsingMergeTree,请参阅VersionedCollapsingMergeTree中的详细信息 。ReplacingMergeTree,请参阅 ReplaceingMergeTree 中的详细信息。
使用 docker-compose(推荐)
Redis Broker,轻量级和低并发
version: "3"
services:
producer:
depends_on:
- redis
image: long2ice/synch
command: synch --alias mysql_db produce
volumes:
- ./synch.yaml:/synch/synch.yaml
# one service consume on schema
consumer.test:
depends_on:
- redis
image: long2ice/synch
command: synch --alias mysql_db consume --schema test
volumes:
- ./synch.yaml:/synch/synch.yaml
redis:
hostname: redis
image: redis:latest
volumes:
- redis
volumes:
redis:
Kafka Broker,用于高并发
version: "3"
services:
zookeeper:
image: bitnami/zookeeper:3
hostname: zookeeper
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
volumes:
- zookeeper:/bitnami
kafka:
image: bitnami/kafka:2
hostname: kafka
environment:
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
- JMX_PORT=23456
- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092
depends_on:
- zookeeper
volumes:
- kafka:/bitnami
kafka-manager:
image: hlebalbau/kafka-manager
ports:
- "9000:9000"
environment:
ZK_HOSTS: "zookeeper:2181"
KAFKA_MANAGER_AUTH_ENABLED: "false"
command: -Dpidfile.path=/dev/null
producer:
depends_on:
- redis
- kafka
- zookeeper
image: long2ice/synch
command: synch --alias mysql_db produce
volumes:
- ./synch.yaml:/synch/synch.yaml
# one service consume on schema
consumer.test:
depends_on:
- redis
- kafka
- zookeeper
image: long2ice/synch
command: synch --alias mysql_db consume --schema test
volumes:
- ./synch.yaml:/synch/synch.yaml
redis:
hostname: redis
image: redis:latest
volumes:
- redis:/data
volumes:
redis:
kafka:
zookeeper:
重要的
- 您需要始终保留没有空主键或复合主键的主键或唯一键。
- DDL 同步不支持 postgres。
- Postgres 同步尚未完全测试,请小心在生产中使用它。
谢谢
来自Jetbrains的强大 Python IDE Pycharm。
执照
该项目在Apache-2.0许可下获得许可。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
synch-0.7.2.tar.gz
(26.2 kB
查看哈希)
内置分布
synch-0.7.2-py3-none-any.whl
(39.4 kB
查看哈希)