关于大数据:ClickHouse单机和分片集群安装与特点介绍

  • 介绍

    ClickHouse 是俄罗斯的Yandex于2016年开源的列式存储数据库(DBMS),应用C++语言编写,次要用于在线剖析解决查问(OLAP)
    适宜单条sql的查问 多表join能力较差

  • 特点

    列式贮存

     对应列的聚合,计算,求和速度优于行式贮存 
     又于列的数据类型雷同 能够应用更加高效的压缩形式 
     数据压缩的更好 一方面节约磁盘空间 另一方面对cache(高速缓存器)有更大      的施展空间 
     吞吐量高、性能强,一致性、事务性较弱
     数据易保护,当咱们更新数据时,历史数据会有版本号,不会被扭转或者隐没。
     毛病也很显著。列式存储在表关联上不不便 适宜数据分析 不适宜简单业务 

    DBMS性能

    实现了规范的SQL语法 DDL ,DML含有大量函数(不反对自定义函数) 用户治理好权限治理,含有数据备份和复原

    多样化引擎

    多种引擎 适应不同的业务场景 20多种  合并树,日志 ,接口,等等

    高吞吐写入

    ClickHouse采纳类LSM Tree的构造,数据写入后定期在后盾Compaction。
    ckHouse在数据导入时全副是程序append写 compaction时也是多个段merge sort后程序写回磁盘
    官网公开benchmark测试显示可能达到50MB-200MB/s的写入吞吐能力,依照每行100Byte估算,大概相当于50W-200W条/s的写入速度。

    数据分区与线程级并行

    单条Query就能利用整机所有CPU ,分区建索引 ,并行查问 
    有一个弊病就是对于单条查问应用多cpu,就不利于同时并发多条查问
  • Clickhouse装置

  • 1 敞开防火墙

    systemctl status firewalld.service 
    systemctl stop firewalld.service 
    systemctl start firewalld.service
  • 2 装置依赖

    每个节点执行
    sudo yum install -y libtool
    sudo yum install -y *unixODBC*    
  • 3 CentOS关上文件数数限度 勾销 SELINUX

      $ sudo vim /etc/security/limits.conf
      #增加以下内容
      * soft nofile 65536
      * hard nofile 65536
      * soft nproc 131072
      * hard nproc 131072
      $ sudo vim /etc/security/limits.d/20-nproc.conf
      #增加以下内容
      * soft nofile 65536
      * hard nofile 65536
      * soft nproc 131072
      * hard nproc 131072
    sudo vim /etc/selinux/config
    SELINUX=disabled

    节点同步文件
    重启服务器

  • 4 在线装置 每台都须要

    sudo yum install yum-utils
    sudo rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
    sudo yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/stable/x86_64
    sudo yum install clickhouse-server clickhouse-client
    

    或者通离线装置 sudo rpm -ivh *.rpm

  • 5 批改配置文件

    sudo vim /etc/clickhouse-server/config.xml
    把 <listen_host>::</listen_host> 的正文关上,这样的话能力让ClickHouse被除本机![image.png](/img/bVcU1T3)
    散发配置文件
  • 6 启动clickhouse

    sudo systemctl start clickhouse-server`
    连贯测试 clickhouse-client -m  
    或者:
    TZ=Asia/Shanghai clickhouse-client -m
    -m是能够换行输出命令

  • 分片集群的部署

    留神:ClickHouse的集群是表级别的,理论企业中,大部分做了高可用,然而没有用分片,防止升高查问性能以及操作集群的复杂性。

  • 配置6节点的集群和正本 三分片二正本

    创立/etc/clickhouse-server/config.d/metrika-shard.xml 文件
    批改文件

    <yandex>
        <clickhouse_remote_servers>
            <gmall_cluster> <!-- 集群名称--> 
                <shard>  <!--集群的第一个分片-->
                    <internal_replication>true</internal_replication>
                    <!--该分片的第一个正本-->
                    <replica>    
                        <host>hadoop101</host>
                        <port>9000</port>
                     </replica>
                     <!--该分片的第二个正本-->
                     <replica> 
                        <host>hadoop102</host>
                        <port>9000</port>
                     </replica>
                </shard>
    
                  <shard>  <!--集群的第二个分片-->
                     <internal_replication>true</internal_replication>
                     <replica>    <!--该分片的第一个正本-->
                        <host>hadoop103</host>
                         <port>9000</port>
                     </replica>
                     <replica>    <!--该分片的第二个正本-->
                        <host>hadoop104</host>
                        <port>9000</port>
                     </replica>
                  </shard>
    
                  <shard>  <!--集群的第三个分片-->
                     <internal_replication>true</internal_replication>
                     <replica>     <!--该分片的第一个正本-->
                        <host>hadoop105</host>
                        <port>9000</port>
                     </replica>
                     <replica>    <!--该分片的第二个正本-->
                        <host>hadoop106</host>
                        <port>9000</port>
                     </replica>
                  </shard>
            </gmall_cluster>
        </clickhouse_remote_servers>
    </yandex>
    

    同步散发,重启服务

  • 创立集群表
    会主动同步 但每个节点上只能够查本人的数据

    create table st_order_mt on cluster gmall_cluster (
        id UInt32,
        sku_id String,
        total_amount Decimal(16,2),
        create_time  Datetime
     ) engine =ReplicatedMergeTree('/clickhouse/tables/{shard}/st_order_mt_0108','{replica}')
       partition by toYYYYMMDD(create_time)
       primary key (id)
       order by (id,sku_id);

    创立总表(能够查看所有分片数据)

    create table st_order_mt_all on cluster gmall_cluster
    (
        id UInt32,
        sku_id String,
        total_amount Decimal(16,2),
        create_time  Datetime
    )engine = Distributed(gmall_cluster,default, st_order_mt,hiveHash(sku_id));

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理