~]# 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】linux
# 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/24spa
再從新檢查是否能夠同步code
[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