大数据 - ClickHouse

数据,clickhouse · 浏览次数 : 200

小编点评

生成内容时需要带简单的排版,例如: * 生成用户配置时,需要带排版用户目录格式。 * 生成数据配置时,需要带排版数据路径格式。 * 生成日志配置时,需要带排版日志格式。 以下是一些生成用户配置时,需要带排版用户目录格式的例子: ``` /nonexistent/user/name/directory /nonexistent/user/name/directory/user/name/directory /nonexistent/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory/user/name/directory

正文

https://clickhouse.com/

概念

ClickHouse 是俄罗斯的 Yandex 于 2016 年开源的列式存储数据库(DBMS),使用 C++语言编写,主要用于在线分析处理查询(OLAP),能够使用 SQL 查询实时生成分析数据报告。
OLAP:一次写入,多次读取

ClickHouse凭借着其出色的分析查询性能,尤其是在日志处理上的优势,非常有效的解决了关系型数据库在海量数据场景下的分析查询短板问题

ClickHouse 的特点

Id Name Age
1 张三 18
2 李四 22
3 王五 34

采用行式存储时,数据在磁盘上的组织结构为:

1 张三 18 2 李四 22 3 王五 34
好处是想查某个人所有的属性时,可以通过一次磁盘查找加顺序读取就可以。但是当想查所有人的年龄时,需要不停的查找,或者全表扫描才行,遍历的很多数据都是不需要的。

采用列式存储时,数据在磁盘上的组织结构为:

1 2 3 张三 李四 王五 18 22 34
这时想查所有人的年龄只需把年龄那一列拿出来就可以了

列式储存的好处:

  • 方便聚合,对于列的聚合,计数,求和等统计操作原因优于行式存储。
  • 由于某一列的数据类型都是相同的,针对于数据存储更容易进行数据压缩,每一列选择更优的数据压缩算法,大大提高了数据的压缩比重。
  • 由于数据压缩比更好,一方面节省了磁盘空间,另一方面对于 cache 也有了更大的发挥空间。

DBMS 的功能
几乎覆盖了标准 SQL 的大部分语法,包括 DDL 和 DML,以及配套的各种函数,用户管理及权限管理,数据的备份与恢复。

多样化引擎
ClickHouse 和 MySQL 类似,把表级的存储引擎插件化,根据表的不同需求可以设定
不同的存储引擎。目前包括合并树、日志、接口和其他四大类 20 多种引擎。

高吞吐写入能力
ClickHouse 采用类 LSM Tree 的结构,数据写入后定期在后台 Compaction。通过类 LSM tree 的结构,ClickHouse 在数据导入时全部是顺序 append 写,写入后数据段不可更改,在后台 compaction 时也是多个段 merge sort 后顺序写回磁盘。顺序写的特性,充分利用了磁盘的吞吐能力,即便在 HDD 上也有着优异的写入性能。
官方公开 benchmark 测试显示能够达到 50MB-200MB/s 的写入吞吐能力,按照每行 100Byte 估算,大约相当于 50W-200W 条/s 的写入速度。

数据分区与线程级并行
ClickHouse 将数据划分为多个 partition,每个 partition 再进一步划分为多个 index granularity(索引粒度),然后通过多个 CPU 核心分别处理其中的一部分来实现并行数据处理。在这种设计下,单条 Query 就能利用整机所有 CPU。极致的并行处理能力,极大的降低了查询延时。
所以,ClickHouse 即使对于大量数据的查询也能够化整为零平行处理。但是有一个弊端就是对于单条查询使用多 cpu,就不利于同时并发多条查询。所以对于高 QPS(Queries Per Second 每秒查询率) 的查询业务,ClickHouse 并不是强项

性能对比
单表查询
image
关联查询
image
结论: ClickHouse 像很多 OLAP 数据库一样,单表查询速度由于关联查询,而且ClickHouse 的两者差距更为明显。

安装

https://clickhouse.com/docs/en/install/

[root@VipSoft clickhouse]# pwd
/opt/clickhouse
# 下载安装程序
[root@VipSoft clickhouse]# curl https://clickhouse.com/ | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2473    0  2473    0     0   1514      0 --:--:--  0:00:01 --:--:--  1515

Will download https://builds.clickhouse.com/master/amd64/clickhouse into clickhouse

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  502M  100  502M    0     0  5262k      0  0:01:37  0:01:37 --:--:-- 6022k

Successfully downloaded the ClickHouse binary, you can run it as:
    ./clickhouse

You can also install it:
    sudo ./clickhouse install
# 设置权限
[root@VipSoft clickhouse]# chmod -R 775 ./
[root@VipSoft clickhouse]# ll
total 4447904
-rwxrwxr-x 1 root root 2147479552 Dec 30 13:46 clickhouse
[root@VipSoft clickhouse]# ./clickhouse install
Copying ClickHouse binary to /usr/bin/clickhouse.new
Renaming /usr/bin/clickhouse.new to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-server to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-client to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-local to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-benchmark to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-copier to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-obfuscator to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-git-import to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-compressor to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-format to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-extract-from-config to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper-converter to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-disks to /usr/bin/clickhouse.
Creating clickhouse group if it does not exist.
 groupadd -r clickhouse
Creating clickhouse user if it does not exist.
 useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse clickhouse
Will set ulimits for clickhouse user in /etc/security/limits.d/clickhouse.conf.
Creating config directory /etc/clickhouse-server.
Creating config directory /etc/clickhouse-server/config.d that is used for tweaks of main server configuration.
Creating config directory /etc/clickhouse-server/users.d that is used for tweaks of users configuration.
Data path configuration override is saved to file /etc/clickhouse-server/config.d/data-paths.xml.
Log path configuration override is saved to file /etc/clickhouse-server/config.d/logger.xml.
User directory path configuration override is saved to file /etc/clickhouse-server/config.d/user-directories.xml.
OpenSSL path configuration override is saved to file /etc/clickhouse-server/config.d/openssl.xml.
Creating log directory /var/log/clickhouse-server.
Creating data directory /var/lib/clickhouse.
Creating pid directory /var/run/clickhouse-server.
 chown -R clickhouse:clickhouse '/var/log/clickhouse-server'
 chown -R clickhouse:clickhouse '/var/run/clickhouse-server'
 chown  clickhouse:clickhouse '/var/lib/clickhouse'
Enter password for default user: 【输入密码】# 输入密码
Password for default user is saved in file /etc/clickhouse-server/users.d/default-password.xml.
Setting capabilities for clickhouse binary. This is optional.
Cannot set 'net_admin' or 'ipc_lock' or 'sys_nice' or 'net_bind_service' capability for clickhouse binary. This is optional. Taskstats accounting will be disabled. To enable taskstats accounting you may add the required capability later manually.
Allow server to accept connections from the network (default is localhost only), [y/N]: y # 允许外面访问
The choice is saved in file /etc/clickhouse-server/config.d/listen.xml.
 chown -R clickhouse:clickhouse '/etc/clickhouse-server'

ClickHouse has been successfully installed.

Start clickhouse-server with:
 sudo clickhouse start

Start clickhouse-client with:
 clickhouse-client --password
# 启动服务
[root@VipSoft clickhouse]# clickhouse start
 chown -R clickhouse: '/var/run/clickhouse-server/'
Will run sudo -u 'clickhouse' /usr/bin/clickhouse-server --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon
Waiting for server to start
Waiting for server to start
Waiting for server to start
Waiting for server to start
Waiting for server to start
Server started

客户端工具

DBeaver、NineData

与大数据 - ClickHouse相似的内容:

大数据 - ClickHouse

https://clickhouse.com/ 概念 ClickHouse 是俄罗斯的 Yandex 于 2016 年开源的列式存储数据库(DBMS),使用 C++语言编写,主要用于在线分析处理查询(OLAP),能够使用 SQL 查询实时生成分析数据报告。 OLAP:一次写入,多次读取 ClickH

大数据 - ADS 数据可视化实现

之前数据分层处理,最后把轻度聚合的结果保存到 ClickHouse 中,主要的目的就是提供即时的数据查询、统计、分析服务。这些统计服务一般会用两种形式展现,一种是为专业的数据分析人员的 BI 工具,一种是面向非专业人员的更加直观的数据大屏。 以下主要是面向百度的 sugar 的数据大屏服务的接口开发

Docker Compose V2 安装 ClickHouse v20.6.8.5 经验分享

前言 ClickHouse 是一款开源的分布式列式数据库管理系统,专门设计用于高性能的大数据分析和查询。 目前项目中用到的一个场景是将mongo的数据同步到clickhouse,使用clickhouse做报表,后续也将分享同步和使用方案 使用 Docker Compose 部署单机版,小项目和自己测

[转帖]一文快速入门 ClickHouse

https://zhuanlan.zhihu.com/p/621480049 什么是clickhouse ClickHouse是一种OLAP类型的列式数据库管理系统,这里有两个概念:OLAP、列式数据库。这两个概念会在接下来做介绍,ClickHouse完美的实现了OLAP和列式数据库的优势,因此在大

[大数据][机器学习]之Model Card(模型卡片)介绍

每当我们在公有云或者私有云发布训练好的大数据模型,为了方便大家辨识、理解和运用,参照huggingface所制定的标准制作一个Model Card展示页,是种非常好的模型展示和组织形式。 下面就是一个Model Card 的示例,我试着把它翻译成了中文,源网址,并且提供了Markdown的模板,供大

大数据面试SQL每日一题系列:最高峰同时在线主播人数。字节,快手等大厂高频面试题

大数据面试SQL每日一题系列:最高峰同时在线主播人数。字节,快手等大厂高频面试题 之后会不定期更新每日一题sql系列。 SQL面试题每日一题系列内容均来自于网络以及实际使用情况收集,如有雷同,纯属巧合。 1.题目 问题1:如下为某直播平台各主播的开播及关播时间数据明细,现在需要计算该平台最高峰期同时

大数据怎么学?对大数据开发领域及岗位的详细解读,完整理解大数据开发领域技术体系

经常有小伙伴和我咨询大数据怎么学,我觉得有必要写一下关于大数据开发的具体方向,下次就不用苦哈哈的打字回复了。直接回复文章。 1.大数据岗位划分 我们通常说的大数据开发主要分为三大方向: 1.1数据平台开发工程师 主要从事后端开发,结合Hadoop,flink,spark等做二次开发,基于底层框架开发

孙荣辛|大数据穿针引线进阶必看——Google经典大数据知识

大数据技术的发展是一个非常典型的技术工程的发展过程,荣辛通过对于谷歌经典论文的盘点,希望可以帮助工程师们看到技术的探索、选择过程,以及最终历史告诉我们什么是正确的选择。 何为大数据 “大数据”这个名字流行起来到现在,差不多已经有十年时间了。在这十年里,不同的人都按照自己的需要给大数据编出了自己的解释

大数据-数据仓库-实时数仓架构分析

![image](https://img2023.cnblogs.com/blog/80824/202211/80824-20221128173125005-1682211493.png) ![image](https://img2023.cnblogs.com/blog/80824/202211/

大数据-业务数据采集-FlinkCDC

CDC CDC 是 Change Data Capture(变更数据获取)的简称。核心思想是,监测并捕获数据库的变动(包括数据或数据表的插入、更新以及删除等),将这些变更按发生的顺序完整记录下来,写入到消息中间件中以供其他服务进行订阅及消费。 CDC 的种类 CDC 主要分为基于查询和基于 Binl