164 字
1 分钟
Linux服务器配置校时
2025-11-12
无标签
0 次
0 人
数据查不出来?找了半天,md是因为时间不对

在使用服务器时,时间同步很重要,因为很多服务依赖时间,比如数据库、缓存、日志、监控等等。

但是随着运行时间的增长,时间同步的精度会越来越差,因此,建议将服务器的时钟同步到公网时间服务器。

将时区设置为上海#

sudo timedatectl set-timezone Asia/Shanghai

安装时间同步工具 chrony#

# 代理配置
#export http_proxy=http://192.168.1.87:3128
#export https_proxy=http://192.168.1.87:3128
yum install chrony -y
# apt install chrony -y

配置国内 NTP 服务器/配置内网ntp服务器#

sudo vim /etc/chrony.conf
server 192.168.1.244 iburst
server ntp.aliyun.com iburst
server time1.cloud.tencent.com iburst
server ntp1.aliyun.com iburst
server ntp.sjtu.edu.cn iburst
server cn.ntp.org.cn iburst

启动并启用 chronyd 服务\验证 chrony 是否运行#

systemctl enable chronyd --now
systemctl start chronyd
systemctl status chronyd

检查时间同步状态#

## 查看跟踪状态
chronyc tracking
## 查看时间源
chronyc sources -v

设置 timedatectl 使用 NTP#

timedatectl set-ntp true

再次查看时间状态#

timedatectl

如果这篇文章对你有帮助,欢迎分享给更多人!

发现错误或想要改进这篇文章?

在 GitHub 上编辑此页
Linux服务器配置校时
https://m.olinl.com/posts/liunx-chrony/
作者
顾拾柒
发布于
2025-11-12
许可协议
CC BY-NC-SA 4.0