来讲一下“以示例讲解Clickhouse Docker集群部署以及配置”的完整攻略吧。
1. 安装Docker
首先需要安装Docker,可以根据自己的系统版本去下载并安装Docker。
2. 配置ClickHouse Docker镜像
使用以下命令从Docker Hub上拉取ClickHouse镜像:
docker pull yandex/clickhouse-server
3. 创建ClickHouse集群
使用Docker Compose创建一个三个节点的ClickHouse集群。首先在本地新建一个目录用于存放配置文件。在该目录下新建一个docker-compose.yml文件,输入以下内容:
version: '3'
services:
clickhouse-node1:
image: yandex/clickhouse-server
container_name: clickhouse_node1
environment:
- CLICKHOUSE_CONFIG=/etc/clickhouse-server/config.xml
- CLICKHOUSE_HTTP_PORT=8123
- CLICKHOUSE_TCP_PORT=9000
volumes:
- ./config.xml:/etc/clickhouse-server/config.xml
ports:
- "8123:8123"
- "9000:9000"
networks:
ch-network:
ipv4_address: 192.168.100.101
clickhouse-node2:
image: yandex/clickhouse-server
container_name: clickhouse_node2
environment:
- CLICKHOUSE_CONFIG=/etc/clickhouse-server/config.xml
- CLICKHOUSE_HTTP_PORT=8123
- CLICKHOUSE_TCP_PORT=9000
volumes:
- ./config.xml:/etc/clickhouse-server/config.xml
ports:
- "8124:8123"
- "9001:9000"
networks:
ch-network:
ipv4_address: 192.168.100.102
clickhouse-node3:
image: yandex/clickhouse-server
container_name: clickhouse_node3
environment:
- CLICKHOUSE_CONFIG=/etc/clickhouse-server/config.xml
- CLICKHOUSE_HTTP_PORT=8123
- CLICKHOUSE_TCP_PORT=9000
volumes:
- ./config.xml:/etc/clickhouse-server/config.xml
ports:
- "8125:8123"
- "9002:9000"
networks:
ch-network:
ipv4_address: 192.168.100.103
networks:
ch-network:
driver: bridge
ipam:
config:
- subnet: 192.168.100.0/24
4. ClickHouse配置文件
每个节点都需要相同的配置文件,在本地创建config.xml配置文件:
<yandex>
<http_server>
<listen_host>::</listen_host>
<listen_port>8123</listen_port>
<http_handler>
<default_database>default</default_database>
<listen_try_count>3</listen_try_count>
<base_path>/</base_path>
<keep_alive_timeout>5</keep_alive_timeout>
<restrict_concurrency>true</restrict_concurrency>
<max_concurrent_queries_for_user>0</max_concurrent_queries_for_user>
</http_handler>
</http_server>
<tcp_port>9000</tcp_port>
<listen_host>0.0.0.0</listen_host>
<interserver_http_port>9009</interserver_http_port>
<default_max_memory_usage_ratio>0.6</default_max_memory_usage_ratio>
<zookeeper>
<node>
<host>192.168.100.101</host>
<port>2181</port>
</node>
<node>
<host>192.168.100.102</host>
<port>2181</port>
</node>
<node>
<host>192.168.100.103</host>
<port>2181</port>
</node>
<base_path>/clickhouse/tables/</base_path>
</zookeeper>
</yandex>
5. 启动ClickHouse集群
在新建的目录下运行以下命令启动ClickHouse集群:
docker-compose up -d
6. 测试ClickHouse集群
使用以下命令登录到其中一个节点:
docker exec -it clickhouse_node1 /bin/bash
使用以下命令连接集群并创建一个数据库 :
clickhouse-client --host=clickhouse-node1 --port=9000 -u default --password=
CREATE DATABASE test;
退出后使用以下命令杀死并删除容器:
docker-compose down
示例1:如何扩展集群
在docker-compose.yml文件中添加以下内容:
services:
clickhouse-node4:
image: yandex/clickhouse-server
container_name: clickhouse_node4
environment:
- CLICKHOUSE_CONFIG=/etc/clickhouse-server/config.xml
- CLICKHOUSE_HTTP_PORT=8123
- CLICKHOUSE_TCP_PORT=9000
volumes:
- ./config.xml:/etc/clickhouse-server/config.xml
ports:
- "8126:8123"
- "9003:9000"
networks:
ch-network:
ipv4_address: 192.168.100.104
然后运行以下命令重新启动集群:
docker-compose up -d
使用以下命令登录到该节点:
docker exec -it clickhouse_node4 /bin/bash
使用以下命令连接到集群并创建一个数据库:
clickhouse-client --host=clickhouse-node1,clickhouse-node2,clickhouse-node3,clickhouse-node4 --port=9000 -u default --password=
CREATE DATABASE test;
示例2:如何修改配置文件
使用以下命令重启ClickHouse集群:
docker-compose down
docker-compose up -d
在本地修改config.xml文件后,可以通过以下命令将更改的配置文件覆盖到对应的容器中:
docker cp config.xml clickhouse_node1:/etc/clickhouse-server/config.xml
docker cp config.xml clickhouse_node2:/etc/clickhouse-server/config.xml
docker cp config.xml clickhouse_node3:/etc/clickhouse-server/config.xml
然后重启集群:
docker-compose down
docker-compose up -d
就是这样了,以上就是“以示例讲解ClickHouse Docker集群部署以及配置”的完整攻略。
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:以示例讲解Clickhouse Docker集群部署以及配置 - Python技术站