安装配置
创建目录并更改权限
mkdir -p /home/db/clickhouse/data
mkdir -p /home/db/clickhouse/conf
mkdir -p /home/db/clickhouse/log
chmod -R 777 /home/db/clickhouse/data
chmod -R 777 /home/db/clickhouse/conf
chmod -R 777 /home/db/clickhouse/log
拉取镜像
docker pull yandex/clickhouse-server
查看 Docker Hub 文件,EXPOSE 9000 8123 9009 了三个端口,而宿主机9000端口已被其他服务占用,所以创建容器暴露该端口用9090替换
创建临时容器
docker run --rm -d --name=clickhouse-server \
--ulimit nofile=262144:262144 \
-p 8123:8123 -p 9009:9009 -p 9090:9000 \
yandex/clickhouse-server
复制临时容器内配置文件到宿主机
docker cp clickhouse-server:/etc/clickhouse-server/config.xml /home/db/clickhouse/conf/config.xml
docker cp clickhouse-server:/etc/clickhouse-server/users.xml /home/db/clickhouse/conf/users.xml
停掉临时容器
docker stop clickhouse-server
创建default账号密码
PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
会输出明码和SHA256密码
创建root账号密码
PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
会输出明码和SHA256密码
修改用户配置
修改 /home/db/clickhouse/conf/users.xml
把default账号设为只读权限,并设置密码
yandex-->users-->default-->profile 节点设为 readonly
注释掉 yandex-->users-->default-->password 节点
新增 yandex-->users-->default-->password_sha256_hex 节点,填入生成的密码
新增root账号
<users>
<default>
<!-- JrARTWjQ -->
<password_sha256_hex>8073e9f23aa46133fc66d82c4beb99e8f0968e3897a7d778c026d2d018e2adec</password_sha256_hex>
<networks>
<ip>::/0</ip>
</networks>
<profile>readonly</profile>
<quota>default</quota>
</default>
<root>
<!-- iWHKyllv -->
<password_sha256_hex>534c12f815bd35ba3d6f7bb746de195f8be6f305ecad2c1b1843d8f42d38abd4</password_sha256_hex>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</root>
</users>
创建容器
docker run -d --name=clickhouse-server \
-p 8123:8123 -p 9009:9009 -p 9090:9000 \
--ulimit nofile=262144:262144 \
-v /home/db/clickhouse/data:/var/lib/clickhouse:rw \
-v /home/db/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml \
-v /home/db/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml \
-v /home/db/clickhouse/log:/var/log/clickhouse-server:rw \
yandex/clickhouse-server