时间同步chrony,最全最细

时间同步chrony,最全最细,第1张

时间同步chrony,最全最细
时间同步服务
多主机协作工作时,各个主机的时间同步很重要,时间不一致会造成很多重要应用的故障,如:加密协
议,日志,集群等, 利用NTP(Network Time Protocol) 协议使网络中的各个计算机时间达到同步。



目前NTP协议属于运维基础架构中必备的基本服务之一

时间同步软件
ntp
将系统时钟和世界协调时UTC同步,精度在局域网内可达0.1ms,在互联网上绝大多数的地方精度可以
达到1-50ms chrony
实现NTP协议的的自由软件。


可使系统时钟与NTP服务器,参考时钟(例如GPS接收器)以及使用手表
和键盘的手动输入进行同步。


还可以作为NTPv4(RFC 5905)服务器和对等体运行,为网络中的计算机
提供时间服务。


设计用于在各种条件下良好运行,包括间歇性和高度拥挤的网络连接,温度变化(计算
机时钟对温度敏感),以及不能连续运行或在虚拟机上运行的系统。


chrony的优势
更快的同步只需要数分钟而非数小时时间,从而最大程度减少了时间和频率误差,对于并非全天
24 小时运行的虚拟计算机而言非常有用
能够更好地响应时钟频率的快速变化,对于具备不稳定时钟的虚拟机或导致时钟频率发生变化的节
能技术而言非常有用

chrony官网:https://chrony.tuxfamily.org

chrony官方文档:https://chrony.tuxfamily.org/documentation.html

chrony文件组成
rpm -ql chrony
/etc/NetworkManager/dispatcher.d/20-chrony
/etc/chrony.conf
/etc/chrony.keys
/etc/dhcp/dhclient.d/chrony.sh
/etc/logrotate.d/chrony
/etc/sysconfig/chronyd
/usr/bin/chronyc
/usr/lib/systemd/ntp-units.d/50-chronyd.list
/usr/lib/systemd/system/[email protected]
/usr/lib/systemd/system/[email protected]
/usr/lib/systemd/system/chrony-wait.service
/usr/lib/systemd/system/chronyd.service
/usr/libexec/chrony-helper
/usr/sbin/chronyd
/usr/share/doc/chrony-3.4
/usr/share/doc/chrony-3.4/COPYING
/usr/share/doc/chrony-3.4/FAQ
/usr/share/doc/chrony-3.4/NEWS
/usr/share/doc/chrony-3.4/README
/usr/share/man/man1/chronyc.1.gz
/usr/share/man/man5/chrony.conf.5.gz
/usr/share/man/man8/chronyd.8.gz
/var/lib/chrony
/var/lib/chrony/drift
/var/lib/chrony/rtc
/var/log/chrony



监听端口: 323/udp,123/udp
配置文件: /etc/chrony.conf 规划如下:

10.0.0.8 充当NTP服务器

10.0.0.30 客户端

10.0.0.190 客户端

10.0.0.9 客户端

具体配置如下
# vim /etc/chrony.conf pool ntp.aliyun.com iburst #可以写阿里云的,也可以写其他的。



重启配置文件后查看
[root@localhost ~]# chronyc sources -v
210 Number of sources = 1 .-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 203.107.6.88 2 6 17 51 +411us[-2720us] +/- 37ms

我们可以看到已经同步OK,查看端口

端口是udp的323和123

ss -ntul

Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port

udp UNCONN 0 0 127.0.0.1:876 *:*

udp UNCONN 0 0 *:904 *:*

udp UNCONN 0 0 *:38293 *:*

udp UNCONN 0 0 *:2049 *:*

udp UNCONN 0 0 *:20048 *:*

udp UNCONN 0 0 *:111 *:*

udp UNCONN 0 0 *:123 *:*

ss -ntulp

Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port

udp UNCONN 0 0 127.0.0.1:876 *:* users:(("rpc.statd",pid=1123,fd=7))

udp UNCONN 0 0 *:904 *:* users:(("rpcbind",pid=743,fd=7))

udp UNCONN 0 0 *:38293 *:* users:(("rpc.statd",pid=1123,fd=8))

udp UNCONN 0 0 *:2049 *:*

udp UNCONN 0 0 *:20048 *:* users:(("rpc.mountd",pid=1143,fd=7))

udp UNCONN 0 0 *:111 *:* users:(("rpcbind",pid=743,fd=6))

udp UNCONN 0 0 *:123 *:* users:(("chronyd",pid=2542,fd=7))

udp UNCONN 0 0 *:50933 *:*

udp UNCONN 0 0 127.0.0.1:323 *:* users:(("chronyd",pid=2542,fd=5))

udp UNCONN 0 0 [::]:42338 [::]:*

udp UNCONN 0 0 [::]:904 [::]:*

ntpdate 10.0.0.8
17 Mar 16:40:44 ntpdate[1483]: no server suitable for synchronization found
没有找到适合同步的服务器 #设置本地网络可以同步我的ntp服务请求
#按照别人的配置往下写就好了
#allow 192.168.0.0/16
allow 10.0.0.0/24 #重启测试
# systemctl restart chronyd
#都同步OK
ntpdate 10.0.0.8
17 Mar 16:49:14 ntpdate[1502]: adjust time server 10.0.0.8 offset -0.005113 sec ntpdate 10.0.0.8
17 Mar 16:51:05 ntpdate[4147]: adjust time server 10.0.0.8 offset 0.009203 sec
ntpdate 10.0.0.8
17 Mar 17:03:52 ntpdate[1727]: adjust time server 10.0.0.8 offset 0.006905 sec
#客户端查看
chronyc
chrony version 3.4
Copyright (C) 1997-2003, 2007, 2009-2018 Richard P. Curnow and others
chrony comes with ABSOLUTELY NO WARRANTY. This is free software, and
you are welcome to redistribute it under certain conditions. See the
GNU General Public License version 2 for details. chronyc> clinets
Unrecognized command
chronyc> clients
Hostname NTP Drop Int IntL Last Cmd Drop Int Last
===============================================================================
10.0.0.190 4 0 1 - 20m 0 0 - -
10.0.0.9 4 0 1 - 1140 0 0 - -
10.0.0.30 4 0 1 - 373 0 0 - -

NTP服务器已经全部OK!!!希望对有所帮助!!!

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/587479.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存