9.linuxntp服务器搭建

建站服务器

一、先介绍几个与时间相关常见的概念

成都创新互联专业为企业提供陆港网站建设、陆港做网站、陆港网站设计、陆港网站制作等企业网站建设、网页设计与制作、陆港企业网站模板建站服务,10多年陆港做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

GMT:Greenwich Mean Time 格林威治时间

理论上来说,格林尼治标准时间的正午是指当太阳横穿格林尼治子午线时(也就是在格林尼治上空高点时)的时间。由于地球在它的椭圆轨道里的运动速度不均匀,这个时刻可能和实际的太阳时相差16分钟。

UTC:Coordinated Universal Time 协调世界时

世界标准时间

CST:(Chinese Standard Time)

CST却同时可以代表如下 4 个不同的时区:

Central Standard Time (USA) UT-6:00
Central Standard Time (Australia) UT+9:30
China Standard Time UT+8:00
Cuba Standard Time UT-4:00

二、操作系统上的两种时间

软件时钟:也叫系统时间,根据1970/01/01开始计算的总秒数

查看系统时间:
[root@node1~]#date#查看当前时间
WedJun2819:57:53CST2017

[root@node1~]#date+%Y-%m-%d#设置当前时间格式
2017-06-28

[root@node1~]#date+%Y-%m-%d%H:%M:%S#设置当前时间格式
2017-06-2819:58:42

[root@node1~]#date+%s#从1970/01/01到现在的总秒数
1498651211
设置时间:


date-s2012052301:01:01#设置当前系统时间,一般不建议直接在生产主机上执行。
date-sdd/mm/yyyyhh:mm:ss

硬件时钟:主机硬件系统上的时钟。主板上BIOS中的时间,由主板电池供电来维持运行,系统开机时要读取这个时间,并根据它来设定系统时间.

查看硬件时间:hwclock或clock
设置:hwclock--set--date=06/18/1414:55

硬件时间与系统时间相互转换:

clock--hctosys#将系统时间调整为目前的硬件时间一致;当Linux启动时,系统时钟会去读取硬件时钟的设定,之后系统时钟即独立运作.
clock--systohc#将硬件时钟调整为与目前的系统时钟一致;将系统时间存回硬件时钟内

三、NTP服务器安装与设置

1.所需要的软件

ntp 主要软件

tzdata 提供各时区对应的显示格式

2.相关文件

/etc/ntp.conf 主配置文件

/usr/share/zoneinfo/ 由tzdata提供,为各时区的时间格式对应文件。

/etc/sysconfig/clock 设置时区是否使用UTC时钟的配置文件。

[root@node1zoneinfo]#cat/etc/sysconfig/clock
ZONE=Asia/Shanghai
#表明我们的时间配置文件要使用/usr/share/zoneinfo/Asia/Shanghai那个文件

/etc/localtime 本地端的时间配置文件

简单的一个例子:
目前在上海,假如到了美国,怎么调整时间?
首先vim/etc/sysconfig/clock
ZONE=America/New_York
然后cp/usr/share/zoneinfo/America/New_York/etc/localtime
最后date

3.主配置文件

[root@node1~]#cat/etc/ntp.conf
#Formoreinformationaboutthisfile,seethemanpages
#ntp.conf(5),ntp_acc(5),ntp_auth(5),ntp_clock(5),ntp_misc(5),ntp_mon(5).

driftfile/var/lib/ntp/drift

#Permittimesynchronizationwithourtimesource,butdonot
#permitthesourcetoqueryormodifytheserviceonthissystem.
restrictdefaultkodnomodifynotrapnopeernoquery
restrict-6defaultkodnomodifynotrapnopeernoquery

#Permitallaccessovertheloopbackinterface.Thiscould
#betightenedaswell,buttodosowouldeffectsomeof
#theadministrativefunctions.
restrict127.0.0.1
restrict-6::1

#Hostsonlocalnetworkarelessrestricted.
#restrict192.168.1.0mask255.255.255.0nomodifynotrap

#Usepublicserversfromthepool.ntp.orgproject.
#Pleaseconsiderjoiningthepool(http://www.pool.ntp.org/join.html).
#server0.rhel.pool.ntp.orgiburst
#server1.rhel.pool.ntp.orgiburst
#server2.rhel.pool.ntp.orgiburst
#server3.rhel.pool.ntp.orgiburst

server1.cn.pool.ntp.org

