適用于 centos7 和ubuntu16.04+的快捷設置方法。
查看時間時區
通過一個命令:timedatectl 查看時間和時區和NTP是否同步等信息一目了然,非常好用。
root@tos-cen084036:~# timedatectl
Local time: Fri 2018-04-27 21:56:17 CST
Universal time: Fri 2018-04-27 13:56:17 UTC
RTC time: Fri 2018-04-27 13:57:11
Time zone: Asia/Shanghai (CST, +0800)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no
時間同步設置
設置時區
如果你的時區不對,用下面的命令設置
timedatectl set-timezone Asia/Shanghai
時間同步服務神器chrony
安裝
yum/apt install chrony
設置開機啟動
systemctl enable chronyd
啟動chronyd
systemctl restart chronyd
查看chrony 效果
root@tos-cen084036:~# chronyc sources -v
210 Number of sources = 4
.-- Source mode '^' = server, '=' = peer,'#' = local clock.
/ .- Source state '*' = current synced, '+'= combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be inerror, '~' = 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 ReachLastRx Last sample
===============================================================================
^- 61-216-153-105.hinet-ip.h 3 8 266 529+24ms[ +25ms] +/- 92ms
^- 119.79-161-57.customer.ly 2 10 375 955+31ms[ +32ms] +/- 305ms
^* time4.aliyun.com 2 9 377 258 +12ms[+14ms] +/- 20ms
^- ntp5.flashdance.cx 2 9 267 109 +17ms[+17ms] +/- 137ms
結束語
用戶會說那設置完怎樣使Linux繼續保持精準的NTP同步時間信息,根據教程這樣簡單的設置下,再也不用擔心,服務器的時間不準了。
掃一掃咨詢微信客服