时间同步
ntp 服务
1$ yum -y install ntp
2
3$ vim /etc/ntp.conf
4...
5server ntp1.aliyun.com
6server ntp2.aliyun.com
7server ntp3.aliyun.com
8#server 0.centos.pool.ntp.org iburst
9
10$ systemctl start ntpd
ntpdate 命令
此外我们若要立刻将系统时间同步为 NTP 服务时间,使用 ntpdate 命令,也可以配置计划任务定期使用 ntpdate 命令同步时间,从而就不用使用 ntp 或 chrony 服务,减少监听的端口,增加系统安全性。
1# 需要关闭ntpd or chrony 服务,否则会报错
2$ service ntpd stop
3
4# 启动并开机启动计划任务cron
5$ systemctl start crond
6$ systemctl enable crond
7
8# 配置计划任务,每5分钟同步一次
9$ crontab -e
10*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com
11
chrony 服务
CentOS7 之前采用 ntp 服务自动同步时间,CentOS7 推荐使用 chrony 同步时间,当然 ntp 仍然可以使用,chrony 官网列举了诸多 chrony 优于 ntp 的功能(ntp 与 chrony 的对比:https://chrony.tuxfamily.org/comparison.html)。
1$ yum -y install chrony
2
3$ vim /etc/chrony.conf
4server ntp1.alyun.com
5server ntp2.alyun.com
6server ntp3.alyun.com
7#server 0.centos.pool.ntp.org iburst
8...
9
10$ systemctl start chronyd