一、什么是 NTP
NTP(Network Time Protocol,网络时间协议) 是一种用于在网络中同步计算机时间的协议。它运行在 TCP/IP 协议栈的应用层,通过 UDP 123 端口与 NTP 服务器进行时间交换,使得网络中各设备的系统时间保持一致。NTP 支持分层结构(Stratum 级别)来组织时间源,从最高精度时间源(如原子钟、GPS)到普通客户端。
二、NTP 的作用
NTP 的主要目的就是保证网络设备(如服务器、路由器、PC、手机等)时间的一致性。不同设备本地时钟可能会有漂移,如果时间不一致,会对日志分析、分布式系统、认证系统(如 Kerberos)、安全证书验证等造成严重影响。
三、常用NTP 服务器列表
1. 系统默认/常见通用服务器
1 2 3 4 5
| time.windows.com time.nist.gov time.apple.com time.asia.apple.com cn.ntp.org.cn
|
2. 阿里云授时服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| # NTP 服务器 ntp1.aliyun.com ntp2.aliyun.com ntp3.aliyun.com ntp4.aliyun.com ntp5.aliyun.com ntp6.aliyun.com ntp7.aliyun.com
# Time 服务器 time1.aliyun.com time2.aliyun.com time3.aliyun.com time4.aliyun.com time5.aliyun.com time6.aliyun.com time7.aliyun.com
|
3. 国内大学授时服务器
1 2 3 4 5 6
| s1c.time.edu.cn # 北京大学 s2m.time.edu.cn # 北京大学 s1b.time.edu.cn # 清华大学 s1e.time.edu.cn # 清华大学 s2a.time.edu.cn # 清华大学 s2b.time.edu.cn # 清华大学
|
4. 国外授时服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| # 苹果提供的授时服务器 time1.apple.com time2.apple.com time3.apple.com time4.apple.com time5.apple.com time6.apple.com time7.apple.com
# Google 提供的授时服务器 time1.google.com time2.google.com time3.google.com time4.google.com
|
四、如何配置 NTP
在 Windows 系统上设置
通过“控制面板 → 时钟、语言和区域 → 设置时间和日期 → Internet 时间 → 更改设置”进入设置界面,然后添加或修改 NTP 服务器地址。
在 Linux 上设置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| yum install ntp
server ntp1.aliyun.com prefer server ntp2.aliyun.com
ntpdate ntp1.aliyun.com
service ntpd start
chkconfig ntpd on
chkconfig --list ntpd
|
五、小提示
- 使用多个 NTP 服务器可以提高可靠性,推荐至少配置 2~3 个不同的时间源。
- NTP 依赖网络与 UDP 123 端口,如果防火墙或网络策略阻断了 UDP 123,会导致无法同步时间。
- NTP 不是加密协议,因此在对安全有更高要求的场景,可以考虑更安全的时间同步方案