CentOS7 - 时间同步服务ntpd 海康ntp校时服务器地址
lipiwang 2024-10-28 17:29 9 浏览 0 评论
简介
在一些集群服务中,不同的主机时间不一致,会导致服务异常。因此都会使用ntp(Network Time Protocol)进行时间同步。
操作系统
CentOS Linux release 7.6.1810 (Core)
安装
yum -y install ntp
配置
默认配置会,同步外网的ntp时间服务。
# For more information about this file, see the man pages # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5). #系统时间与BIOS事件的偏差记录 driftfile /var/lib/ntp/drift # Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. restrict default nomodify notrap nopeer noquery # Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. #restrict 控制相关权限。 #语法为: restrict IP地址 mask 子网掩码 参数 #其中IP地址也可以是default ,default 就是指所有的IP #参数有以下几个: #ignore :关闭所有的 NTP 联机服务 #nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。 #notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网 #noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器 #notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。 #nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟 #kod : 访问违规时发送 KoD 包。 #restrict -6 表示IPV6地址的权限设置。 #对本机不做限制,拥有所有的权限 restrict 127.0.0.1 restrict ::1 # Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap #设置默认策略为允许任何主机进行时间同步 restrict default ignore #此处表示限制向从192.168.1.1-192.168.1.254这些IP段的服务器提供NTP服务。 #restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap noquery # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #设定NTP主机来源(其中prefer表示优先主机),192.168.1.123是本地的NTP服务器,所以优先指定从该主机同步时间。 server 192.168.1.123 prefer server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst #broadcast 192.168.1.255 autokey # broadcast server #broadcastclient # broadcast client #broadcast 224.0.1.1 autokey # multicast server #multicastclient 224.0.1.1 # multicast client #manycastserver 239.255.254.254 # manycast server #manycastclient 239.255.254.254 autokey # manycast client # Enable public key cryptography. #crypto 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
启动服务
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
amy.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时间差
总结
时间同步服务,是一个很简单的服务。
相关推荐
- Redis 常见面试问题总结和答案(redisson面试题)
-
什么是Redis?Redis(RemoteDictionaryServer)Redis是一个开源的使用ANSIC语言编写、遵守BSD协议、支持网络、可基于内存亦可持久化的日志型、Ke...
- 青云QingCloud新增Memcached功能 完善缓存集
-
北京2015年1月30日电/美通社/--基础云服务商青云QingCloud日前宣布,为了更好的满足用户对缓存服务多样性的需求,正式推出基于Memcached的缓存集群服务。此次发布的M...
- 还不懂什么是Redis?一文详解Redis,入门学习看这一篇就够了
-
在我们日常的开发中,无不都是使用数据库来进行数据的存储,由于一般的系统任务中通常不会存在高并发的情况,所以这样看起来并没有什么问题,可是一旦涉及大数据量的需求,比如一些商品抢购的情景,或者是主页访问量...
- redis一些常见的面试题(附答案)(redis经典面试题)
-
1、什么是redis?Redis是一个基于内存的高性能key-value数据库。2、Reids的特点 Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库统...
- Java面试官最爱问的那些Redis面试题盘点
-
一、概述二、数据类型STRINGLISTSETHASHZSET三、数据结构字典跳跃表四、使用场景计数器缓存查找表消息队列会话缓存分布式锁实现其它五、Redis与Memcached数据类型数据持久化...
- Redis为什么「操作速度」这么快以及在实际开发中的「应用场景」
-
Redis在目前分布式开发大环境下应用的场景比较多,但是大家有没有思考过为什么大家都愿意使用Redis呢?以及Redis为什么速度会这么快的原因呢?还有我们实际开发过程中使用Redis的场景又有哪些呢...
- Redis分片(分布式缓存)(redis分片存储)
-
分片(partitioning)就是将你的数据拆分到多个Redis实例的过程,这样每个实例将只包含所有键的子集.(相关推荐:Redis教程)1分片何用Redis的分片承担着两个主要目标:o允...
- 您应该了解的20大系统设计概念(系统设计有哪些)
-
您应该了解的20大系统设计概念我应该从基础开始,比如可扩展性、可用性、可靠性这些。这些都是系统设计的核心要素。接下来,可能需要考虑性能相关的,比如延迟和吞吐量,这两者常常被一起讨论。然后是存储,数据库...
- 一文彻底弄懂 TPS RPS QPS(tps/cps)
-
以下是关于RPS、QPS、TPS的核心区别与关联的总结,结合实际场景和优化建议:一、核心定义与区别RPS:RequestsPerSecond每秒请求数客户端到服务器的完整请求数量Web服务...
- redis,memcached,nginx网络组件
-
1.理解阻塞io,非阻塞io,同步io,异步io的区别2.理解BIO和AIO的区别io多路复用只负责io检测,不负责io操作阻塞io中的write,能写多少是多少,只要写成功就返回,譬如准备写500字...
- 为什么 Redis 单线程却能支撑高并发?
-
#暑期创作大赛#为什么Redis单线程却能支撑高并发?Redis和memcached有什么区别?Redis的线程模型是什么?为什么Redis单线程却能支撑高并发?这个是问Redis的...
- 值得一看的35个Redis面试题总结(redis面试题汇总)
-
Redis是一个基于内存的高性能key-value数据库。作者:民工哥1.什么是redis?Redis是一个基于内存的高性能key-value数据库。2.Reids的特点 Redis本质上是一...
- 内存数据库优缺点一览:Redis、Memcached、MongoDB和Ignite
-
内存数据库是一种将数据存储在内存中的数据库,相比于传统的磁盘数据库,内存数据库具有更高的性能、更低的延迟和更好的并发能力。内存数据库广泛应用于高速缓存、实时分析、游戏、社交网络等场景。本文将对比介绍四...
- Java面试 | 关于Redis 的面试题(redis面试题2021)
-
1.Redis是什么?Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库统统加载在内存当中进行操作,定期通过异步操作把数据库数据flush到硬盘上进行保存。因...
- 数字化与智能化技术:分布式缓存数据库Redis
-
一、Redis概述Redis远程字典服务(RemoteDictionaryServer),是一个开源的使用ANSIC语言编写的,基于内存的分布式缓存Key-Value数据库。1、Redis数据...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- maven镜像 (69)
- undefined reference to (60)
- zip格式 (63)
- oracle over (62)
- date_format函数用法 (67)
- 在线代理服务器 (60)
- shell 字符串比较 (74)
- x509证书 (61)
- localhost (65)
- java.awt.headless (66)
- syn_sent (64)
- settings.xml (59)
- 弹出窗口 (56)
- applicationcontextaware (72)
- my.cnf (73)
- httpsession (62)
- pkcs7 (62)
- session cookie (63)
- java 生成uuid (58)
- could not initialize class (58)
- beanpropertyrowmapper (58)
- word空格下划线不显示 (73)
- jar文件 (60)
- jsp内置对象 (58)
- makefile编写规则 (58)