1、簡介
? ? ? ? clickhouse 作為大數據場景中,實現快速檢索的常用列式存儲數據庫,采用物理機部署,會在數據量大的場景中,物理機器存儲達到閾值需要擴容,會帶來比較大的問題,因此,使用docker部署clickhouse集群可以使得運維簡單。
2、clickhouse安裝
2.1、集群規劃
? ? ? ? 采用三臺節點進行部署,只能實現3個分片1個副本進行部署,部署規劃如下:
節點 | ip | 描述 |
node-1 | 192.168.0.66 | 集群中安裝的zookeeper集群, 端口號2181 |
node-2 | 192.168.0.67 | |
node-3 | 192.168.0.68 |
2.2、拉取鏡像
docker pull clickhouse/clickhouse-server
?2.3、編寫docker-compose文件
services:clickhouse:image: clickhouse/clickhouse-server:latestcontainer_name: clickhousenetwork_mode: hostvolumes: # 掛載路徑- ./clickhouse/data:/var/lib/clickhouse- ./clickhouse/config:/etc/clickhouse-server- ./clickhouse/log:/var/log/clickhouse-serverulimits: # 文件描述符個數設置,可根據實際情況來nofile:soft: 65536hard: 65536
在當前目錄下創建三個掛載目錄:
mkdir -p clickhouse/data
mkdir -p clickhouse/config
mkdir -p clickhouse/log
2.4、在config目錄下創建配置文件
? ? ? ? config目錄下包含兩個配置文件:config.xml 和 users.xml
1)、config.xml文件
<?xml version="1.0"?>
<yandex>
<!-- log級別及目錄配置 --><logger><level>information</level><log>/var/log/clickhouse-server/clickhouse-server.log</log><errorlog>/var/log/clickhouse-server/clickhouse-server.err.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>
<!-- 監聽ip設置 --><listen_host>0.0.0.0</listen_host><max_connections>4096</max_connections><keep_alive_timeout>3</keep_alive_timeout><max_concurrent_queries>100</max_concurrent_queries><uncompressed_cache_size>8589934592</uncompressed_cache_size><mark_cache_size>5368709120</mark_cache_size>
<!-- 數據保存路徑設置 --><path>/var/lib/clickhouse/</path><tmp_path>/var/lib/clickhouse/tmp/</tmp_path><user_files_path>/var/lib/clickhouse/user_files/</user_files_path><users_config>users.xml</users_config><default_profile>default</default_profile><default_database>default</default_database><timezone>Asia/Shanghai</timezone><mlock_executable>false</mlock_executable>
<!-- zk中分布式ddl節點設置,和下面zookeeper配置中的root結合形成整個節點路徑:root/path --><distributed_ddl><path>/clickhouse/task_queue/ddl</path></distributed_ddl><remote_servers><test_cluster> <!-- 集群名稱,集群分片副本配置,博主只有三臺機器,只能配置3分片1副本 --><shard> <!-- 分片 --><replica><host>192.168.0.66</host><port>9000</port></replica></shard><shard><replica><host>192.168.0.67</host><port>9000</port></replica></shard><shard><replica><host>192.168.0.68</host><port>9000</port></replica></shard></test_cluster></remote_servers>
<!-- zookeeper配置 -->
<zookeeper><node index="1"><host>192.168.0.66</host><port>2181</port></node><node index="2"><host>192.168.0.67</host><port>2181</port></node><node index="3"><host>192.168.0.68</host><port>2181</port></node><session_timeout_ms>30000</session_timeout_ms><operation_timeout_ms>10000</operation_timeout_ms><root>/ck</root>
</zookeeper><macros><cluster>test_cluster</cluster><shard>3</shard><replica>192.168.0.66</replica></macros>
</yandex>
?2)、users.xml
<?xml version="1.0"?>
<yandex><users><default> <!-- 默認用戶名 --><password></password><networks><ip>::/0</ip></networks><profile>default</profile><quota>default</quota></default><test> <!-- 配置用戶名 --><password>default123.com</password> <!-- 自定義密碼 --><networks incl="networks" replace="replace"><ip>::/0</ip></networks><profile>default</profile><quota>default</quota></test></users><profiles><default><max_memory_usage>10000000000</max_memory_usage><use_uncompressed_cache>0</use_uncompressed_cache><load_balancing>random</load_balancing></default></profiles><quotas><default><interval><duration>3600</duration><queries>0</queries><errors>0</errors><result_rows>0</result_rows><read_rows>0</read_rows><execution_time>0</execution_time></interval></default></quotas>
</yandex>
3、啟動集群
# 1、在每個節點都執行( 到docker-compose.yml所在的目錄下執行)
docker compose up -d
# 2、驗證啟動成功
docker exec -it clickhouse clickhouse-client
select * from system.clusters; # 可以查看集群情況
4、總結
? ? ? ? 至此,clickhouse集群就搭建完成,中間排了很多坑,這一套配置是100%能搭建成功的。
注:
1)、集群之間防火墻關閉或者放開使用到的端口;
2)、docker使用host網絡模式;
3)、使用機器名要將/etc/hosts映射進去
? ? ? ? 搭建過程中有任何不懂的地方可以關注: it自學社團 ,后臺私信問我。