欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 社会 > Docker方式部署ClickHouse

Docker方式部署ClickHouse

2024/10/31 11:22:44 来源:https://blog.csdn.net/sunny05296/article/details/143312771  浏览:    关键词:Docker方式部署ClickHouse


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 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com