mysql-Synch-clickhouse

2024-03-01 17:36

本文主要是介绍mysql-Synch-clickhouse,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Synch

GitHub - long2ice/synch: Sync data from the other DB to ClickHouse(cluster)

 环境:

mysql5.7

redis >= 5.0

clickhouse21.2

postgresql

python3

binlog_format=row

XREAD

default

pg_config      

synch

1:安装clickhouse

rpm下载地址:

https://repo.yandex.ru/clickhouse/rpm/stable/x86_6

安装:rpm -ivh ./*.rpm

配置:

/etc/clickhouse-server/config.xml
/etc/clickhouse-server/users.xml

服务:

systemctl start clickhouse-server

 客户端:

clickhouse-client

2:安装Python3

系统默认: Python 2.7.5

安装:pip

yum -y install epel-release

yum install python-pip

pip --version

下载安装

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz

cd Python-3.7.0
./configure --prefix=/usr/local/python3 --enable-shared --enable-optimizations
make

make install

环境变量

/etc/profile

export PYTHON_HOME=/usr/local/python3

export PATH=$PYTHON_HOME/bin:$PATH

异常及处理:
/usr/local/python3/bin/python3.7: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory

将python库的路径写到/etc/ld.so.conf配置中

vim /etc/ld.so.conf.d/python3.conf
/usr/local/python3/lib
ldconfig

升级pip

3:安装synch

pip3 install synch

安装异常:

需要安装:PostgreSQL,

yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

yum install -y postgresql13-server

yum install postgresql-devel

psql --version

配置环境变量:

/usr/pgsql-13/bin/pg_config

export PATH=$PATH:/usr/pgsql-13/bin

安装成功:

查看synch

配置synch.yaml
core:debug: true # when set True, will display sql information.insert_num: 1 # how many num to submit,recommend set 20000 when productioninsert_interval: 1 # how many seconds to submit,recommend set 60 when production# enable this will auto create database `synch` in ClickHouse and insert monitor datamonitoring: truesentry:environment: developmentdsn:redis:host: 127.0.0.1port: 6379db: 0password:prefix: synchqueue_max_len: 200000 # stream max len, will delete redundant ones with FIFOsource_dbs:- db_type: mysqlalias: mysql_db # must be uniquebroker_type: redis # current support redis and kafkaserver_id: 3host: 127.0.0.1port: 3306user: rootpassword: "123456"# optional, auto get from `show master status` when emptyinit_binlog_file:# optional, auto get from `show master status` when emptyinit_binlog_pos:skip_dmls: alert # dmls to skipskip_delete_tables: # tables skip delete, format with schema.tableskip_update_tables: # tables skip update, format with schema.tabledatabases:- database: crm# optional, default true, auto create database when database in clickhouse not existsauto_create: truetables:- table: user_log# optional, default false, if your table has decimal column with nullable, there is a bug with full data etl will, see https://github.com/ClickHouse/ClickHouse/issues/7690.skip_decimal: false # set it true will replace decimal with string type.# optional, default trueauto_full_etl: true # auto do full etl at first when table not exists# optional, default ReplacingMergeTreeclickhouse_engine: ReplacingMergeTree # current support MergeTree, CollapsingMergeTree, VersionedCollapsingMergeTree, ReplacingMergeTree# optionalpartition_by: # Table create partitioning by, like toYYYYMM(created_at).# optionalsettings: # Table create settings, like index_granularity=8192# optionalsign_column: sign # need when clickhouse_engine=CollapsingMergeTree and VersionedCollapsingMergeTree, no need real in source db, will auto generate in clickhouse# optionalversion_column: # need when clickhouse_engine=VersionedCollapsingMergeTree and ReplacingMergeTree(optional), need real in source db, usually is `updated_at` with auto update.- table: deptinfo- table: userclickhouse:hosts:- 127.0.0.1:9000user: defaultpassword: ''cluster_name: #perftest_3shards_1replicasdistributed_suffix: ###_all # distributed tables suffix, available in cluster#kafka:
#  servers:
#    - kafka:9092
#  topic_prefix: synch# enable this to send error report, comment or delete these if not.
mail:mailhost: smtp.gmail.comfromaddr: long2ice@gmail.comtoaddrs:- long2ice@gmail.comuser: long2ice@gmail.compassword: "123456"subject: "[synch] Error logging report"

4:测试

1:create 。。 if not exists

synch -c /etc/synch.yaml --alias mysql_db etl --schema crm --table user

2:生产

监听源库并将变动数据写入消息队列。

synch --alias mysql_db produce

3:消费

从消息队列中消费数据并插入 ClickHouse,使用 --skip-error跳过错误消息。 配置 auto_full_etl = True 的时候会首先尝试做一次全量复制。

消费数据库 crm 并插入到ClickHouse

synch --alias mysql_db consume --schema crm

5:安装supervisord守护进程

yum install supervisor

配置
[program:mysql-to-ck-produce]
process_name=%(program_name)s
command=/usr/local/python3/bin/synch -c /etc/synch.yaml --alias mysql_db produce
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stdout_logfile_maxbytes=2048MB
stdout_logfile_backups=20
stopwaitsecs=3600[program:mysql-to-ck-consume-crm]
process_name=%(program_name)s
command=/usr/local/python3/bin/synch -c /etc/synch.yaml --alias mysql_db consume --schema crm
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stdout_logfile_maxbytes=2048MB
stdout_logfile_backups=20
stopwaitsecs=3600
服务:

systemctl restart supervisord

日志:

/var/log/supervisor

mysql-to-ck-consume-crm.log mysql-to-ck-produce.log supervisord.log

这篇关于mysql-Synch-clickhouse的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/763251

相关文章

Mysql的主从同步/复制的原理分析

《Mysql的主从同步/复制的原理分析》:本文主要介绍Mysql的主从同步/复制的原理分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录为什么要主从同步?mysql主从同步架构有哪些?Mysql主从复制的原理/整体流程级联复制架构为什么好?Mysql主从复制注意

如何解决Druid线程池Cause:java.sql.SQLRecoverableException:IO错误:Socket read timed out的问题

《如何解决Druid线程池Cause:java.sql.SQLRecoverableException:IO错误:Socketreadtimedout的问题》:本文主要介绍解决Druid线程... 目录异常信息触发场景找到版本发布更新的说明从版本更新信息可以看到该默认逻辑已经去除总结异常信息触发场景复

MyBatis编写嵌套子查询的动态SQL实践详解

《MyBatis编写嵌套子查询的动态SQL实践详解》在Java生态中,MyBatis作为一款优秀的ORM框架,广泛应用于数据库操作,本文将深入探讨如何在MyBatis中编写嵌套子查询的动态SQL,并结... 目录一、Myhttp://www.chinasem.cnBATis动态SQL的核心优势1. 灵活性与可

MySQL 表的内外连接案例详解

《MySQL表的内外连接案例详解》本文给大家介绍MySQL表的内外连接,结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录表的内外连接(重点)内连接外连接表的内外连接(重点)内连接内连接实际上就是利用where子句对两种表形成的笛卡儿积进行筛选,我

MySQL的ALTER TABLE命令的使用解读

《MySQL的ALTERTABLE命令的使用解读》:本文主要介绍MySQL的ALTERTABLE命令的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、查看所建表的编China编程码格式2、修改表的编码格式3、修改列队数据类型4、添加列5、修改列的位置5.1、把列

Mybatis嵌套子查询动态SQL编写实践

《Mybatis嵌套子查询动态SQL编写实践》:本文主要介绍Mybatis嵌套子查询动态SQL编写方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言一、实体类1、主类2、子类二、Mapper三、XML四、详解总结前言MyBATis的xml文件编写动态SQL

解决mysql插入数据锁等待超时报错:Lock wait timeout exceeded;try restarting transaction

《解决mysql插入数据锁等待超时报错:Lockwaittimeoutexceeded;tryrestartingtransaction》:本文主要介绍解决mysql插入数据锁等待超时报... 目录报错信息解决办法1、数据库中执行如下sql2、再到 INNODB_TRX 事务表中查看总结报错信息Lock

MySQL启动报错:InnoDB表空间丢失问题及解决方法

《MySQL启动报错:InnoDB表空间丢失问题及解决方法》在启动MySQL时,遇到了InnoDB:Tablespace5975wasnotfound,该错误表明MySQL在启动过程中无法找到指定的s... 目录mysql 启动报错:InnoDB 表空间丢失问题及解决方法错误分析解决方案1. 启用 inno

MySQL 安装配置超完整教程

《MySQL安装配置超完整教程》MySQL是一款广泛使用的开源关系型数据库管理系统(RDBMS),由瑞典MySQLAB公司开发,目前属于Oracle公司旗下产品,:本文主要介绍MySQL安装配置... 目录一、mysql 简介二、下载 MySQL三、安装 MySQL四、配置环境变量五、配置 MySQL5.1

MySQL 添加索引5种方式示例详解(实用sql代码)

《MySQL添加索引5种方式示例详解(实用sql代码)》在MySQL数据库中添加索引可以帮助提高查询性能,尤其是在数据量大的表中,下面给大家分享MySQL添加索引5种方式示例详解(实用sql代码),... 在mysql数据库中添加索引可以帮助提高查询性能,尤其是在数据量大的表中。索引可以在创建表时定义,也可