拉取镜像

  1. docker pull yandex/clickhouse-server:20.3.5.21

创建临时容器

  1. docker run -d --rm --name=temp yandex/clickhouse-server:20.3.5.21

复制临时容器内配置文件到宿主机

  1. docker cp temp:/etc/clickhouse-server/users.xml /opt/clickhouse/conf/users.xml
  2. docker cp temp:/etc/clickhouse-server/config.xml /opt/clickhouse/conf/config.xml

停掉临时容器

  1. docker stop temp

创建密码

  1. PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'

返回明文密码和SHA256密码

修改 /app/cloud/clickhouse/conf/users.xml
把default账号设为只读权限,并设置密码 yandex—>users—>default—>profile 节点设为 readonly 注释掉 yandex—>users—>default—>password 节点 新增 yandex—>users—>default—>password_sha256_hex 节点,填入生成的密码

新增root账号

  1. <root>
  2. <password_sha256_hex>35542ded44184b1b4b6cd621e052662578025b58b4187176a3ad2b9548c8356e</password_sha256_hex>
  3. <networks incl="networks" replace="replace">
  4. <ip>::/0</ip>
  5. </networks>
  6. <profile>default</profile>
  7. <quota>default</quota>
  8. </root>

创建容器

  1. docker run -d --name=clickhouse-server \
  2. -p 8123:8123 -p 9009:9009 -p 9090:9000 \
  3. --ulimit nofile=262144:262144 \
  4. -v /opt/clickhouse/data:/var/lib/clickhouse:rw \
  5. -v /opt/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml \
  6. -v /opt/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml \
  7. -v /opt/clickhouse/log:/var/log/clickhouse-server:rw \
  8. yandex/clickhouse-server:20.3.5.21