适用于 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同步时间信息,根据教程这样简单的设置下,再也不用担心,服务器的时间不准了。
扫一扫咨询微信客服