ClickHouse快速安装教程(MacOS)

打印 上一主题 下一主题

主题 701|帖子 701|积分 2103

ClickHouse快速安装教程(MacOS)

1.ClickHouse

ClickHouse®是一个用于在线分析处置惩罚(OLAP)的高性能、面向列的SQL数据库管理体系(DBMS)。ClickHouse专门针对大规模数据分析和及时查询的场景进行优化。它被设计用于高效处置惩罚PB级以上的数据,并能在秒级内完成复杂的查询分析。
OLAP场景的关键特性


  • 绝大多数是读请求
  • 数据以相当大的批次(> 1000行)更新,而不是单行更新;或者根本没有更新。
  • 已添加到数据库的数据不能修改。
  • 对于读取,从数据库中提取相当多的行,但只提取列的一小部分。
  • 宽表,即每个表包含着大量的列
  • 查询相对较少(通常每台服务器每秒查询数百次或更少)
  • 对于简朴查询,允许延迟大约50毫秒
  • 列中的数据相对较小:数字和短字符串(例如,每个URL 60个字节)
  • 处置惩罚单个查询时须要高吞吐量(每台服务器每秒可达数十亿行)
  • 事务不是必须的
  • 对数据一致性要求低
  • 每个查询有一个大表。除了他以外,其他的都很小。
  • 查询结果明显小于源数据。换句话说,数据经过过滤或聚合,因此结果得当于单个服务器的RAM中
ClickHouse具有以下特点:

  • 高性能:接纳了列式存储和压缩技能,在处置惩罚大规模数据时能够快速高效地进行数据读取和查询。它使用了向量化查询引擎和多级缓存,可以实现即时的查询结果响应。
  • 分布式架构:支持程度扩展,可以轻松地在集群中添加或删除节点。它使用分片和复制机制来实现高可用性和数据冗余。
  • 强大的查询功能:支持标准的SQL查询语言,并提供了丰富的查询函数和聚合操作,可以方便地进行复杂的数据分析和数据挖掘。
  • 可伸缩性:能够处置惩罚海量数据,并且能够在不降低性能的情况下轻松地扩展到更多的节点,以满意不断增长的数据需求。
  • 低延迟查询:通过使用基于内存的数据存储和高效的查询引擎,可以在毫秒级的时间范围内处置惩罚查询请求,实用于须要及时响应的场景。 总之,ClickHouse是一个专门用于大规模数据分析和及时查询的高性能分布式列式数据库,它具有高可扩展性和低延迟查询的优势,实用于须要处置惩罚大量数据和复杂查询的应用场景。
2.快速安装

本地下载ClickHouse最简朴的方法是运行以下curl命令:
  1. curl https://clickhouse.com/ | sh
复制代码

下载ClickHouse(执行本命令安装完成后,你可以编辑ClickHouse的设置文件来自定义参数和设置,例如监听地址、端口,以及数据存储和备份的路径等。)

3.快速启动

3.1.启动服务器

  1. ./clickhouse server
复制代码

3.2.启动客户端

  1. ./clickhouse client
复制代码

可以看到会出现以下警告:最大线程数低于30000。处置惩罚大量同时进行的查询大概会出现问题。
  1. Warnings:
  2. * Maximum number of threads is lower than 30000. There could be problems with handling a lot of simultaneous queries.
复制代码
这个警告表明,当前设置的线程数大概不足以处置惩罚大量的同时查询。您可以通过修改ClickHouse的设置文件来增加线程数。在/etc/clickhouse-server/config.xml文件中找到max_threads设置,并根据您的服务器性能和负载情况进行调解
4.使用案例

1.设置文件

