配置环境:
Linux:
[root@localhost conf]# uname -a
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost conf]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
Docker:
[root@localhost conf]# rpm -qa | grep docker
docker-buildx-plugin-0.11.2-1.el7.x86_64
docker-ce-cli-24.0.7-1.el7.x86_64
docker-ce-rootless-extras-24.0.7-1.el7.x86_64
docker-compose-plugin-2.21.0-1.el7.x86_64
docker-ce-24.0.7-1.el7.x86_64
[root@localhost conf]# docker -v
Docker version 24.0.7, build afdd53b
Docker安装配置略
1.下载clickhosue对应的docker安装包:
[root@localhost clickhouse]# docker pull clickhouse/clickhouse-server:21.8.13.6
21.8.13.6: Pulling from clickhouse/clickhouse-server
7b1a6ab2e44d: Pull complete
aad09852ab22: Pull complete
989c863105b3: Pull complete
b31a4d680e91: Pull complete
5ae1f6331138: Pull complete
520dcd02a2d1: Pull complete
2cca46d2b93e: Pull complete
Digest: sha256:1301b70c73f2a14698a2f8807d0c12357f2b2e0198770cc440340bd5a930bf1c
Status: Downloaded newer image for clickhouse/clickhouse-server:21.8.13.6
docker.io/clickhouse/clickhouse-server:21.8.13.6
2.在本地创建相关的目录:
创建数据存储目录:
mkdir -p /usr/local/clickhouse_data/project1/data
创建配置文件目录:
mkdir -p /usr/local/clickhouse_data/project1/conf/
创建日志目录:
/usr/local/clickhouse_data/project1/log
3.创建临时容器,用以生成配置文件
# 容器关闭后会自动删除掉
docker run -d --rm --name clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
.将配置文件复制到 /data/clickhouse/conf 路径下
docker cp clickhouse-server:/etc/clickhouse-server/config.xml /usr/local/clickhouse_data/project1/conf/config.xml
docker cp clickhouse-server:/etc/clickhouse-server/users.xml /usr/local/clickhouse_data/project1/conf/users.xml
关闭临时容器
docker stop clickhouse-server
4.给配置文件目录读写权限:
chown clickhouse.clickhouse /usr/local/clickhouse_data/project1/conf/config.xml
chown clickhouse.clickhouse /usr/local/clickhouse_data/project1/conf/users.xml
chmod 755 /usr/local/clickhouse_data/project1/conf/config.xml
chmod 755 /usr/local/clickhouse_data/project1/conf/users.xml
5.通过以下命令启动docker:
docker run -d --name clickhouse-project1 --ulimit nofile=262144:262144 -p 18123:8123 -p 19000:9000 -p 19009:9009 -p 19004:9004 -p 19005:9005 --privileged=true -v /usr/local/clickhouse_data/project1/log:/var/log/clickhouse-server:rw -v /usr/local/clickhouse_data/project1/data:/var/lib/clickhouse:rw -v /usr/local/clickhouse_data/project1/conf/config.xml:/etc/clickhouse-server/config.xml -v /usr/local/clickhouse_data/project1/conf/users.xml:/etc/clickhouse-server/users.xml clickhouse/clickhouse-server:21.8.13.6
6.查看docker是否启动成功:
[root@localhost conf]# docker ps -a | grep clickhouse
b0d14e224350 clickhouse/clickhouse-server:21.8.13.6 "/entrypoint.sh" 9 minutes ago Up 8 minutes 0.0.0.0:18123->8123/tcp, :::18123->8123/tcp, 0.0.0.0:19000->9000/tcp, :::19000->9000/tcp, 0.0.0.0:19004->9004/tcp, :::19004->9004/tcp, 0.0.0.0:19005->9005/tcp, :::19005->9005/tcp, 0.0.0.0:19009->9009/tcp, :::19009->9009/tcp clickhouse-project1
7.查看系统端口是否有启动:
[root@localhost conf]# netstat -lntup | egrep -E '19000|18123|19004|19005|19009'
tcp 0 0 0.0.0.0:18123 0.0.0.0:* LISTEN 15112/docker-proxy
tcp 0 0 0.0.0.0:19000 0.0.0.0:* LISTEN 15092/docker-proxy
tcp 0 0 0.0.0.0:19004 0.0.0.0:* LISTEN 15069/docker-proxy
tcp 0 0 0.0.0.0:19005 0.0.0.0:* LISTEN 15047/docker-proxy
tcp 0 0 0.0.0.0:19009 0.0.0.0:* LISTEN 15024/docker-proxy
tcp6 0 0 :::18123 :::* LISTEN 15119/docker-proxy
tcp6 0 0 :::19000 :::* LISTEN 15099/docker-proxy
tcp6 0 0 :::19004 :::* LISTEN 15074/docker-proxy
tcp6 0 0 :::19005 :::* LISTEN 15054/docker-proxy
tcp6 0 0 :::19009 :::* LISTEN 15030/docker-proxy
8.通过DBeaver查看是否可以连接到clickhouse,注意,连接的端口为端口映射的18123端口
如果输出以上信息,表示通过docker安装clickhouse服务配置完成