CentOS7之前采用ntp服务自动同步时间,CentOS7推荐使用chrony同步时间,当然ntp仍然可以使用,chrony官网列举了诸多chrony优于ntp的功能(ntp与chrony的对比:https://chrony.tuxfamily.org/comparison.html)。
此外我们若要立刻将系统时间同步为NTP服务时间,使用ntpdate命令,也可以配置计划任务定期使用ntpdate命令同步时间,从而就不用使用ntp或chrony服务,减少监听的端口,增加系统安全性。
chrony的安装配置
安装chrony
$ yum -y install chrony
配置chrony
$ vim /etc/chrony.conf
server ntp1.alyun.com
server ntp2.alyun.com
server ntp3.alyun.com
#server 0.centos.pool.ntp.org iburst
…
启动chrony
$ systemctl start chronyd
ntpdate -u ntp.api.bz