centos7使用ntp自动同步时间

使用VMware虚拟机由于电脑关机时,虚拟机没关闭,导致虚拟机被挂起,再打开电脑继续运行虚拟机时,时间就变为上次关闭电脑的时间,导致虚拟机时间不对,下面使用ntp来处理时间同步问题

1.安装ntp

 yum -y install ntp

2.设置开机自启并启动ntp服务

systemctl enable ntpd
systemctl start ntpd

3.使用命令同步时间

ntpdate -u cn.pool.ntp.org

 4.使用crontab定时自动同步时间

echo "*/20 * * * * /usr/sbin/ntpdate -u ntp1.aliyun.com >/dev/null &" >> /var/spool/cron/root

5.常用的ntp服务器

国内:

cn.pool.ntp.org  中国开源免费NTP服务器
ntp1.aliyun.com 阿里云NTP服务器
ntp2.aliyun.com 阿里云NTP服务器
time1.aliyun.com 阿里云NTP服务器
time2.aliyun.com 阿里云NTP服务器

国外:

time1.apple.com 苹果NTP服务器
time2.apple.com 苹果NTP服务器
time3.apple.com 苹果NTP服务器
time4.apple.com 苹果NTP服务器
time5.apple.com 苹果NTP服务器
time1.google.com 谷歌NTP服务器
time2.google.com 谷歌NTP服务器
time3.google.com 谷歌NTP服务器
time4.google.com 谷歌NTP服务器
pool.ntp.org 开源免费NTP服务器
百流积聚,江河是也;文若化风,可以砾石。
原文地址:https://www.cnblogs.com/qixing/p/14295634.html