ClickHouse 使用 docker 部署

2024-02-20  本文已影响0人  偷油考拉

一、部署 docker 运行环境

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
cat <<EOF > /etc/docker/daemon.json
{
   "registry-mirrors": [
   "https://mirror.ccs.tencentyun.com"
  ]
}
EOF
sudo systemctl enable --now docker

二、 在 docker 部署 clickhouse

mkdir -p /lvmdata/clickhouse/{logs,data}
docker run -d -p 8123:8123 -p9000:9000 -p9009:9009\
    -v /lvmdata/clickhouse/data:/var/lib/clickhouse/ \
    -v /lvmdata/clickhouse/logs:/var/log/clickhouse-server/ \
    --name ch --ulimit nofile=262144:262144 clickhouse/clickhouse-server
[root@VM-201-2-centos ~]# echo 'SELECT version()' | curl 'http://localhost:8123/' --data-binary @-
24.1.5.6

By default, starting above server instance will be run as the default user without password.

[root@VM-201-2-centos ~]# curl http://10.41.201.2:8123
Ok.
[root@VM-201-2-centos ~]# echo 'SELECT 1' | curl 'http://10.41.201.2:8123/' --data-binary @-
1
[root@VM-201-2-centos jaeger-clickhouse]# echo 'CREATE DATABASE IF NOT EXISTS jaeger;' | curl 'http://10.41.201.2:8123/' --data-binary @-
[root@VM-201-2-centos jaeger-clickhouse]# echo 'show databases;' | curl 'http://10.41.201.2:8123/' --data-binary @-
INFORMATION_SCHEMA
default
information_schema
jaeger
system

三、 docker部署的同时,创建数据库

使用默认配置可不创建。因为用户名默认 default,密码 空,数据库 default。CH初始化就是这样的。
如下仅示范创建。

https://clickhouse.com/docs/en/interfaces/http

docker run -d -p 8123:8123 -p9000:9000 -p9009:9009\
    -e CLICKHOUSE_DB=jaeger \
    -e CLICKHOUSE_USER=jaeger  \
    -e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 \
    -e CLICKHOUSE_PASSWORD=jaeger \
    -v /lvmdata/clickhouse/data:/var/lib/clickhouse/ \
    -v /lvmdata/clickhouse/logs:/var/log/clickhouse-server/ \
    --name ch --ulimit nofile=262144:262144 clickhouse/clickhouse-server:24.1.3

存在有些版本创建不了数据库的BUG。

[root@VM-201-2-centos clickhouse]# echo 'SELECT 1' | curl 'http://localhost:8123/' --data-binary @- -ujaeger:jaeger
1
[root@VM-201-2-centos clickhouse]# echo 'show databases' | curl 'http://localhost:8123/' --data-binary @- -ujaeger:jaeger
INFORMATION_SCHEMA
default
information_schema
jaeger
system

四、时区问题

[root@VM-201-2-centos clickhouse]# docker exec -it ch date
Wed 21 Feb 2024 07:36:44 AM UTC
docker run -d -p 8123:8123 -p9000:9000 -p9009:9009\
    -e TZ='Asia/Shanghai' \
    -e CLICKHOUSE_DB=jaeger \
    -e CLICKHOUSE_USER=jaeger  \
    -e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 \
    -e CLICKHOUSE_PASSWORD=jaeger \
    -v /lvmdata/clickhouse/data:/var/lib/clickhouse/ \
    -v /lvmdata/clickhouse/logs:/var/log/clickhouse-server/ \
    --name ch --ulimit nofile=262144:262144 clickhouse/clickhouse-server:24.1.3

[root@VM-201-2-centos clickhouse]# docker exec -it ch date
Wed 21 Feb 2024 03:39:39 PM CST
上一篇下一篇

猜你喜欢

热点阅读