1、安装chrony命令
centos9里是预安装的,没有安装的话执行以下命令:
yum install -y chrony
说明:centos9 时间同步要使用chrony命令,ntp命令不能使用了
2、查看chrony状态
#启用chronyd服务 systemctl enable chronyd #重启chronyd服务 systemctl restart chronyd #查看chronyd服务状态 systemctl status chronyd
3、修改配置文件,将第三行注释后添加如下内容
vim /etc/chrony.conf # use public servers from the pool.ntp.org project. # please consider joining the pool (https://www.pool.ntp.org/join.html). #pool 2.centos.pool.ntp.org iburst pool ntp1.aliyun.com iburst pool ntp2.aliyun.com iburst pool ntp3.aliyun.com iburst pool ntp4.aliyun.com iburst pool ntp5.aliyun.com iburst pool ntp6.aliyun.com iburst
4、重启chronyd服务
systemctl restart chronyd
5、查看同步情况
通过命令进行查看是否同步,出现^*即表示有可同步的源
chronyc sources ms name/ip address stratum poll reach lastrx last sample =============================================================================== ^- 120.25.115.20 2 6 255 83 -4786us[-7195us] +/- 89ms ^* 203.107.6.88 2 6 367 26 -3585us[-5936us] +/- 97ms
system clock synchronized: yes 表示同步成功
timedatectl local time: 一 2024-04-15 10:28:28 cst universal time: 一 2024-04-15 02:28:28 utc rtc time: 一 2024-04-15 02:28:29 time zone: asia/shanghai (cst, +0800) system clock synchronized: yes # 表示同步成功 ntp service: active rtc in local tz: no
6、设置时区
如果时区不对,需要执行以下命令,修改时区
执行如下命令修改时区:
timedatectl set-timezone asia/shanghai
到此这篇关于centos stream release 9 使用chrony服务同步时间的文章就介绍到这了,更多相关centos chrony服务同步时间内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论