[原]CentOS 7 chrony 筆記


~]# timedatectl  status
      Local time: Sun 2018-08-26 21:01:15 CST        ==> 本地系統實際時間,設置時間timedatectl set-time 15:58:30
                                                                           設置日期timedatectl set-time 20151120
                                                                           設置時間日期timedatectl set-time '16:10:40 2015-11-20'
      Universal time: Sun 2018-08-26 13:01:15 UTC    ==> 世界統一時間
      RTC time: Sun 2018-08-26 13:01:15              ==> 硬件時鍾的時間
      Time zone: Asia/Shanghai (CST, +0800)          ==> 當前時區,查看可用時區timedatectl list-timezones
                                                                   設置當前時區timedatectl set-timezone "Asia/Shanghai"
                                                                   設置世界統一時區timedatectl set-timezone UTC
      NTP enabled: yes                               ==> 開啟自動同步時間服務器功能,timedatectl set-ntp true 或 timedatectl set-ntp false
      NTP synchronized: yes                          ==> 與時間服務器的同步狀態,如果顯示yes,則同步成功
      RTC in local TZ: no                            ==> 將時區設置為本地時區,timedatectl set-local-rtc 1
                                                         硬件時鍾設置為協調世界時(UTC)timedatectl set-local-rtc 0
      DST active: n/a



[root@network ~]# 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               
===============================================================================
^? controller                    9   6    37    47   +123us[ +123us] +/-   25ms           ==>如果前面是有個?表明時間服務器不可達 

如果一直顯示為? 表示網絡沒有設置正確,需要設置配置文件中的網絡
server : 10.50.10.10
client : 10.50.10.20
編輯 /etc/chrony.conf

【client】

# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 10.50.10.0/16

【server】

# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 10.50.10.20/24

再重新檢查是否可以同步

[root@network ~]# 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               
===============================================================================
^* controller                    9   6   177    46    +19us[  -65us] +/-   36ms         ==>如果前面是有個*表明時間服務器可同步








常用的命令:
啟動chronyd進程
systemctl start chronyd.service
強制單次進行時間同步  
chronyd -q 'server <時間服務器域名> iburst'
或者
ntpdate <ntp_server_name>
## 查看 ntp服務器是否可以正常同步
ntpdate -d <ntp_server_name>
## 查看 ntp_servers 狀態
chronyc sources -v
## 查看 ntp_sync 狀態
chronyc sourcestats -v
## 查看 ntp_servers 是否在線
chronyc activity -v
## 查看 ntp 詳細信息
chronyc tracking -v







當執行ntpdate -d <ntp_server_name>出現 NTP. Server dropped: strata too high  
可能原因是時間服務器stratum 值過高  調低就可以了  比如server為 8   client為9  則正常
當執行ntpdate -d <ntp_server_name>出現Server dropped: no data  
可能原因可以使用journalctl -xe 來查看,可能是selinux沒有關閉 可以在/etc/selinux/conf中disable

 

 


免責聲明!

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



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