本文主要是介绍解决ck容器与直装时间不一致的问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天发现之前2种方式安装的ck时间不一致,记录一下解决方案:
一、ck容器不一致
1、查看服务器时区
[root@localhost ~]# timedatectl statusLocal time: 二 2024-01-30 17:02:01 CSTUniversal time: 二 2024-01-30 09:02:01 UTCRTC time: 二 2024-01-30 09:02:00Time zone: Asia/Shanghai (CST, +0800)NTP enabled: yes
NTP synchronized: noRTC in local TZ: noDST 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/Shanghaiimage: yandex/clickhouse-server:latestcontainer_name: clickhouserestart: alwaysnetworks:- dengports:- "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:rwnetworks: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 statusLocal time: 二 2024-01-30 17:02:07 CSTUniversal time: 二 2024-01-30 09:02:07 UTCRTC time: 二 2024-01-30 09:02:07Time zone: America/New_York (CST, +0800)NTP enabled: yes
NTP synchronized: yesRTC in local TZ: noDST active: n/a2、设置时区
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
这篇关于解决ck容器与直装时间不一致的问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!