添加设置文件 config.xml
  1. <clickhouse>
  2.           <logger>
  3.         <level>trace</level>
  4.         <log>/Users/admin/ck/data/logs/clickhouse.log</log>
  5.         <errorlog>/Users/admin/ck/data/logs/error.log</errorlog>
  6.         <size>500M</size>
  7.         <count>5</count>
  8.     </logger>
  9.     <http_port>8123</http_port>
  10.     <tcp_port>9000</tcp_port>
  11.     <interserver_http_port>9001</interserver_http_port>
  12.     <interserver_http_host>127.0.0.1</interserver_http_host>  
  13.     <listen_host>0.0.0.0</listen_host>
  14.     <max_connections>4096</max_connections>
  15.     <keep_alive_timeout>300</keep_alive_timeout>
  16.     <max_concurrent_queries>1000</max_concurrent_queries>
  17.     <uncompressed_cache_size>8589934592</uncompressed_cache_size>
  18.     <mark_cache_size>5368709120</mark_cache_size>
  19.           <default_profile>default</default_profile>
  20.     <default_database>default</default_database>
  21.     <builtin_dictionaries_reload_interval>3600</builtin_dictionaries_reload_interval>
  22.     <max_session_timeout>3600</max_session_timeout>
  23.     <default_session_timeout>300</default_session_timeout>
  24.     <max_table_size_to_drop>0</max_table_size_to_drop>
  25.     <merge_tree>
  26.         <parts_to_delay_insert>300</parts_to_delay_insert>
  27.         <parts_to_throw_insert>600</parts_to_throw_insert>
  28.         <max_delay_to_insert>2</max_delay_to_insert>
  29.     </merge_tree>
  30.     <max_table_size_to_drop>0</max_table_size_to_drop>
  31.     <max_partition_size_to_drop>0</max_partition_size_to_drop>
  32.     <!-- Path to data directory, with trailing slash. -->
  33.     <path>/Users/admin/ck/data/</path>
  34.     <!-- Path to temporary data for processing hard queries. -->
  35.     <tmp_path>/Users/admin/ck/data/tmp/</tmp_path>
  36.     <!-- Sources to read users, roles, access rights, profiles of settings, quotas. -->
  37.     <user_directories>
  38.         <users_xml>
  39.             <!-- Path to configuration file with predefined users. -->
  40.                   <!-- 此处的目录地址指向下方的users.xml -->
  41.             <path>/Users/admin/ck/users.xml</path>
  42.         </users_xml>
  43.         <local_directory>
  44.             <!-- Path to folder where users created by SQL commands are stored. -->
  45.             <!-- 用户创建sql语句的存储目录 -->
  46.             <path>/Users/admin/ck/users/</path>
  47.         </local_directory>
  48.     </user_directories>
  49. </clickhouse>
复制代码
添加用户设置文件 users.xml
  1. <clickhouse>
  2.           <profiles>
  3.         <default>
  4.             <max_memory_usage>10000000000</max_memory_usage>
  5.             <use_uncompressed_cache>0</use_uncompressed_cache>
  6.             <load_balancing>random</load_balancing>
  7.         </default>
  8.         <readonly>
  9.             <max_memory_usage>10000000000</max_memory_usage>
  10.             <use_uncompressed_cache>0</use_uncompressed_cache>
  11.             <load_balancing>random</load_balancing>
  12.             <readonly>1</readonly>
  13.         </readonly>
  14.     </profiles>
  15.     <quotas>
  16.         <!-- Name of quota. -->
  17.         <default>
  18.             <interval>
  19.                 <queries>0</queries>
  20.                 <errors>0</errors>
  21.                 <result_rows>0</result_rows>
  22.                 <read_rows>0</read_rows>
  23.                 <execution_time>0</execution_time>
  24.             </interval>
  25.         </default>
  26.     </quotas>
  27.     <users>
  28.         <default>
  29.           <!-- 明文:123456 -->
  30.   <password_sha256_hex>8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92</password_sha256_hex>
  31.           <networks>
  32.                 <ip>::/0</ip>
  33.             </networks>  
  34.           <profile>default</profile>
  35.           <quota>default</quota>
  36.           <access_management>1</access_management>
  37.         </default>
  38.     </users>
  39. </clickhouse>
复制代码
  ⚠️留意:
  如果不设置以上设置文件,使用CK默认的设置,在新增用户并设置权限会出现以下问题:DB::Exception: Could not insert user test because there is no writeable access
  

  2.启动CK服务

与之前不同,此处使用指定的设置文件启动,也就是上节的设置文件地址。
  1. ./clickhouse server
  2. --config-file=/Users/admin/ck/config.xml
复制代码

启动客户端,与之前一样。

3.创建数据库

  1. CREATE DATABASE IF NOT EXISTS test
复制代码

4.创建表

  1. CREATE TABLE IF NOT EXISTS test.t_users
  2. (
  3.     `id` String COMMENT 'ID',
  4.           `name` Nullable(String) COMMENT '名称',
  5.           `age` Nullable(Int64) COMMENT '年龄',
  6.           `create_date` Nullable(Date) DEFAULT toDate(now()) COMMENT '创建时间'
  7. ) ENGINE = MergeTree
  8. PRIMARY KEY(id);
复制代码

5.插入数据

  1. INSERT INTO test.t_users(id,name,age) VALUES (1, 'jack', 18)
复制代码

6.查询数据

  1. select * from test.t_users where id = '1'
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

梦应逍遥

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表