官方文档 - docker 运行 DockerHub - clickhouse 镜像
先准备配置文件
docker run -d --name clickhouse-server --ulimit -e nofile=262144:262144 -e CLICKHOUSE_USER=root -e CLICKHOUSE_PASSWORD=root clickhouse/clickhouse-server:22.6.4.35
docker cp clickhouse-server:/etc/clickhouse-server/ ./etc
docker rm -f clickhouse-server
docker-compose.yml
version: '3.1'
services:
clickhouse:
container_name: clickhouse
image: clickhouse/clickhouse-server:22.6.4.35
restart: always
environment:
TZ: Asia/Shanghai
CLICKHOUSE_USER: root
CLICKHOUSE_PASSWORD: root
nofile: "262144:262144"
volumes:
- ./clickhouse/data/:/var/lib/clickhouse/
- ./clickhouse/logs/:/val/log/clickhouse-server/
- ./clickhouse/etc/clickhouse-server/:/etc/clickhouse-server/
#- ./clickhouse/config.yaml:/etc/clickhouse-server/config.yaml
ports:
- 18123:8123
- 19000:9000
# 容器拥有 root 权限
user: root
privileged: true
说下注意事项:
TZ
:前面说过了设置 docker 容器的时区CLICKHOUSE_USER
:创建的用户名不能是全数字,否则容器会启动不起来/var/lib/clickhouse/
:是数据目录/val/log/clickhouse-server/
:是日志目录/etc/clickhouse-server/config.yaml
:是服务器配置,暂时是个空文件,没有的话就以默认值运行/etc/clickhouse-server/
:在最开始,将配置文件都复制出来了,所以这里映射的就是复制出来的目录
:::tips
在 windows 上挂载目录在 insert 数据的时候会报错(说权限不够,这个不知道怎么解决)
Received exception from server (version 22.6.4):
Code: 481. DB::Exception: Received from localhost:9000. DB::ErrnoException. DB::ErrnoException: Cannot set modification time for file: /var/lib/clickhouse/store/7cc/7cc2fcd2-de0e-4f34-a0be-2d7c4545e965/tmp_insert_201507_7_7_0/, errno: 1, strerror: Operation not permitted. (PATH_ACCESS_DENIED)
:::
集群如何搭建
请参考其他大佬写的 CSDN 博客文章
如何使用 UI 工具连接
使用什么 UI 工具连接?Idea 全家桶里面的 DataGrip 工具可以连接,如下所示
其他笔记教程请参考