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 | 集群中安装的zookeeper集群, 端口号2181 |
| node-3 | 192.168.0.68 | 集群中安装的zookeeper集群, 端口号2181 |
2.2、拉取镜像
bash
docker pull clickhouse/clickhouse-server
2.3、编写docker-compose文件
bash
services:
clickhouse:
image: clickhouse/clickhouse-server:latest
container_name: clickhouse
network_mode: host
volumes: # 挂载路径
- ./clickhouse/data:/var/lib/clickhouse
- ./clickhouse/config:/etc/clickhouse-server
- ./clickhouse/log:/var/log/clickhouse-server
ulimits: # 文件描述符个数设置,可根据实际情况来
nofile:
soft: 65536
hard: 65536
在当前目录下创建三个挂载目录:
bash
mkdir -p clickhouse/data
mkdir -p clickhouse/config
mkdir -p clickhouse/log
2.4、在config目录下创建配置文件
config目录下包含两个配置文件:config.xml 和 users.xml
1)、config.xml文件
bash
<?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
bash
<?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、启动集群
bash
# 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自学社团,后台私信问我。