ClickHouse入门:多副本集群配置

x33g5p2x  于2021-12-25 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(1389)

前言
插件及服务器版本
服务器:ubuntu 16.04
ClickHouse:21.4.6.55

简介

配置一个单Shard、3副本的ClickHouse集群,并验证测试

服务器准备

3台ubuntu 16.04的服务器:
192.168.10.17
192.168.10.10
192.168.10.16

安装ClickHouse

3台服务器均安装ClickHouse:

sudo apt-get install apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E0C56BD4

echo "deb https://repo.clickhouse.tech/deb/stable/ main/" | sudo tee \
    /etc/apt/sources.list.d/clickhouse.list
sudo apt-get update

sudo apt-get install -y clickhouse-server clickhouse-client

sudo service clickhouse-server start
clickhouse-client

修改配置文件

修改3台服务器ClickHouse配置文件 /etc/clickhouse-server/config.xml

1、在 <remote_servers> 标签内添加如下配置:
配置副本节点

<nt_1shards_3replicas> 
  <shard> 
    <internal_replication>true</internal_replication>  
    <replica> 
      <host>192.168.10.17</host>  
      <port>9000</port> 
    </replica>  
    <replica> 
      <host>192.168.10.10</host>  
      <port>9000</port> 
    </replica>  
    <replica> 
      <host>192.168.10.16</host>  
      <port>9000</port> 
    </replica> 
  </shard> 
</nt_1shards_3replicas>

2、添加zookeeper配置

<zookeeper> 
  <node index="1"> 
    <host>192.168.10.17</host>  
    <port>2181</port> 
  </node>  
  <node index="2"> 
    <host>192.168.10.10</host>  
    <port>2181</port> 
  </node>  
  <node index="3"> 
    <host>192.168.10.16</host>  
    <port>2181</port> 
  </node> 
</zookeeper>

3、添加macros配置

<macros>
    <shard>1</shard>
    <replica>192.168.10.17</replica> //这里每个结点的配置添加当前节点IP
</macros>

重启使配置生效

systemctl restart clickhouse-server.service

ClickHouse-Client查看配置是否生效:

select * from system.clusters;

测试创建Replicated表

CREATE TABLE test_replicated ON CLUSTER nt_1shards_3replicas
(
    id String,
    code String
)ENGINE = ReplicatedMergeTree('/clickhouse/tables/nt_1shards_3replicas/{shard}/test_replicated','{replica}')
ORDER BY id
SETTINGS index_granularity= 8192;

相关文章