您的位置:首页 > 编程语言 > PHP开发

NTP时间服务器搭建及配置

2016-06-29 10:40 435 查看
网络时间协议NTP(Network
Time
Protocol)是用于互联网中时间同步的标准互联网协议。NTP的用途是把计算机的时间同步到某些时间标准。目前采用的时间标准是世界协调时UTC(Universal
Time Coordinated)。NTP的主要开发者是美国特拉华大学的David L.
Mills教授。其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。NTP服务的安装[root@m01 ~]# yum
install ntp[root@m01 ~]# rpm
-qa ntpntp-4.2.6p5-5.el6.centos.x86_64NTP 服务端配置[root@m01 ~]# egrep
-v "#|^$" /etc/ntp.confdriftfile
/var/lib/ntp/driftrestrict default
nomodifyrestrict -6 default
kod nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict -6 ::1server
ntp1.aliyun.comserver
time.nist.govincludefile
/etc/ntp/crypto/pwkeys /etc/ntp/keysntp.conf配置详解driftfile /var/lib/ntp/drift #driftfile 参数解决NTP服务器校准时间时的传送延迟,格式:driftfile 文件名;在与上级时间服务器联系时所花费的时间记录在driftfile参数后面的文件内。注意:driftfile 后面接的文件必须是完整的全路径,不能是链接文件,并且文件权限要写成ntpd守护进程可写的状态restrict 是控制权限参数,主要的语法格式为:restrict IP地址 mask 子网掩码 参数。其中IP 可以是ip 也可以是default(即:所有IP);参数包含:ignore:关闭所有的NTP联机服务nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校对notrust:客户端除非通过认证,否则客户端来源将被认为不信任子网noquery:不提供客户端的时间查询注:如果参数么有设定,默认是没有任何限制restrict -6 default kod nomodify notrap nopeer
noquery#拒绝IPV6restrict default kod nomodify notrap nopeer
noquery #拒绝IPV4restrict 127.0.0.1 #放行本机来源restrict -6 ::1restrict 192.168.1.0 mask 255.255.255.0 nomodify
notrap 放行网络来源server ntp1.aliyun.com prefer 以这个为最优先级(上级)server time.nist.gov 以这个为最上级备机(参考)restrict 133.100.9.2 #开放server
访问我们ntp服务的权限NTP服务的启动 在启动前,先使用ntpdate手动同步下时间,免得本机与外部时间服务器时间差距太大,让ntpd不能正常同步。#
ntpdate -u 202.112.10.3622
Dec 16:52:38 ntpdate[6400]: adjust time server 202.112.10.36 offset 0.012135
sec [root@m01
~]# /etc/init.d/ntpd start正在启动 ntpd:
[确定]如果定时任务里面有时间同步任务时候要注释掉[root@m01
~]# chkconfig ntpd on[root@m01
~]# netstat -lntup|grep ntpudp 0
0 172.16.1.61:123
0.0.0.0:*
2312/ntpd udp 0
0 10.0.0.61:123
0.0.0.0:*
2312/ntpd udp 0
0 127.0.0.1:123
0.0.0.0:*
2312/ntpd udp 0
0 0.0.0.0:123
0.0.0.0:*
2312/ntpd udp 0
0 fe80::20c:29ff:fed3:8d56:123 :::*
2312/ntpd udp 0
0 fe80::20c:29ff:fed3:8d4c:123 :::*
2312/ntpd udp 0
0 ::1:123
:::*
2312/ntpd udp 0
0 :::123
:::*
2312/ntpd [root@m01
~]# tail -10 /var/log/messagesJun
26 19:49:35 m01 ntpd[2312]: Listen normally on 5 lo ::1 UDP 123Jun
26 19:49:35 m01 ntpd[2312]: Listen normally on 6 eth0 fe80::20c:29ff:fed3:8d4c
UDP 123Jun
26 19:49:35 m01 ntpd[2312]: Listen normally on 7 eth1 fe80::20c:29ff:fed3:8d56
UDP 123Jun
26 19:49:35 m01 ntpd[2312]: Listening on routing socket on fd #24 for interface
updatesJun
26 19:49:36 m01 ntpd[2312]: 0.0.0.0 c016 06 restartJun
26 19:49:36 m01 ntpd[2312]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPMJun
26 19:49:36 m01 ntpd[2312]: 0.0.0.0 c011 01 freq_not_setJun
26 19:49:36 m01 ntpd[2312]: 0.0.0.0 c61c 0c clock_step +222384.777553 sJun
29 09:36:01 m01 ntpd[2312]: 0.0.0.0 c614 04 freq_modeJun
29 09:36:02 m01 ntpd[2312]: 0.0.0.0 c618 08 no_sys_peer如何确定服务器顺利的更新了时间?使用下面的命令查看[root@m01
~]# ntpstatunsynchronised polling server every 64 s上面是么有成功的,可以重启ntp服务,如下:[root@m01
~]# /etc/init.d/ntpd restart关闭 ntpd:
[确定]正在启动 ntpd: [确定][root@m01
~]# ntpstatsynchronised
to NTP server (182.92.12.11) at stratum 3 time correct to within 7952 ms polling server every 64 s这里代表顺利的更新了时间 [root@m01
~]# ntpq -p remote refid st t when poll reach delay
offset jitter==============================================================================*time5.aliyun.co
10.137.38.86 2 u 43
64 7 9.230
8.139 2.038 host-24-56-178- .ACTS. 1 u
105 64 2
333.570 -34.886 0.000上面的ntpq -p列出了与NTP服务相关的上联ntp服务的状态,其中每行的意思:remote:NTP的的主机ip或是主机名,其中*代表正在使用当中的上联NTP;+代表也能上联,作为下个提供时间更新的候选refid:参考的上一级NTP服务器地址st: remote远程服务器的级别,由于NTP是层级结构,有顶端的服务器,也有多层的Relay Server再到客户端,所以服务器从高到低分为1-16个级别,为了减缓负荷和网络堵塞,原则上应该直接连到级别为1的服务器上when :上次成功请求后,到现在的秒数poll: 本地和远程服务器多少时间进行一次时间同步。刚开始的运行ntp的时候找个poll值会比较小,那样和服务器的同步频率就增加了,可以尽快调整的正确的时间范围,之后poll的值会逐渐增大,同步的频率也会相对减小reach : 这是一个八进制值,用来测试能和服务器连接,每成功一次它的值就会增加delay : 从本地发送同步要求到ntp服务器的时间,也就是网络传输的延迟时间,单位是10^(-3)秒offset : 主机通过NTP时钟同步与所同步时间源的时间偏移量,单位为毫秒(ms)。offset越接近于0,主机和ntp服务器的时间越接近jitter : 这是一个用来做统计的值.
它统计了在特定个连续的连接数里offset的分布情况. 简单地说这个数值的绝对值越小,主机的时间就越精确NTP服务的安全配置:虽然已经在ntp.conf中使用restrict参数配置了限制,但是最好在IPtables中再次限制iptables
-A INPUT -i $EXTIF -p udp -s 192.168.100.0/24 --dport 123 -j ACCEPTNTP客户的时间校准1、手动的方式进行校准使用date hwclock-r;hwclock -w这三个命令来查看时间并且写入bioos中

2、网络校对的方式ntpdate 10.0.0.61

使用hwclock -w 写入到bios中

添加crontab定时任务

通过在客户端启动ntp服务器进程,在ntp.conf配置文件中配置

restrict 10.0.0.61 授权来自61服务器server 10.0.0.61 这个就是ntp服务器地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  服务器 时间 NTP