☛ 概述
Network Time Protocol简称(ntp),是一个能使计算机之间实现时间同步的协议,发布这个校准时间的服务器就是NTP server。一般来说客户端与时间服务器之间的时间误差应该在几十毫秒以内,如果时间服务器在美国或者欧洲,误差可能稍大一些。大陆的 NTP Server 基本都属于科研教育机构所有,普通社会组织发布的 NTP Server 并不多,以下是一些大陆可用的 NTP 伺服器:
① 1.cn.pool.ntp.org
② 2.cn.pool.ntp.org
③ 3.cn.pool.ntp.org
④ 0.cn.pool.ntp.org
⑤ cn.pool.ntp.org
⑥ tw.pool.ntp.org
⑦ 0.tw.pool.ntp.org
⑧ 1.tw.pool.ntp.org
⑨ 2.tw.pool.ntp.org
⑩ 3.tw.pool.ntp.org
台湾惯用公开时 NTP 伺服器如下:
① time.stdtime.gov.tw
② tock.stdtime.gov.tw
③ tick.stdtime.gov.tw
④ clock.stdtime.gov.tw
⑤ watch.stdtime.gov.tw
☛ 安装
检查一下系统是否有安装 ntp 这个套件:
[root@localhost ~ ]# yum list installed ntp
如果出现 Error: No matching Packages to list 的消息,就表示系统上没有安装 ntp 套件,请用 yum 安装:
[root@localhost ~ ]# yum install ntp -y
☛ 设定 NTP 服务
使用 gedit 修改 /etc/ntp.conf 设定档的内容,如下所示:
# Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. restrict 127.0.0.1 restrict ::1 restrict tock.stdtime.gov.tw restrict tick.stdtime.gov.tw restrict time.stdtime.gov.tw # Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server tock.stdtime.gov.tw prefer server tick.stdtime.gov.tw server time.stdtime.gov.tw
接下来修改 /etc/sysconfig/ntpd,设定 BIOS 的时间也同步调整,如下所示:
# Drop root to id 'ntp:ntp' by default. OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g" SYNC_HWCLOCK=yes
☛ 启动 NTP 服务
修改好 NTP 的设定档之后,启动 ntpd 服务:
[root@localhost ~ ]# systemctl start ntpd [root@localhost ~ ]# systemctl enable ntpd
检查是否有正确执行( 需要等一段时间让 NTP Server与上层同步完成 ),如下:
[root@localhost ~ ]# ntpstat synchronised to NTP server (211.22.103.157) at stratum 3 time correct to within 104 ms polling server every 64 s
出现以上字样即表示已经与上层 Server 完成同步。
☛ 应用
完成了 NTP 伺服器建置后,可将区域网路内的网路设备与 NTP 伺服器进行时间同步校准,范例 ( ASUS RT-AC51U 路由器 ) 如下: