网络时间协议NTP(Network Time Protocol)是用于互联网中时间同步的标准互联网协议。NTP的用途是把计算机的时间同步到某些时间标准。目前采用的时间标准是世界协调时UTC(Universal Time Coordinated)。NTP的主要开发者是美国特拉华大学的David L. Mills教授。
NTP对于我们个人来说有什么用呢,简单的讲,当你的计算机时间不准确了,你可以接入到互联网,从网上同步一下时间。
对于企业来说,当你有成百上千的计算机,都不能直接连接互联网,时间不统一影响业务,如果一台一台的修改,工作量太大。这时搭建一个自己的NTP服务器就显出它的优势了。
企业内部架设NTP服务器的大概拓扑如下:
配置好相关的yum源、确保你的ntp服务器可以连网
# vim /etc/resolv.conf
#添加网关,这个可以ipconfig查看默认网关
nameserver 192.168.8.251
配置内网NTP-Server(192.168.8.100)
1、yum安装ntp服务
# yum install -y ntp
配置开机启动
# chkconfig ntpd on
# chkconfig --list ntpd
ntpd 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
2、编辑ntp的配置文件
# vim /etc/ntp.conf 添加如下内容就可以了
# 允许内网网段 192.168.0.0 其他机器同步时间
restrict 192.168.0.0 mask 255.255.0.0 nomodify
# 中国这边最活跃的时间服务器 : http://www.pool.ntp.org/zone/cn
server ntp.api.bz perfer
server 210.72.145.44 # 中国国家受时中心
server 202.112.10.36 # 1.cn.pool.ntp.org
server 59.124.196.83 # 0.asia.pool.ntp.org
# 允许上层时间服务器主动修改本机时间
restrict ntp.api.bz nomodify notrap noquery
restrict 210.72.145.44 nomodify notrap noquery
restrict 202.112.10.36 nomodify notrap noquery
restrict 59.124.196.83 nomodify notrap noquery
# 外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
最终的参数:
# cat /etc/ntp.conf |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}'
或者
# cat /etc/ntp.conf | grep "^[^#]"
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
restrict 192.168.0.0 mask 255.255.0.0 nomodify
server ntp.api.bz perfer
server 210.72.145.44 # 中国国家受时中心
server 202.112.10.36 # 1.cn.pool.ntp.org
server 59.124.196.83 # 0.asia.pool.ntp.org
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
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
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
国内常用的时间服务器列表:
210.72.145.44 (国家授时中心服务器IP地址)
ntp.sjtu.edu.cn 202.120.2.101 (上海交通大学网络中心NTP服务器地址)
s1a.time.edu.cn 北京邮电大学
s1b.time.edu.cn 清华大学
s1c