安装chrony

yum install chrony -y

查看chrony的程序运行环境

▶ rpm -ql chrony
/etc/NetworkManager/dispatcher.d/20-chrony
/etc/chrony.conf 主配置文件
/etc/chrony.keys
/etc/dhcp/dhclient.d/chrony.sh
/etc/logrotate.d/chrony
/etc/sysconfig/chronyd
/usr/bin/chronyc 客户端可执行文件
...

使用man chrony.conf了解配置文件的格式

配置

  1. 配置chronyd服务开机自启

systemctl enable chronyd.service

  1. 重启chronyd服务

systemctl restart chronyd.service

  1. 查看chronyd服务状态

systemctl status chronyd.service

编辑/etc/chrony.conf配置文件:

  1 # Use public servers from the pool.ntp.org project.
  2 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  3 #server 0.centos.pool.ntp.org iburst
  4 #server 1.centos.pool.ntp.org iburst
  5 #server 2.centos.pool.ntp.org iburst
  6 #server 3.centos.pool.ntp.org iburst
  7 
  8 server ntp1.aliyun.com iburst # 替换为aliyun服务器
  9 server ntp2.aliyun.com iburst
 10 server ntp3.aliyun.com iburst
 11 server ntp4.aliyun.com iburst
 12 
 13 # Record the rate at which the system clock gains/losses time.
 14 driftfile /var/lib/chrony/drift
 15 
 16 # Allow the system clock to be stepped in the first three updates
 17 # if its offset is larger than 1 second.
 18 makestep 1.0 3
 19 
 20 # Enable kernel synchronization of the real-time clock (RTC).
 21 rtcsync
 22 
 23 # Enable hardware timestamping on all interfaces that support it.
 24 #hwtimestamp *
 25 
 26 # Increase the minimum number of selectable sources required to adjust
 27 # the system clock.
 28 #minsources 2
 29 
 30 # Allow NTP client access from local network.
 31 #allow 192.168.0.0/16
 32 
 33 # Serve time even if not synchronized to a time source.
 34 #local stratum 10
 35 
 36 # Specify file containing keys for NTP authentication.
 37 #keyfile /etc/chrony.keys
 38 
 39 # Specify directory for log files.
 40 logdir /var/log/chrony
 41 
 42 # Select which information is logged.
 43 #log measurements statistics tracking

手动强制同步系统时钟

chronyc -a makestep