时间同步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/chrony-dnssrv@.service /usr/lib/systemd/system/chrony-dnssrv@.timer /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
![](https://img2020.cnblogs.com/blog/2178349/202103/2178349-20210317174824498-298009588.png)
监听端口: 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
ntpdate 10.0.0.8
-bash: ntpdate: 未找到命令
#解决方法:
apt install ntpdate
yum install ntpdate
#都同步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 - -
同步阿里云时间
# ntpdate ntp1.aliyun.com
13 Sep 21:20:49 ntpdate[3751]: adjust time server 120.25.115.20 offset -0.000147 sec
NTP服务器已经全部OK!!!希望对有所帮助!!!
相关文章
- [PHP] 2018年终总结
- [MySQL] INFORMATION_SCHEMA 数据库包含所有表的字段
- [日常] DNS解析概述
- [PHP] swoole的安装和简单使用
- [PHP] PHP闭包(closures)
- [PHP]代码执行和生命周期
- [PHP] 理解依赖注入
- [日常]总结2016年7月入职至2016年7月26号微盘所遇bug
- [PHP] 多进程通信-消息队列使用
- [PHP] PHP多进程处理tcp连接
- [PHP]PHP rpc框架hprose测试
- [日常] nginx与负载均衡策略
- [日常]nginx与网络事件模型
- [日常] HTTP的缓存
- [日常] HTTP连接管理
- [日常] HTTP的媒体类型
- [日常] HTTP协议状态码
- [日常] MySQL数据库持久连接
- [日常] PHP库函数fgetss的BUG
- [PHP] 算法-选择排序的PHP实现