Centos7怎么部署NTP时间服务器
本篇内容介绍了“Centos7怎么部署NTP时间服务器”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
NTP(Network Time Protocol)网络时间协议基于UDP,用于网络时间同步的协议,使网络中的计算机时钟同步到UTC,再配合各个时区的偏移调整就能实现精准同步对时功能。
OS:Linux Centos 7.4 x86_64
1.查看当前服务器时区&列出时区并设置时区(如已是正确时区,请略过):
#timedatectl#timedatectllist-timezones#timedatectlset-timezoneAsia/Shanghai2.时间时区概念理解:
GMT、UTC、CST、DST
UTC:
整个地球分为二十四时区,每个时区都有自己的本地时间,在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC:Universal Time Coordinated)。
GMT:
格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线(UTC与GMT时间基本相同)。
CST:
中国标准时间 (China Standard Time)
GMT + 8 = UTC + 8 = CST
DST:
夏令时(Daylight Saving Time) 指在夏天太阳升起的比较早时,将时间拨快一小时,以提早日光的使用(中国不使用)。
2.使用 NTP 公共时间服务器池(NTP Public Pool Time Servers)http://www.pool.ntp.org 同步你的服务器时间。
查看是否安装:
#rpm-qntpntp-4.2.6p5-25.el7.centos.2.x86_64
如已安装请略过此步,否则请执行以下命令安装:
#yuminstallntpdatentp-y
修改NTP配置:
注:绿色为原有我注释掉的内容,红色为新增代替之前注释内容,其他默认。
#vim/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#新增:日志目录.logfile/var/log/ntpd.log#Permittimesynchronizationwithourtimesource,butdonot#permitthesourcetoqueryormodifytheserviceonthissystem.restrictdefaultnomodifynotrapnopeernoquery#Permitallaccessovertheloopbackinterface.Thiscould#betightenedaswell,buttodosowouldeffectsomeof#theadministrativefunctions.restrict127.0.0.1restrict::1#这一行的含义是授权172.16.128.0网段上的所有机器可以从这台机器上查询和同步时间.restrict172.16.128.0mask255.255.255.0nomodifynotrap#Hostsonlocalnetworkarelessrestricted.#restrict192.168.1.0mask255.255.255.0nomodifynotrap#Usepublicserversfromthepool.ntp.orgproject.#Pleaseconsiderjoiningthepool(http://www.pool.ntp.org/join.html).#server0.centos.pool.ntp.orgiburst#server1.centos.pool.ntp.orgiburst#server2.centos.pool.ntp.orgiburst#server3.centos.pool.ntp.orgiburst#新增:时间服务器列表.server0.cn.pool.ntp.orgiburstserver1.cn.pool.ntp.orgiburstserver2.cn.pool.ntp.orgiburstserver3.cn.pool.ntp.orgiburst#新增:当外部时间不可用时,使用本地时间.server172.16.128.171iburstfudge127.0.0.1stratum10#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#新增:允许上层时间服务器主动修改本机时间.restrict0.cn.pool.ntp.orgnomodifynotrapnoqueryrestrict1.cn.pool.ntp.orgnomodifynotrapnoqueryrestrict2.cn.pool.ntp.orgnomodifynotrapnoquery#Enablepublickeycryptography.#cryptoincludefile/etc/ntp/crypto/pw#Keyfilecontainingthekeysandkeyidentifiersusedwhenoperating#withsymmetrickeycryptography.keys/etc/ntp/keys#Specifythekeyidentifierswhicharetrusted.#trustedkey4842#Specifythekeyidentifiertousewiththentpdcutility.#requestkey8#Specifythekeyidentifiertousewiththentpqutility.#controlkey8#Enablewritingofstatisticsrecords.#statisticsclockstatscryptostatsloopstatspeerstats#Disablethemonitoringfacilitytopreventamplificationattacksusingntpdc#monlistcommandwhendefaultrestrictdoesnotincludethenoqueryflag.See#CVE-2013-5211formoredetails.#Note:Monitoringwillnotbedisabledwiththelimitedrestrictionflag.disablemonitor3.设置系统开机自启动:
#systemctlenablentpd#systemctlenablentpdate#systemctlis-enabledntpd
在ntpd服务启动时,先使用ntpdate命令同步时间:
#ntpdate-u1.cn.pool.ntp.org
原因之一:当服务端与客户端之间的时间误差过大时,此时修改时间可能对系统或应用带来不可预知问题,NTP会停止时间同步。若检查NTP启动后时间未同步时,应考虑可能是时间误差过大所致,此时需要先手动进行时间同步。
启动NTP服务器:
#systemctlstartntpdate#systemctlstartntpd4.加入防火墙:
#firewall-cmd--permanent--add-service=ntp#firewall-cmd--reload5.查看ntp连接状态如果没有问题,将正确时间写入硬件:
#ss-tlunp|grepntp#ntpq-p#hwclock-w
5.1.系统时间与硬件时间
硬件时间:
RTC(Real-Time Clock)或CMOS时间,一般在主板上靠电池供电,服务器断电后也会继续运行。仅保存日期时间数值,无法保存时区和夏令时设置。
系统时间:
一般在服务器启动时复制RTC时间,之后独立运行,保存了时间、时区和夏令时设置。
6.客户端:以服务进程方式实时同步(需安装NTP):
#vim/etc/ntp.confserver172.16.128.171
重要:修改任意节点服务器的NTP配置文件都需要重起ntpd服务:
#systemctlrestartntpd
以crontab任务计划同步时间(需安装ntpdate,每天24点更新同步时间):
#crontab-e00***/usr/sbin/sntp-Pno-r172.16.128.171;hwclock-w
已部署完毕。这样集群会自动定期进行服务的同步,如此以来集群的时间就保持一致了。
“Centos7怎么部署NTP时间服务器”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。