参考资料
Linux - CentOS7上的时间同步 https://www.cnblogs.com/zhubiao/p/9768209.html
配置Linux实例Chrony服务(CentOS 7) https://help.aliyun.com/document_detail/187016.html?spm=a2c4g.11186623.2.23.54b829c59fG0tc
正文
运行以下命令修改时区
[root@cgmcentos7 ~]# ln -sf /usr/share/zoneinfo/Asia/Hong-Kong /etc/localtime
运行以下命令更新硬件时钟(RTC)
[root@cgmcentos7 ~]# hwclock -w
运行以下命令查看时区
[root@cgmcentos7 ~]# timedatectl status
打开chrony配置文件
[root@cgmcentos7 ~]# vim /etc/chrony.conf
# Use Alibaba NTP server
# Public NTP
# Alicloud NTP
server ntp.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp1.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp1.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp10.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp11.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp12.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp2.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp2.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp3.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp3.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp4.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp4.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp5.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp5.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp6.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp6.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp7.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp8.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp9.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
# Ignore stratum in source selection.
stratumweight 0.05
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# Enable kernel RTC synchronization.
rtcsync
# In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds.
makestep 10 3
# Allow NTP client access from local network.
#allow 192.168/16
# Listen for commands only on localhost.
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
# Disable logging of client accesses.
noclientlog
# Send a message to syslog if a clock adjustment is larger than 0.5 seconds.
logchange 0.5
logdir /var/log/chrony
#log measurements statistics tracking
运行以下命令启动chronyd服务并设置开机自启动。
[root@cgmcentos7 ~]# systemctl start chronyd.service
[root@cgmcentos7 ~]# systemctl enable chronyd.service
运行以下命令查看本机时间同步状态,用于验证服务是否已启动。
[root@cgmcentos7 ~]# chronyc tracking
运行以下命令查看时间同步服务器列表。
[root@cgmcentos7 ~]# chronyc -n sources -v
使用Chrony手动同步时钟
运行以下命令进入Chrony工具。
[root@cgmcentos7 ~]# chronyc
在Chrony工具内,运行makestep命令同步时钟。