首页 > 编程知识 正文

时间同步(centos搭建ntp)

时间:2023-05-06 18:30:06 阅读:86871 作者:622

简介

在某些集群服务器上,不同的主机时间不一致,从而导致服务器异常。 因此,使用网络时间协议(NTP )进行时间同步。

操作系统

centos Linux7.6. 1810版(酷睿) )。

安装

yum-y安装NTP

配置

默认设置用于同步外联网的ntp时间服务。

# # formoreinformationaboutthisfile,第三页

#NTP.conf(5、ntp_acc(5) 5、ntp_auth(5) 5、ntp_clock(5) 5、ntp_misc(5) 5、ntp_mon(5) 5

# #系统时间和BIOS事件的偏差记录

差异文件/增量/lib/NTP /差异

# #永久同步withourtimesource,but do not

# # permitthesourcetoqueryormodifytheserviceonthissystem

restrictdefaultnomodifynotrapnopeernoquery

# # permitallaccessovertheloopbackinterface.this could

# be tightened as well,but to do so would effect some of

# # the管理功能。

# #严格控制相关权限。

# #语法是严格IP地址掩码的参数

# #其中,IP地址可以是default,default是指所有IP

# #参数如下所示。

#ignore :关闭所有NTP在线服务

#nomodify :客户端不能更改服务器端的时间参数,但客户端可以通过服务器端进行网络校验。

#notrust :除非客户机经过验证,否则该客户机的源被视为不可靠的子网

#noquery :不提供客户端的时间查询:客户端不能使用ntpq、ntpc等命令查询ntp服务器

# # notrap :不提供trap远程登录:拒绝向匹配的主机提供模式6控制消息陷阱服务。 陷阱服务是ntpdq控制消息协议的子系统,用于远程事件记录器。

#nopeer :为了防止主机试图与服务器对等,允许未经授权的服务器控制时钟

#KoD :访问违反时发送kod软件包。

#restrict -6表示IPV6地址的权限设定。

# #不限制本机,拥有所有权限

严格127.0.0.1

严格:1

# # hostsonlocalnetworkarelessrestricted。

# #严格192.168.1.0屏蔽255.255.255.0无修改通知

# #设定默认策略,允许任意主机的时间同步

严格默认忽略

# #此处表示限制向IP段为192.168.1.1-192.168.1.254的服务器提供NTP服务。

# #严格192.168.1.0掩码255.255.255.0北方移动节点查询

# # usepublicserversfromthepool.NTP.org项目。

# # pleaseconsiderjoiningthepool (http://www.pool.NTP.org/join.html )。

设置#NTP主机源。 其中,prefer表示首选主机。 192.168.1.123是本地NTP服务器,因此优先指定从此主机的同步时间。

服务器192.168.1.123首选项

服务器0.centos .保罗. NTP.Org I burst

服务器1.centos .保罗. NTP.Org I burst

服务器2.centos .保罗. NTP.Org I burst

服务器3.centos .保罗. NTP.Org I burst

# #广播192.168.1.255自动密钥#广播服务器

# #广播客户端#广播客户端

# # broadcast 224.0.1.1自动密钥#多媒体服务器

# #多客户端224.0.1.1 #多客户端

# # manycastserver 239.255.254.254 # manycastserver

# # manycastclient 239.255.254.254 autokey # manycastclient

# #启用公钥加密技术。

# # cry

pto includefile /etc/ntp/crypto/pw # Key file containing the keys and key identifiers used when operating # with symmetric key cryptography. keys /etc/ntp/keys # Specify the key identifiers which are trusted. #trustedkey 4 8 42 # Specify the key identifier to use with the ntpdc utility. #requestkey 8 # Specify the key identifier to use with the ntpq utility. #controlkey 8 # Enable writing of statistics records. #statistics clockstats cryptostats loopstats peerstats # Disable the monitoring facility to prevent amplification attacks using ntpdc # monlist command when default restrict does not include the noquery flag. See # CVE-2013-5211 for more details. # Note: Monitoring will not be disabled with the limited restriction flag. disable monitor

服务启动时,同步的时间服务器

修改/etc/ntp/stpe-tickers文件

server 192.168.1.123 server 0.centos.pool.ntp.org server 1.centos.pool.ntp.org server 2.centos.pool.ntp.org server 3.centos.pool.ntp.org

配置硬件时间同步

ntp服务,默认只会同步系统时间。如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd文件,在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes 这样,就可以让硬件时间与系统时间一起同步。

#允许BIOS与系统时间同步,也可以通过hwclock -w 命令

SYNC_HWCLOCK=yes #pgc-card .pgc-card-href { text-decoration: none; outline: none; display: block; width: 100%; height: 100%; } #pgc-card .pgc-card-href:hover { text-decoration: none; } /*pc 样式*/ .pgc-card { box-sizing: border-box; height: 164px; border: 1px solid #e8e8e8; position: relative; padding: 20px 94px 12px 180px; overflow: hidden; } .pgc-card::after { content: " "; display: block; border-left: 1px solid #e8e8e8; height: 120px; position: absolute; right: 76px; top: 20px; } .pgc-cover { position: absolute; width: 162px; height: 162px; top: 0; left: 0; background-size: cover; } .pgc-content { overflow: hidden; position: relative; top: 50%; -webkit-transform: translateY(-50%); transform: translateY(-50%); } .pgc-content-title { font-size: 18px; color: #222; line-height: 1; font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .pgc-content-desc { font-size: 14px; color: #444; overflow: hidden; text-overflow: ellipsis; padding-top: 9px; overflow: hidden; line-height: 1.2em; display: -webkit-inline-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; } .pgc-content-price { font-size: 22px; color: #f85959; padding-top: 18px; line-height: 1em; } .pgc-card-buy { width: 75px; position: absolute; right: 0; top: 50px; color: #406599; font-size: 14px; text-align: center; } .pgc-buy-text { padding-top: 10px; } .pgc-icon-buy { height: 23px; width: 20px; display: inline-block; background: url(https://lf3-cdn-tos.bytescm.com/obj/cdn-static-resource/pgc/v2/pgc_tpl/static/image/commodity_buy_f2b4d1a.png); } Linux命令行与shell脚本编程大全 第3版 shell脚本程序编程开发 shell编程IT操作系统linux大全书籍 人民邮电出版社 ¥59.9 领1元券

启动服务

systemctl start ntpd

查看ntp服务器有无和上层ntp连通

ntpstat

synchronised to NTP server (120.25.115.20) at stratum 3

time correct to within 85 ms

polling server every 64 s

查看ntp服务器与上层ntp的状态

ntpq -p

remote refid st t when poll reach delay offset jitter

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

*120.25.115.20 10.137.53.7 2 u 39 64 7 34.227 -1.895 5.605

含蓄的花卷.chl.la .INIT. 16 u - 64 0 0.000 0.000 0.000

+xk-6-95-a8.bta. 10.41.14.199 2 u 36 64 7 38.472 1.974 1.703

ntp7.flashdance .INIT. 16 u - 64 0 0.000 0.000 0.000

remote - 本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先

refid - 参考上一层ntp主机地址

st - stratum阶层

when - 多少秒前曾经同步过时间

poll - 下次更新在多少秒后

reach - 已经向上层ntp服务器要求更新的次数

delay - 网络延迟

offset - 时间补偿

jitter - 系统时间与bios时间差


总结

时间同步服务,是一个很简单的服务。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。