当前位置:   article > 正文

clickhouse 集群搭建_clickhouse集群搭建

clickhouse集群搭建

目录

一、 首先要安装单节点集群

二、安装zookeeper并搭建集群

1. 配置host

2. 安装zookeeper

3. 配置zookeeper

三、clickhouse 集群配置

1.配置metrika.xml文件

2. 修改clickhouse的配置文件


一、 首先要安装单节点集群

在这里就不太赘述。官网下载安装包,然后放到一个文件夹中,执行以下命令即可:

rpm -ivh ./*.rpm

安装途中会让你为默认用户指定密码,输入密码或者直接回车键不设置密码。

安装完成后可以直接

clickhouse start

来启动

二、安装zookeeper并搭建集群

1. 配置host

vim /etc/hosts

  1. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  2. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  3. 192.168.10.11 ck-01
  4. 192.168.10.12 ck-02
  5. 192.168.10.13 ck-03

 修改本机hostname,

  1. vim /etc/sysconfig/network
  2. HOSTNAME=ck-01
hostnamectl set-hostname ck-01

2. 安装zookeeper

tar -xzvf apache-zookeeper-3.5.9-bin.tar.gz -C /opt/

解压路径可以自己指定。

3. 配置zookeeper

进入zookeeper的conf目录下, 将其中的zoo_sample.cfg 文件改名或者复制一份命名为zoo.cfg

并对 zoo.cfg进行配置

  1. cd /opt/apache-zookeeper-3.5.9-bin/conf/
  2. cp zoo_sample.cfg zoo.cfg
  3. vim zoo.cfg

配置文件修改为如下:

  1. # The number of milliseconds of each tick
  2. tickTime=2000
  3. # The number of ticks that the initial
  4. # synchronization phase can take
  5. initLimit=10
  6. # The number of ticks that can pass between
  7. # sending a request and getting an acknowledgement
  8. syncLimit=5
  9. # the directory where the snapshot is stored.
  10. # do not use /tmp for storage, /tmp here is just
  11. # example sakes.
  12. dataDir=/data/zookeeper/
  13. dataLogDir=/data/log/zookeeper/
  14. # the port at which the clients will connect
  15. clientPort=2181
  16. # the maximum number of client connections.
  17. # increase this if you need to handle more clients
  18. #maxClientCnxns=60
  19. #
  20. # Be sure to read the maintenance section of the
  21. # administrator guide before turning on autopurge.
  22. #
  23. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
  24. #
  25. # The number of snapshots to retain in dataDir
  26. #autopurge.snapRetainCount=3
  27. # Purge task interval in hours
  28. # Set to "0" to disable auto purge feature
  29. #autopurge.purgeInterval=1
  30. server.1=ck-01:2888:3888
  31. server.2=ck-02:2888:3888
  32. server.3=ck-03:2888:3888

其中dataDir是数据存储路径,dataLogDir是日志路径,这个自己指定即可

在设定的dataDir的目录下,创建myid文件并写入1,其他机器分别写入2,3

  1. cd /data/zookeeper/
  2. vim myid
  3. echo 1 > myid

然后进入bin目录下执行启动脚本启动zookeeper

  1. cd /opt/apache-zookeeper-3.5.9-bin/bin/
  2. # 启动
  3. ./zkServer.sh start
  4. # 查看状态
  5. ./zkServer.sh status

出现下面这种则表示成功启动成功

\

可以将zookeper的启动加入到环境变量中,避免每次都要进入bin目录才能启动,

  1. vim /etc/profile
  2. export ZOOKEEPER_HOME=/opt/apache-zookeeper-3.5.9-bin
  3. export PATH=$PATH:$ZOOKEEPER_HOME/bin

三、clickhouse 集群配置

1.配置metrika.xml文件

首先在/etc 下创建metrika.xml文件,并输入

  1. <!--集群分片副本相关配置 1分片3副本 -->
  2. <yandex>
  3. <clickhouse_remote_servers>
  4. <!--集群名称 -->
  5. <clickhouse_1shards_3replicas>
  6. <!-- 第1个分片 -->
  7. <shard>
  8. <!-- 是否写入多副本 -->
  9. <!-- <internal_replication>false</internal_replication> -->
  10. <!-- 1分片的1副本 -->
  11. <replica>
  12. <host>ck-01</host>
  13. <port>9000</port>
  14. </replica>
  15. <!-- 1分片的2副本 -->
  16. <replica>
  17. <host>ck-02</host>
  18. <port>9000</port>
  19. </replica>
  20. <!-- 1分片的3副本 -->
  21. <replica>
  22. <host>ck-03</host>
  23. <port>9000</port>
  24. </replica>
  25. </shard>
  26. </clickhouse_1shards_3replicas>
  27. </clickhouse_remote_servers>
  28. <!--zookeeper相关配置-->
  29. <zookeeper-servers>
  30. <node index="1">
  31. <host>ck-01</host>
  32. <port>2181</port>
  33. </node>
  34. <node index="2">
  35. <host>ck-02</host>
  36. <port>2181</port>
  37. </node>
  38. <node index="3">
  39. <host>ck-03</host>
  40. <port>2181</port>
  41. </node>
  42. </zookeeper-servers>
  43. <!--压缩策略-->
  44. <clickhouse_compression>
  45. <case>
  46. <min_part_size>10000000000</min_part_size>
  47. <min_part_size_ratio>0.01</min_part_size_ratio>
  48. <method>lz4</method>
  49. </case>
  50. </clickhouse_compression>
  51. <!-- 本机绑定地址 -->
  52. <networks>
  53. <ip>::/0</ip>
  54. </networks>
  55. <macros>
  56. <shard_name>01</shard_name>
  57. <replica_name>ck-01</replica_name>
  58. </macros>
  59. </yandex>

<macros>标签下的要根据所配置的机器进行配置,其他两台应该

  1. <macros>
  2. <shard_name>02</shard_name>
  3. <replica_name>ck-02</replica_name>
  4. </macros>
  5. <macros>
  6. <shard_name>03</shard_name>
  7. <replica_name>ck-03</replica_name>
  8. </macros>

需要注意的是,这个配置文件需要赋予clickhouse权限

chown -R clickhouse:clickhouse /etc/metrika.xml

2. 修改clickhouse的配置文件

clickhouse的默认配置文件为/etc/clickhouse-server/config.xml

vim /etc/clickhouse-server/config.xml
  1. <!--对外开放-->
  2. <listen_host>::</listen_host>
  3. <!--修改数据路径-->
  4. <path>/data/clickhouse/</path>
  5. <!-- Configuration of clusters that could be used in Distributed tables.
  6. https://clickhouse.tech/docs/en/operations/table_engines/distributed/
  7. -->
  8. <zookeeper incl="zookeeper-servers" optional="true" />
  9. <include_from>/etc/metrika.xml</include_from>
  10. <macros incl="macros" optional="true" />
  11. <remote_servers incl="clickhouse_remote_servers">

一共需要修改三项,分别是:

1)<listen_hosts> 这个是为了能让外部机器访问

2)<path> 这个是配置数据存储路径,也可以不修改,但是如果修改了路径,则一定要将这个路径的权限改为clickhouse,不然无法启动clickhosue

3)添加上面的配置,使得集群配置生效,如果不配置,则无法启动集群

完成配置后,重新启动clickhouse

clickhouse restart

然后随便一台机器执行

clickhouse-client

然后执行以下语句

select * from system.clusters;

则能看到所配置的集群,集群名称应该为:clickhouse_1shards_3replicas 这个根据自己配置的集群名称不同有所不同

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/246429
推荐阅读
相关标签
  

闽ICP备14008679号