今天发现之前2种方式安装的ck时间不一致,记录一下解决方案:
一、ck容器不一致
1、查看服务器时区
[root@localhost ~]# timedatectl status
Local time: 二 2024-01-30 17:02:01 CST
Universal time: 二 2024-01-30 09:02:01 UTC
RTC time: 二 2024-01-30 09:02:00
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
2、 进入容器查看时间
root@e9ffa84e7b00:/# date
Tue 30 Jan 2024 05:05:16 PM CST
3、关闭容器、在run命令后添加参数-e TZ=Asia/Shanghai,或者通过docker-compose指定环境变量- TZ=Asia/Shanghai
version: '3'
services:
clickhouse:
environment:
- TZ=Asia/Shanghai
image: yandex/clickhouse-server:latest
container_name: clickhouse
restart: always
networks:
- deng
ports:
- "8123:8123"
- "19000:9000"
volumes:
# 默认配置
- ./config/docker_related_config.xml:/etc/clickhouse-server/config.d/docker_related_config.xml:rw
- ./config/config.xml:/etc/clickhouse-server/config.xml:rw
- ./config/users.xml:/etc/clickhouse-server/users.xml:rw
- /etc/localtime:/etc/localtime:ro
# 运行日志
- ./log:/var/log/clickhouse-server
# 数据持久
- ./data:/var/lib/clickhouse:rw
networks:
deng:
external: true
再重启容器
docker-compose -f docker-compose-ch-2.yaml down
docker-compose -f docker-compose-ch-2.yaml up -d
二、通过命令直装ck,修改时区
1、查看时区,是America/New_York
[root@localhost clickhouse-server]# timedatectl status
Local time: 二 2024-01-30 17:02:07 CST
Universal time: 二 2024-01-30 09:02:07 UTC
RTC time: 二 2024-01-30 09:02:07
Time zone: America/New_York (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
2、设置时区
sudo timedatectl set-timezone Asia/Shanghai
3、重启ck
systemctl stop clickhouse-server
sudo /etc/init.d/clickhouse-server start
或者
sudo /etc/init.d/clickhouse-server restart