
Daha önce 2 node üzerinde çalışan ve 3 node Clickhouse-keeper içeren bir Cluster oluşturmuştuk.
Buradaki konfigürasyonu değiştirerek, mevcut clusterımızı 4 node olacak şekilde konfigüre etmek istiyoruz , buradaki yapıda 2 shard ve her sard bir replika içerecek şekilde bir cluster oluşturulacak, sonrasında tek shard bütün nodelar birbirinin replikası olan başka bir cluster daha oluşturacağız. İlk olarak 2 shard ve her shardın replikası olan yapı aşağıdaki gibidir, 3 node üzerinde clikhouse-keeper da çalışacak,

Bu işlem için konfigürasyon dosylarımızı düzenlememiz gerek , konfigürasyon dosyaları için aşağıdaki yazıya bakabilirsiniz.
enable-keeper.xml –> yanlızca clickhouse-keeper kullanılcak node lar için kullanılmaktadır. server_id alanı her node için düzenlenmelidir.
<clickhouse>
<keeper_server>
<tcp_port>9181</tcp_port>
<server_id>1</server_id>
<log_storage_path>/var/lib/clickhouse-keeper/coordination/log</log_storage_path>
<snapshot_storage_path>/var/lib/clickhouse-keeper/coordination/snapshots</snapshot_storage_path>
<coordination_settings>
<operation_timeout_ms>10000</operation_timeout_ms>
<session_timeout_ms>30000</session_timeout_ms>
<raft_logs_level>trace</raft_logs_level>
<rotate_log_storage_interval>10000</rotate_log_storage_interval>
</coordination_settings>
<raft_configuration>
<server>
<id>1</id>
<hostname>clicknode01</hostname>
<port>9234</port>
</server>
<server>
<id>2</id>
<hostname>clicknode02</hostname>
<port>9234</port>
</server>
<server>
<id>3</id>
<hostname>clicknode03</hostname>
<port>9234</port>
</server>
</raft_configuration>
</keeper_server>
</clickhouse>
use_keeper.xml –> Tüm node lar için aşağıdaki dosya bulunmalıdır;
<clickhouse>
<zookeeper>
<node index="1">
<host>clicknode01</host>
<port>9181</port>
</node>
<node index="2">
<host>clicknode02</host>
<port>9181</port>
</node>
<node index="3">
<host>clicknode03</host>
<port>9181</port>
</node>
</zookeeper>
</clickhouse>
macros.xml –> Her node için uygun shard numarsı ile eklenmelidir;
<clickhouse>
<macros>
<cluster>mycluster</cluster>
<shard>01</shard>
<replica>clicknode01</replica>
<layer>01</layer>
</macros>
</clickhouse>
remote-servers.xml –> 4 node içinde aynı dosya kullanılır,
<clickhouse>
<remote_servers>
<mycluster>
<shard>
<internal_replication>true</internal_replication>
<replica><host>clicknode01</host><port>9000</port></replica>
<replica><host>clicknode02</host><port>9000</port></replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica><host>clicknode03</host><port>9000</port></replica>
<replica><host>clicknode04</host><port>9000</port></replica>
</shard>
</mycluster>
</remote_servers>
</clickhouse>
NOT : ** users.xml ve users.d altındaki konfigürasyonlarda eklenen nodlarda aynı olacak şekilde düzenlenmelidir.
Cluster a node ve keeper ları ekledik kontrol edelim;
SELECT
host_name,
host_address,
replica_num
FROM system.clusters
Query id: b69a5322-91eb-422f-91c0-236b6832455c
┌─host_name─┬─host_address──┬─replica_num─┐
│ clickn01 │ 10.220.164.56 │ 1 │
│ clickn02 │ 10.220.164.57 │ 2 │
│ clickn03 │ 10.220.164.58 │ 1 │
│ clickn04 │ 10.220.164.59 │ 2 │
└───────────┴───────────────┴─────────────┘
4 rows in set. Elapsed: 0.001 sec.
keeper drumlarını kontrol edelim; 2. node leader durumda 1 ve 3 ise follower durumda
# echo mntr | nc localhost 9181
zk_version v23.6.2.18-stable-89f39a7ccfe0c068c03555d44036042fc1c09d22
zk_avg_latency 1
zk_max_latency 21
zk_min_latency 0
zk_packets_received 4320
zk_packets_sent 4339
zk_num_alive_connections 4
zk_outstanding_requests 0
zk_server_state leader
zk_znode_count 317
zk_watch_count 18
zk_ephemerals_count 7
zk_approximate_data_size 96644
zk_key_arena_size 61440
zk_latest_snapshot_size 0
zk_open_file_descriptor_count 143
zk_max_file_descriptor_count 3246847
zk_followers 2
zk_synced_followers 2
Yeni bir cluster eklemek için ; remote-servers.xml ve macros.xml dosyalarını değiştirmemiz gerekmektedir. tek shard ve full replika bir cluster için remote-server.xml dosyamıza aşağıdaki clusterı xml tag olarak eklmeliyiz.
<all_repcls>
<shard>
<internal_replication>true</internal_replication>
<replica><host>clicknode01</host><port>9000</port></replica>
<replica><host>clicknode02</host><port>9000</port></replica>
<replica><host>clicknode03</host><port>9000</port></replica>
<replica><host>clicknode04</host><port>9000</port></replica>
</shard>
</all_repcls>
kontrol edelim;
SELECT
cluster,
host_name,
host_address,
replica_num,
shard_num
FROM system.clusters
Query id: 9c34f31c-40a1-431e-afc5-aa932e2aaf9c
┌─cluster────┬─host_name─┬─host_address──┬─replica_num─┬─shard_num─┐
│ all_repcls │ cliknd01 │ 10.120.168.56 │ 1 │ 1 │
│ all_repcls │ cliknd02 │ 10.120.168.57 │ 2 │ 1 │
│ all_repcls │ cliknd03 │ 10.120.168.58 │ 3 │ 1 │
│ all_repcls │ cliknd04 │ 10.120.168.59 │ 4 │ 1 │
│ mycluster │ cliknd01 │ 10.120.168.56 │ 1 │ 1 │
│ mycluster │ cliknd02 │ 10.120.168.57 │ 2 │ 1 │
│ mycluster │ cliknd03 │ 10.120.168.58 │ 1 │ 2 │
│ mycluster │ cliknd04 │ 10.120.168.59 │ 2 │ 2 │
└────────────┴───────────┴───────────────┴─────────────┴───────────┘
8 rows in set. Elapsed: 0.001 sec.
ÖNEMLİ NOT: Burada yeni eklnen nodlar için database ve tablo bilgilerinin rebalacnce olması gibi vir özelliği maalesef ClickHouse için mevcut değil dolayısıyla burada el yordamı ile datatabaseler oluşturulmalı ve distrubuted tablolar yeni node lar için tekrar tanımlanmalıdır.
Aşağıda yapılan mycluster konfigürasyonuna göre replika tablo oluşturulacak ve bu tablo distrubuted bir tabloya refere edilerek kontrolleri sağlanmaktadır;
-- Node1 üzerinden
clickhouse :) create table db1.test2 on cluster mycluster (id UInt16, name String)ENGINE=ReplicatedMergeTree order by id
clickhouse :) insert into db1.test2 values(1,'Test1');
SELECT *
FROM db1.test2
Query id: 93b3a7e3-acd8-48a9-abae-ec89cef6f33d
┌─id─┬─name──┐
│ 1 │ Test1 │
└────┴───────┘
--- node2 den
SELECT *
FROM db1.test2
Query id: 93b3a7e3-acd8-48a9-abae-ec89cef6f33d
┌─id─┬─name──┐
│ 1 │ Test1 │
└────┴───────┘
-- Node3 ve 4 ten 0 rows bekliyoruz
SELECT *
FROM db1.test2
Query id: 57005839-de95-4734-9369-85fb02a8c7df
Ok.
0 rows in set. Elapsed: 0.001 sec.
-- node 3 den bir insert yapalım;
clickhouse :) insert into db1.test2 values(2,'Test2');
-- Node3 ve 4 ten sorguladığımızda
SELECT *
FROM db1.test2
Query id: 69c12e4a-9554-4fa7-8d9d-720ef58039fe
┌─id─┬─name──┐
│ 2 │ Test2 │
└────┴───────┘
1 row in set. Elapsed: 0.002 sec.
Şimdi bu tabloyu refere ederek ditrubuted bir tablo oluşturalım;
clickhouse :) create table db1.test2_dist on cluster mycluster (id UInt16, name String)ENGINE= Distributed (mycluster,db1,test2,rand());
CREATE TABLE db1.test2_dist ON CLUSTER mycluster
(
`id` UInt16,
`name` String
)
ENGINE = Distributed(mycluster, db1, test2, rand())
Query id: 9bfe4454-f58c-49c3-b915-bf17cc814939
┌─host─────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ clickn04 │ 9000 │ 0 │ │ 3 │ 0 │
│ clickn02 │ 9000 │ 0 │ │ 2 │ 0 │
│ clickn01 │ 9000 │ 0 │ │ 1 │ 0 │
│ clickn03 │ 9000 │ 0 │ │ 0 │ 0 │
└──────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
4 rows in set. Elapsed: 0.123 sec.
-- Şimdi bu tabloyu tüm node lar dan sorgulayalım;
clickhouse-client -u clickadmin --password Parola123 --query="select * from db1.test2_dist"
1 Test1
2 Test2
Bir yanıt yazın