CentOS8上启用时间服务器、同步时间

2021-10-18 1041点热度 0人点赞 0条评论

前言

在CentOS7以前,都是用ntpd来同步时间的,如何配置详见之前的文章:https://blog.terrynow.com/2021/10/17/centos7-sync-time-automatically-with-ntp/

安装

装了CentOS8后,发现yun仓库里已经找不到ntp了,原来CentOS8已经把时间同步软件换成了chrony了,一般来说默认安装的CentOS8已经包含chrony了,如果没有安装,可以手动安装下

#检查chrony是否安装
[root@localhost ~]#rpm -q chrony
package chrony is not installed

#没有安装的话,就用yum安装chrony
[root@localhost ~]#yum install chrony

配置

chrony和ntpd一样,都是既做服务端,又可以当做客户端的。配置文件在/etc/chrony.conf

  • 作为服务器端的配置

修改配置文件/etc/chrony.conf

server后面的就是上游ntp服务器的地址,这里是ntp.aliyun.com的公益ntp服务器地址,allow 192.168/16 如果取消注释,就是允许192.168.0.0/16网段的客户机作为客户端来同步时间

#启动chronyd服务
systemctl start chronyd
#开机启动
systemctl enable chronyd
  • 作为客户端的配置

修改配置文件/etc/chrony.conf

同样是这个配置文件,只需要把server后面ntp.aliyun.com修改成实际的地址即可,后者填入内网的ntp服务器的ip地址

  • 防火墙端口放行

防火墙端口和ntp一样,也是使用的123/udp端口,可以根据自己的防火墙(firewalld或者iptables)添加放行端口

#firewalld
firewall-cmd --permanent --add-service=ntp
firewall-cmd --reload
#iptables
iptables -A INPUT -p udp --dport 123 -j ACCEPT
  • chrony其他命令介绍

chronyc sources: 查看当前的同步源

chronyc sourcestats -v: 查看当前的同步状态

chronyc -a makestep: 手动同步时间

chronyc tracking: 显示系统时间信息

chronyc: 进入交互式界面进行相关的操作,具体可以输入help查看对应的帮助.

[root@ecs-587c ~]# chronyc sources -v
210 Number of sources = 1

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 100.125.0.251                 3   6   377    43    +13us[  +13us] +/-  146ms
[root@ecs-587c ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================

[root@ecs-587c ~]# chronyc sourcestats -v
210 Number of sources = 1
.- Number of sample points in measurement set.
/ .- Number of residual runs with same sign.
| / .- Length of measurement set (time).
| | / .- Est. clock freq error (ppm).
| | | / .- Est. error in freq.
| | | | / .- Est. offset.
| | | | | | On the -.
| | | | | | samples. \
| | | | | | |
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
==============================================================================
100.125.0.251 30 18 929 +0.000 0.025 +10ns 8817ns

 

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论