拉取镜像
docker pull yandex/clickhouse-server:20.3.5.21
创建临时容器
docker run -d --rm --name=temp yandex/clickhouse-server:20.3.5.21
复制临时容器内配置文件到宿主机
docker cp temp:/etc/clickhouse-server/users.xml /opt/clickhouse/conf/users.xml
docker cp temp:/etc/clickhouse-server/config.xml /opt/clickhouse/conf/config.xml
停掉临时容器
docker stop temp
创建密码
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账号
<root>
<password_sha256_hex>35542ded44184b1b4b6cd621e052662578025b58b4187176a3ad2b9548c8356e</password_sha256_hex>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</root>
创建容器
docker run -d --name=clickhouse-server \
-p 8123:8123 -p 9009:9009 -p 9090:9000 \
--ulimit nofile=262144:262144 \
-v /opt/clickhouse/data:/var/lib/clickhouse:rw \
-v /opt/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml \
-v /opt/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml \
-v /opt/clickhouse/log:/var/log/clickhouse-server:rw \
yandex/clickhouse-server:20.3.5.21