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 中的三种删除方式1.DELETE语句✅ 基本语法: 示例:2.TRUNCATE语句✅ 基本语

MySQL中查找重复值的实现

《MySQL中查找重复值的实现》查找重复值是一项常见需求,比如在数据清理、数据分析、数据质量检查等场景下,我们常常需要找出表中某列或多列的重复值,具有一定的参考价值,感兴趣的可以了解一下... 目录技术背景实现步骤方法一:使用GROUP BY和HAVING子句方法二:仅返回重复值方法三:返回完整记录方法四:

从入门到精通MySQL联合查询

《从入门到精通MySQL联合查询》:本文主要介绍从入门到精通MySQL联合查询,本文通过实例代码给大家介绍的非常详细,需要的朋友可以参考下... 目录摘要1. 多表联合查询时mysql内部原理2. 内连接3. 外连接4. 自连接5. 子查询6. 合并查询7. 插入查询结果摘要前面我们学习了数据库设计时要满

MySQL查询JSON数组字段包含特定字符串的方法

《MySQL查询JSON数组字段包含特定字符串的方法》在MySQL数据库中,当某个字段存储的是JSON数组,需要查询数组中包含特定字符串的记录时传统的LIKE语句无法直接使用,下面小编就为大家介绍两种... 目录问题背景解决方案对比1. 精确匹配方案(推荐)2. 模糊匹配方案参数化查询示例使用场景建议性能优

mysql表操作与查询功能详解

《mysql表操作与查询功能详解》本文系统讲解MySQL表操作与查询,涵盖创建、修改、复制表语法,基本查询结构及WHERE、GROUPBY等子句,本文结合实例代码给大家介绍的非常详细,感兴趣的朋友跟随... 目录01.表的操作1.1表操作概览1.2创建表1.3修改表1.4复制表02.基本查询操作2.1 SE

MySQL中的锁机制详解之全局锁,表级锁,行级锁

《MySQL中的锁机制详解之全局锁,表级锁,行级锁》MySQL锁机制通过全局、表级、行级锁控制并发,保障数据一致性与隔离性,全局锁适用于全库备份,表级锁适合读多写少场景,行级锁(InnoDB)实现高并... 目录一、锁机制基础:从并发问题到锁分类1.1 并发访问的三大问题1.2 锁的核心作用1.3 锁粒度分

MySQL数据库中ENUM的用法是什么详解

《MySQL数据库中ENUM的用法是什么详解》ENUM是一个字符串对象,用于指定一组预定义的值,并可在创建表时使用,下面:本文主要介绍MySQL数据库中ENUM的用法是什么的相关资料,文中通过代码... 目录mysql 中 ENUM 的用法一、ENUM 的定义与语法二、ENUM 的特点三、ENUM 的用法1

MySQL count()聚合函数详解

《MySQLcount()聚合函数详解》MySQL中的COUNT()函数,它是SQL中最常用的聚合函数之一,用于计算表中符合特定条件的行数,本文给大家介绍MySQLcount()聚合函数,感兴趣的朋... 目录核心功能语法形式重要特性与行为如何选择使用哪种形式?总结深入剖析一下 mysql 中的 COUNT

mysql中的服务器架构详解

《mysql中的服务器架构详解》:本文主要介绍mysql中的服务器架构,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、背景2、mysql服务器架构解释3、总结1、背景简单理解一下mysqphpl的服务器架构。2、mysjsql服务器架构解释mysql的架

MySQL之InnoDB存储引擎中的索引用法及说明

《MySQL之InnoDB存储引擎中的索引用法及说明》:本文主要介绍MySQL之InnoDB存储引擎中的索引用法及说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录1、背景2、准备3、正篇【1】存储用户记录的数据页【2】存储目录项记录的数据页【3】聚簇索引【4】二