Rocky9 linux 时间相关配置

运维

0.前言

对于很多服务而言,服务器时间的准确性是很重要的,今天我们就来看下rocky9 linux系统有哪些和时间相关的命令。

1.手动设置时间

手动设置时间可以用date命令,举例如下:

date 051723052070

2.配置时区

2.1 查看时间信息

timedatectl status

picture.image 可以看到本地时间,世界时间,RTC时间和时区等信息.

2.2 查看可用时区

timedatectl list-timezones

picture.image
可用时区展示如上图所示。

2.3 设置时区

根据服务器展示的时区,可以根据需要将调整服务器时区,命令如下:

timedatectl set-timezone Asia/Shanghai

以上命令可以将时区调整为上海时区。

3.时间同步

今天我们就基于chrony服务,做一下服务器的时间同步。

3.1 安装chrony

安装chrony非常简单,一条命令即可,如下所示:

dnf install chrony -y

3.2 配置chrony

chrony配置文件位置/etc/chrony.conf,可以往配置文件里面添加可用的时间同步服务器地址,这里以server ntp.ntsc.ac.cn iburst,server ntp1.aliyun.com为例. 编辑一下chrony配置文件:

vim /etc/chrony.conf
server ntp.ntsc.ac.cn iburst //中国科学院时间同步服务器
server ntp1.aliyun.com // 阿里云时间同步服务器

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Specify directory for log files.
logdir /var/log/chrony

3.3 启动chrony服务

配置修改完成之后,重启一下chrony服务,就可以完成时间同步了,命令如下:

systemctl restart chronyd

重启之后,查看下当前时间,命令如下:

date
Mon May 19 03:03:24 PM CST 2025

可以看到,时间已经同步完成.

0
0
0
0
关于作者
关于作者

文章

0

获赞

0

收藏

0

相关资源
云原生环境下的日志采集存储分析实践
云原生场景下,日志数据的规模和种类剧增,日志采集、加工、分析的多样性也大大增加。面对这些挑战,火山引擎基于超大规模下的 Kubernetes 日志实践孵化出了一套完整的日志采集、加工、查询、分析、消费的平台。本次主要分享了火山引擎云原生日志平台的相关实践。
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论