安装配置
- 创建目录并更改权限
mkdir -p /app/cloud/clickhouse/data
mkdir -p /app/cloud/clickhouse/conf
mkdir -p /app/cloud/clickhouse/log
chmod -R 777 /app/cloud/clickhouse/data
chmod -R 777 /app/cloud/clickhouse/conf
chmod -R 777 /app/cloud/clickhouse/log
- 拉取镜像
docker pull yandex/clickhouse-server:20.3.5.21
查看 https://hub.docker.com/r/yandex/clickhouse-server/dockerfile 文件,EXPOSE 9000 8123 9009 了三个端口,而宿主机9000端口已被 MinIO 对象存储服务器占用,所以创建容器暴露该端口用9090替换
root@jazz-pc:~# docker ps --format "table {{.Names}} ------> {{.Ports}}" | grep minio
minio ------> 0.0.0.0:9000->9000/tcp
- 创建临时容器
docker run --rm -d --name=clickhouse-server \
--ulimit nofile=262144:262144 \
-p 8123:8123 -p 9009:9009 -p 9090:9000 \
yandex/clickhouse-server:20.3.5.21
- 复制临时容器内配置文件到宿主机
docker cp clickhouse-server:/etc/clickhouse-server/config.xml /app/cloud/clickhouse/conf/config.xml
docker cp clickhouse-server:/etc/clickhouse-server/users.xml /app/cloud/clickhouse/conf/users.xml
- 停掉临时容器
docker stop clickhouse-server
- 创建default账号密码
PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
会输出明码和SHA256密码 SEGByR98 211371f5bc54970907173acf6facb35f0acbc17913e1b71b814117667c01d96d
- 创建root账号密码
PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
会输出明码和SHA256密码 092j3AnV 35542ded44184b1b4b6cd621e052662578025b58b4187176a3ad2b9548c8356e
修改 /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 /app/cloud/clickhouse/data:/var/lib/clickhouse:rw \
-v /app/cloud/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml \
-v /app/cloud/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml \
-v /app/cloud/clickhouse/log:/var/log/clickhouse-server:rw \
yandex/clickhouse-server:20.3.5.21