#broadcast192.168.1.255autokey#broadcastserver
#broadcastclient#broadcastclient
#broadcast224.0.1.1autokey#multicastserver
#multicastclient224.0.1.1#multicastclient
#manycastserver239.255.254.254#manycastserver
#manycastclient239.255.254.254autokey#manycastclient

#Enablepublickeycryptography.
#crypto

includefile/etc/ntp/crypto/pw

#Keyfilecontainingthekeysandkeyidentifiersusedwhenoperating
#withsymmetrickeycryptography.
keys/etc/ntp/keys

#Specifythekeyidentifierswhicharetrusted.
#trustedkey4842

#Specifythekeyidentifiertousewiththentpdcutility.
#requestkey8

#Specifythekeyidentifiertousewiththentpqutility.
#controlkey8

#Enablewritingofstatisticsrecords.
#statisticsclockstatscryptostatsloopstatspeerstats

参数解释:

(1)driftfile 记录时间差异

(2)restrict 管理权限控制

restrict[ip]mask[netmask_ip][parameter]
parameter主要有:
ignore:拒绝所有类型的NTP连接
nomodify:客户端不能使用ntpc/ntpq来修改服务器的时间参数,但客户端可以进行网络校时
noquery:客户端不能用ntpq/ntpc来查询时间服务器,等于不提供NTP的网络校时
notrap:不提供trap这个远程事件登陆
notrust:拒绝没有认证的客户端

如果在[parameter]没有设置,则表示该网段不受任何限制。

(3)server:设置上层的NTP服务器

server[ip或主机名][prefer]

四、服务器NTP服务的启动

#/etc/init.d/ntpdstart#启动服务
#chkconfigntpdon#开机自启

#tail/var/log/messages#查看日志


查看端口:
[root@node1~]#netstat-tulnp|grepntp
udp00192.168.209.128:1230.0.0.0:*2766/ntpd
udp00127.0.0.1:1230.0.0.0:*2766/ntpd
udp000.0.0.0:1230.0.0.0:*2766/ntpd
udp00fe80::20c:29ff:fe67:be62:123:::*2766/ntpd
udp00::1:123:::*2766/ntpd
udp00:::123:::*2766/ntpd

通常启动NTP15分钟后才会和上层NTP服务器顺利连接上。


#ntpstat查看ntp服务器是否与上层连接。
synchronisedtoNTPserver(xx.xx.xx.xx)atstratum3
timecorrecttowithin538ms
pollingserverevery128s



[root@node1~]#ntpq-p
remoterefidsttwhenpollreachdelayoffsetjitter
==============================================================================
85.199.214.101.GPS.1u55641245.097179.4150.000


remote:NTP主机的IP或者主机名
*代表目前正在作用当中的上层NTP
+代表已经连接成功,可以作为下一个提供更新时间的候选者
refid:NTP服务器使用的更高一级服务器的名称
st:stratum阶层
when:几秒前曾经做过时间同步化更新的操作.上一次成功请求之后到现在的秒数
poll:下一次更新在几秒钟之后.本地和远程服务器多少时间进行一次同步,单位秒,在一开始运行NTP的时候这个poll值会比较小,服务器同步的频率大,可以尽快调整到正确的时间范围,之后poll值会逐渐增大,同步的频率也就会相应减小
reach:已经向上层NTP服务器要求更新的次数.用来测试能否和服务器连接,是一个八进制值,每成功连接一次它的值就会增加
delay:网络传输过程当中延迟的时间.从本地机发送同步要求到ntp服务器的往返时间
offset:时间补偿的结果.主机通过NTP时钟同步与所同步时间源的时间偏移量,单位为毫秒,offset越接近于0,主机和ntp服务器的时间越接近
jitter:Linux系统时间与硬件时间的差异时间。这个数值的绝对值越小,主机的时间就越精确

五、客户端同步NTP服务器的时间

方法1:
ntpdate192.168.209.128
编辑定时任务crontab,每隔30分钟自动同步,并写入硬件时钟。
*/30****(/usr/sbin/ntpdate192.168.209.128&&hwclock-w)&>/dev/null

方法2:
修改/etc/ntp.conf配置文件,开启ntpd服务,使其自动去同步上层ntp服务器。
添加server1.cn.pool.ntp.org

/etc/init.d/ntpdstart
chkconfigntpdon

本文题目:9.linuxntp服务器搭建
文章位置:https://www.cdcxhl.com/article40/cpjgeo.html

成都网站建设公司_创新互联,为您提供品牌网站设计建站公司网站营销服务器托管定制开发网站排名

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

外贸网站建设