暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

clickhouse集群搭建

果果经典影视 2021-10-22
1111
常用指令
#启停clickhouse server
/etc/init.d/clickhouse-server start|staus|stop
#进入客户端交互界面
clickhouse-client -m
#查询当前现有数据库
clickhouse-client -t -q 'show databases;'
#新建数据库db1400(所有节点都要操作进行创建)
clickhouse-client -q 'create database db1400;'
#进入system库
clickhouse-client -d system

--host  --port --user  --password
--query, -q   非交互模式下查询
--database, -d   默认当前数据库,default
--multiline, -m 准许多行查询
--format, -f   指定格式输出
--time, -t     非交互模式打印执行时间
--stacktrace   如果出现异常,会打印堆栈跟踪信息
--config-file 配置文件名称
安装
基础环境
#检查当前CPU是否支持SSE 4.2的命令
grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"

#文件句柄(文件数和进程数)
vim /etc/security/limits.conf    
vim /etc/security/limits.d/20-nproc.conf
*               soft   nofile         655350
*               hard   nofile         655350
*               soft   nproc          131072
*               hard   nproc          131072

#取消selinux
vim /etc/selinux/config
SELINUX=disabled

#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld

#安装依赖(不强制,如果失败了就安装一下)
yum install -y libtool libicu.x86_64 *unixODBC*
安装rpm包
rpm -ivh clickhouse-common-static-19.16.3.6-1.el7.x86_64.rpm
rpm -ivh clickhouse-server-common-19.16.3.6-1.el7.x86_64.rpm
rpm -ivh clickhouse-server-19.16.3.6-1.el7.x86_64.rpm
rpm -ivh clickhouse-client-19.16.3.6-1.el7.x86_64.rpm
配置config.xml
<?xml version="1.0"?>
<yandex>
  <!-- 日志 -->
  <logger>
      <level>trace</level>
      <log>/data/clickhouse/log/server.log</log>
      <errorlog>/data/clickhouse/log/error.log</errorlog>
      <size>1000M</size>
      <count>10</count>
  </logger>

  <!-- 端口 -->
  <http_port>8123</http_port>
  <tcp_port>9000</tcp_port>
  <interserver_http_port>9009</interserver_http_port>

  <!-- 本机域名 -->
  <interserver_http_host>这里需要用域名,如果后续用到复制的话</interserver_http_host>

  <!-- 监听IP -->
  <listen_host>0.0.0.0</listen_host>
  <!-- 最大连接数 -->
  <max_connections>64</max_connections>

  <!-- 没搞懂的参数 -->
  <keep_alive_timeout>3</keep_alive_timeout>

  <!-- 最大并发查询数 -->
  <max_concurrent_queries>16</max_concurrent_queries>

  <!-- 单位是B -->
  <uncompressed_cache_size>8589934592</uncompressed_cache_size>
  <mark_cache_size>10737418240</mark_cache_size>

  <!-- 存储路径 -->
  <path>/data/clickhouse/</path>
  <tmp_path>/data/clickhouse/tmp/</tmp_path>

  <!-- user配置 -->
  <users_config>users.xml</users_config>
  <default_profile>default</default_profile>

  <log_queries>1</log_queries>

  <default_database>default</default_database>

  <remote_servers incl="clickhouse_remote_servers" />
  <zookeeper incl="zookeeper-servers" optional="true" />
  <macros incl="macros" optional="true" />

  <!-- 没搞懂的参数 -->
  <builtin_dictionaries_reload_interval>3600</builtin_dictionaries_reload_interval>

  <!-- 控制大表的删除 -->
  <max_table_size_to_drop>0</max_table_size_to_drop>
  <include_from>/etc/clickhouse-server/metrika.xml</include_from>
</yandex>
配置metrika.xml
<yandex>
   <clickhouse_remote_servers>
       <perftest_3shards_1replicas><!-- 集群名称 自定义名称-->
           <shard>
               <internal_replication>true</internal_replication>
               <replica>
                   <host>alpnode01</host>
                   <port>9022</port>
               </replica>
           </shard>
           <shard>
               <replica>
                   <internal_replication>true</internal_replication>
                   <host>alpnode02</host>
                   <port>9022</port>
               </replica>
           </shard>
           <shard>
               <internal_replication>true</internal_replication>
               <replica>
                   <host>alpnode03</host>
                   <port>9022</port>
               </replica>
           </shard>
       </perftest_3shards_1replicas>
   </clickhouse_remote_servers>
   <!--zookeeper相关配置,不做高可用可以不写-->
   <zookeeper-servers>
       <node index="1">
           <host>alpnode02</host>
           <port>2181</port>
       </node>
       <node index="2">
           <host>alpnode03</host>
           <port>2181</port>
       </node>
       <node index="3">
           <host>alpnode05</host>
           <port>2181</port>
       </node>
   </zookeeper-servers>

<!--三台机器不要一样-->
   <macros>
       <replica>clickhouse01</replica>
   </macros>
   <networks>
       <ip>::/0</ip>
   </networks>
   <clickhouse_compression>
       <case>
           <min_part_size>10000000000</min_part_size>
           <min_part_size_ratio>0.01</min_part_size_ratio>
           <method>lz4</method>
       </case>
   </clickhouse_compression>
</yandex>
启动
#启动(所有节点)
service clickhouse-server start
验证集群
[root@alpnode01 etc]# clickhouse-client -p 9022
Bad arguments: unrecognised option '-p'
[root@alpnode01 etc]# clickhouse-client --port 9022
ClickHouse client version 20.8.3.18.
Connecting to localhost:9022 as user default.
Connected to ClickHouse server version 20.8.3 revision 54438.

alpnode01 :) select * from system.clusters;

SELECT *
FROM system.clusters

┌─cluster────────────────────┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_name─┬─host_address───┬─port─┬─is_local─┬─user────┬─default_database─┬─errors_count─┬─estimated_recovery_time─┐
│ perftest_3shards_1replicas │         1 │            1 │           1 │ alpnode01 │ 192.168.23.111 │ 9022 │        1 │ default │                 │            0 │                       0
│ perftest_3shards_1replicas │         2 │            1 │           1 │ alpnode02 │ 192.168.23.112 │ 9022 │        0 │ default │                 │            0 │                       0
│ perftest_3shards_1replicas │         3 │            1 │           1 │ alpnode03 │ 192.168.23.113 │ 9022 │        0 │ default │                 │            0 │                       0
└────────────────────────────┴───────────┴──────────────┴─────────────┴───────────┴────────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────────────┘

3 rows in set. Elapsed: 0.007 sec.
OLAP场景特征
  • 绝大多数是读请求

  • 数据以相当大的批次(> 1000行)更新,而不是单行更新;或者根本没有更新。已添加到数据库的数据不能修改。

  • 对于读取,从数据库中提取相当多的行,但只提取列的一小部分。

  • 宽表,即每个表包含着大量的列

  • 查询相对较少(通常每台服务器每秒查询数百次或更少)

  • 对于简单查询,允许延迟大约50毫秒

  • 列中的数据相对较小:数字和短字符串(例如,每个URL 60个字节)

  • 处理单个查询时需要高吞吐量(每台服务器每秒可达数十亿行)

  • 事务不是必须的

  • 对数据一致性要求低

  • 每个查询有一个大表。除了他以外,其他的都很小。

  • 查询结果明显小于源数据。换句话说,数据经过过滤或聚合,因此结果适合于单个服务器的RAM中


文章转载自果果经典影视,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论