内部管理系统服务器更新时间,企业内部在centos7.2系统中必杀技NTP时间服务器及内网服务器时间同步(windows和linux客户端同步)...

网络时间协议NTP(Network Time

Protocol)是用于互联网中时间同步的标准互联网协议。NTP的用途是把计算机的时间同步到某些时间标准。目前采用的时间标准是世界协调时UTC(Universal

Time Coordinated)。NTP的主要开发者是美国特拉华大学的David L. Mills教授。

NTP对于我们个人来说有什么用呢,简单的讲,当你的计算机时间不准确了,你可以接入到互联网,从网上同步一下时间。

对于企业来说,当你有成百上千的计算机,都不能直接连接互联网,时间不统一影响业务,如果一台一台的修改,工作量太大。这时搭建一个自己的NTP服务器就显出它的优势了。

企业内部架设NTP服务器的大概拓扑如下:

a4c26d1e5885305701be709a3d33442f.png

配置好相关的yum源、确保你的ntp服务器可以连网

# vim /etc/resolv.conf

#添加网关,这个可以ipconfig查看默认网关

nameserver 192.168.8.251

配置内网NTP-Server(192.168.8.100)

a4c26d1e5885305701be709a3d33442f.png

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

a4c26d1e5885305701be709a3d33442f.png

最终的参数:

# 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.time.edu.cn 北京大学

s1d.time.edu.cn 东南大学

s1e.time.edu.cn 清华大学

s2a.time.edu.cn 清华大学

s2b.time.edu.cn 清华大学

s2c.time.edu.cn 北京邮电大学

s2d.time.edu.cn 西南地区网络中心

s2e.time.edu.cn 西北地区网络中心

s2f.time.edu.cn 东北地区网络中心

s2g.time.edu.cn 华东南地区网络中心

s2h.time.edu.cn 四川大学网络管理中心

s2j.time.edu.cn 大连理工大学网络中心

s2k.time.edu.cn CERNET桂林主节点

s2m.time.edu.cn 北京大学

在配置前,先使用ntpdate手动同步下时间,免得本机与外部时间服务器时间差距太大,让ntpd不能正常同步

# ntpdate -u ntp.api.bz

13 Apr 14:45:05 ntpdate[11464]: step time server 61.153.197.226

offset 28824.742403 sec

ntp服务器配置好之后启动服务# service ntpd start,它监听的端口是UDP的123端口、可以使用

# netstat -tnulp | grep ntp

udp  0  0 192.168.8.102:123  0.0.0.0:*  11484/ntpd

udp  0  0 127.0.0.1:123  0.0.0.0:*  11484/ntpd  udp  0  0 0.0.0.0:123  0.0.0.0:*  11484/ntpd

udp6  0

0

fe80::4637:e6ff:fe5:123 :::*  11484/ntpd  udp6  0

0 ::1:123

:::*  11484/ntpd

udp6  0

0 :::123

:::*

 11484/ntpd  a4c26d1e5885305701be709a3d33442f.png

重启完了之后要等几分钟或者十几分钟后就可以实现时间同步了,

# ntpdate 192.168.8.100

11 Aug 11:38:30 ntpdate[7619]: adjust time server 10.17.1.60 offset

0.000178 sec

如果重启后马上测试就会出现下面的情况:

# ntpdate 192.168.8.100

11 Aug 11:05:28 ntpdate[7326]: no server suitable for

synchronization found

可以用这个命令参数来查看:

# ntpdate -d 192.168.8.100

ntpq -p 查看网络中的NTP服务器,同时显示客户端和每个服务器的关系

# ntpq -p

remote

refid  st t when poll reach

delay  offset

jitter

==============================================================================

*61.153.197.226  216.218.192.202

2 u  37  64

1  47.274

10.405  0.000

210.72.145.44  .INIT.

16 u  -  64  0  0.000

0.000  0.000

gus.buptnet.edu 10.3.9.9  4 u

35  64  1  81.880  2.559  0.000

59-124-196-83.H .INIT.  16 u