時間同步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

 

 



監聽端口: 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!!!希望對有所幫助!!!

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM