1.新建docker-compose.yml文件
version: '3.3'
services:
clickhouse:
image: clickhouse/clickhouse-server:latest
container_name: clickhouse
#restart: always
# network_mode: host
ports:
- "18123:8123"
- "19000:9000"
volumes:
# 默认配置
- /etc/localtime:/etc/localtime:ro
# 运行日志
- ./data/clickhouse/log:/var/log/clickhouse-server
# 数据持久
- ./data/clickhouse:/var/lib/clickhouse:rw
# 挂载配置
- ./config/docker_related_config.xml:/etc/clickhouse-server/config.d/docker_related_config.xml:rw
- ./config/config.xml:/etc/clickhouse-server/config.xml:rw
- ./config/users.xml:/etc/clickhouse-server/users.xml:rw
注意:挂载配置下面三行先注释掉,否则无法启动 2.当前目录新增config目录,方便后续从docker复制配置文件出来 3.启动:docker-compose up -d 4.进入容器
docker exec -it clickhouse /bin/bash
5.生成登录密码(123456),后面需要用到
执行:PASSWORD=$(base64 < /dev/urandom | head -c8); echo "123456"; echo -n "123456" | sha256sum | tr -d '-
得到:8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92
6.退出容器,并拷贝配置文件到新建的config目录
docker cp clickhouse:/etc/clickhouse-server/config.xml ./config
docker cp clickhouse:/etc/clickhouse-server/users.xml ./config
docker cp clickhouse:/etc/clickhouse-server/config.d/docker_related_config.xml ./config
7.修改users.xml文件
删除password节点(默认为default节点下/default用户)
<password></password>
新增password_sha256_hex节点,内容未上面生成的密码
<password_sha256_hex>8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92</password_sha256_hex>
8.修改docker_related_config.xml文件
注释当前节点
<listen_host>::</listen_host>
打开此节点
<listen_host>0.0.0.0</listen_host>
9.解除docker-compose.yml下的挂载配置并重启 10.下载dbeaver https://dbeaver.io/download/