分类: Linux
AlmaLinux 9使用Chrony设置NTP并同步时间

网络时间协议是一种用于同步网络中所有系统时钟以使用相同的协议时间。
Chrony 是网络时间协议 (NTP) 的实现。 Chrony 通常将计算机同步到 Internet 时间服务器或其他来源,例如无线电或卫星接收器或电话调制解调器服务。 它也可以用作客户端系统的时间源/服务器。
实现步骤如下:
1、查看并更新系统:

[root@Alma9 ~]# cat /etc/redhat-release
AlmaLinux release 9.1 (Lime Lynx)

[root@Alma9 ~]# dnf update -y
[root@Alma9 ~]# dnf install epel-release -y

2、安装并设置:

dnf install chrony -y
systemctl enable chronyd
systemctl start chronyd

3、修改配置:/etc/chrony.conf

[root@Alma9 ~]# grep -v '#' /etc/chrony.conf
pool cn.ntp.org.cn iburst       
sourcedir /run/chrony-dhcp
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
keyfile /etc/chrony.keys
ntsdumpdir /var/lib/chrony
leapsectz right/UTC
logdir /var/log/chrony

4、重新启动 chrony NTP 守护进程以应用更改:

systemctl restart chronyd

5、查看同步状态:

[root@Alma9 ~]# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^- 36.154.179.82                 3   6   377    57  +6312us[+5395us] +/-  324ms
^* 106.75.107.80                 2   6   377    55   -793us[-1713us] +/-   16ms
^- 1.14.61.51                    3   6   377    56  -3489us[-4408us] +/-   75ms

[root@Alma9 ~]# systemctl status chronyd
● chronyd.service - NTP client/server
     Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-11-29 12:53:03 CST; 14min ago
       Docs: man:chronyd(8)
             man:chrony.conf(5)
   Main PID: 14812 (chronyd)
      Tasks: 1 (limit: 11077)
     Memory: 952.0K
        CPU: 36ms
     CGroup: /system.slice/chronyd.service
             └─14812 /usr/sbin/chronyd -F 2

Nov 29 12:53:03 Alma9.1 systemd[1]: Starting NTP client/server...
Nov 29 12:53:03 Alma9.1 chronyd[14812]: chronyd version 4.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +NTS +SECHASH +IPV6 +DEBUG)
Nov 29 12:53:03 Alma9.1 chronyd[14812]: Frequency -11.969 +/- 0.295 ppm read from /var/lib/chrony/drift
Nov 29 12:53:03 Alma9.1 chronyd[14812]: Using right/UTC timezone to obtain leap second data
Nov 29 12:53:03 Alma9.1 chronyd[14812]: Loaded seccomp filter (level 2)
Nov 29 12:53:03 Alma9.1 systemd[1]: Started NTP client/server.
Nov 29 12:53:08 Alma9.1 chronyd[14812]: Selected source 106.75.107.80 (cn.ntp.org.cn)
Nov 29 12:53:08 Alma9.1 chronyd[14812]: System clock TAI offset set to 37 seconds

6、加入开机启动:

systemctl enable chronyd

7、设置添加防火墙:

firewall-cmd --permanent --add-service=ntp
firewall-cmd --reload


相关博文:

发表新评论