Docker方式部署ClickHouse
ClickHouse docker 版本镜像:https://docker.aityp.com/r/docker.io/clickhouse/clickhouse-server
ClickHouse 21.8.13.6 docker 版本镜像:https://docker.aityp.com/image/docker.io/clickhouse/clickhouse-server:21.8.13.6
docker pull swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/clickhouse/clickhouse-server:21.8.13.6
docker tag swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/clickhouse/clickhouse-server:21.8.13.6 clickhouse/clickhouse-server:21.8.13.6
# 先启动临时容器、查看 config、data、log 路径
docker run --rm -d --name=temp-clickhouse-server clickhouse/clickhouse-server:21.8.13.6
# 查看容器里的相关文件
docker exec temp-clickhouse-server cat /etc/clickhouse-server/config.xml
docker exec temp-clickhouse-server cat /etc/clickhouse-server/users.xml
docker exec temp-clickhouse-server ls -l /var/lib/clickhouse/
docker exec temp-clickhouse-server ls -l /var/log/clickhouse-server
# 或者先进入容器、再查看
docker exec -it temp-clickhouse-server /bin/bash
cat /etc/clickhouse-server/config.xml
cat /etc/clickhouse-server/users.xml
ls -l /var/lib/clickhouse/
ls -l /var/log/clickhouse-server
# 宿主机上创建目录(for 挂载)
mkdir -p /data/clickhouse/conf
mkdir -p /data/clickhouse/data
mkdir -p /data/clickhouse/log
chmod -R 777 /data/clickhouse
# 拷贝容器里的配置文件到本机上,按需修改配置、开放端口、设置密码等。
docker cp temp-clickhouse-server:/etc/clickhouse-server/config.xml /data/clickhouse/conf/config.xml
docker cp temp-clickhouse-server:/etc/clickhouse-server/users.xml /data/clickhouse/conf/users.xml
vim /data/clickhouse/conf/config.xml
<listen_host>0.0.0.0</listen_host>
<password>1q2w3e</password>
# 配置文件中如果配置密文密码、先执行命令生成:
# 执行命令,生成SHA256密码
#生成两个随机密码的明文或密文:
PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
#如果要:生产指定密码的明文和密文(安全性低)
PASSWORD=$(echo "123456"); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
PASSWORD=$(echo "1q2w3e"); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
执行命令后会返回密码明文和密文:
PASSWORD=$(echo "123456"); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
123456
8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92
PASSWORD=$(echo "1q2w3e"); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
1q2w3e
c0c4a69b17a7955ac230bfc8db4a123eaa956ccf3c0022e68b8d4e2f5b699d1f
# 修改用户配置文件
vim /data/clickhouse/conf/users.xml
如果是配置密文密码,配置:
<password_sha256_hex>c0c4a69b17a7955ac230bfc8db4a123eaa956ccf3c0022e68b8d4e2f5b699d1f</password_sha256_hex>
如果是配置明文密码,配置:
<password>1q2w3e</password>
<default>
<password_sha256_hex>8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92</password_sha256_hex>
<networks>
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
<quota>default</quota>
</default>
<root>
<password_sha256_hex>c0c4a69b17a7955ac230bfc8db4a123eaa956ccf3c0022e68b8d4e2f5b699d1f</password_sha256_hex>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</root>
# 停止退出临时容器(临时容器退出、会自动删除)
docker stop temp-clickhouse-server
# 配置文件修改好了以后,启动容器(指定对应的挂载目录和文件)
docker run -d -p 8123:8123 -p 8443:8443 -p 9009:9009 -p 9000:9000 \
--ulimit nofile=262144:262144 \
--volume=/data/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml \
--volume=/data/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml \
--volume=/data/clickhouse/data:/var/lib/clickhouse \
--volume=/data/clickhouse/log:/var/log/clickhouse-server \
--name clickhouse-server \
clickhouse/clickhouse-server:21.8.13.6