建站服务器
一、先介绍几个与时间相关常见的概念
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/clockzone=asia/shanghai#表明我们的时间配置文件要使用/usr/share/zoneinfo/asia/shanghai那个文件 /etc/localtime 本地端的时间配置文件
简单的一个例子:目前在上海,假如到了美国,怎么调整时间?首先vim/etc/sysconfig/clockzone=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.restrictdefaultkodnomodifynotrapnopeernoqueryrestrict-6defaultkodnomodifynotrapnopeernoquery#permitallaccessovertheloopbackinterface.thiscould#betightenedaswell,buttodosowouldeffectsomeof#theadministrativefunctions.restrict127.0.0.1restrict-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.orgiburstserver1.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.#cryptoincludefile/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|grepntpudp00192.168.209.128:1230.0.0.0:*2766/ntpdudp00127.0.0.1:1230.0.0.0:*2766/ntpdudp000.0.0.0:1230.0.0.0:*2766/ntpdudp00fe80::20c:29ff:fe67:be62:123:::*2766/ntpdudp00::1:123:::*2766/ntpdudp00:::123:::*2766/ntpd通常启动ntp15分钟后才会和上层ntp服务器顺利连接上。#ntpstat查看ntp服务器是否与上层连接。synchronisedtontpserver(xx.xx.xx.xx)atstratum3timecorrecttowithin538mspollingserverevery128s[root@node1~]#ntpq-premoterefidsttwhenpollreachdelayoffsetjitter============
天猫投入百亿启动“双百计划”日本国内首起域名诉讼案,原告大获全胜数据库业务OceanBase升格为独立公司 蚂蚁集团CEO胡晓明任董事长仅限1个月的特价云主机服务器云存储服务器和硬盘录像机区别在哪网站优化一般怎么做618大促 京东电器集体挑战全年最低价网站小程序打开慢-云服务器问题