目录
一、时区问题
一般ubuntu系统时间以utc时间为准,而国内开发一般需要将时间调整为北京时间
调整linux系统时区为北京时间东八区(GMT+8)
sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
二、时间校准 timesyncd
在ubuntu18.04中systemd-timesyncd.service服务控制着时间校准
systemctl status systemd-timesyncd.service
使用上述命令可查看时间校准的服务器ip
扫描二维码关注公众号,回复:
16768538 查看本文章
如果需要修改时间校准的服务器IP可在下述文件中修改
/etc/systemd/timesyncd.conf
三、时间控制 timedatectl
timedatectl
如图所示打印了当地时间,utc时间和一些网络信息,
System clock synchronized: yes 表示时间已经成功同步
systemd-timesyncd.service active: yes 表示第二部分所提到的timesyncd 已经使能并运行
如果timesyncd 没有运行,可使用timedatectl运行
sudo timedatectl set-ntp on
四、切换为ntpd控制
首先需要先失能timesyncd
sudo timedatectl set-ntp no
可使用第三部分提到的timedatectl查看失能是否成功
timedatectl
在输出中查找systemd-timesyncd.service active: no,这表明timesyncd已经被停止使用
安装ntp
sudo apt update
sudo apt install ntp
ntpd会自动被安装,可以使用ntpd请求状态信息查看时间校准是否正常
ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
0.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
1.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
2.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
3.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000
*time.cloudflare 10.208.8.4 3 u 1 64 1 169.565 -14.952 1.125
+119.28.206.193 100.122.36.196 2 u 1 64 1 66.869 -4.238 4.008
+ntp.wdc2.us.lea 130.133.1.10 2 u 1 64 1 243.232 -12.407 2.168
time.cloudflare 10.211.8.4 3 u 2 64 1 162.087 -15.373 0.316
electrode.felix 176.9.157.12 3 u 1 64 1 306.433 32.054 3.009
sv1.ggsrv.de 205.46.178.169 2 u 1 64 1 276.995 22.243 0.000
79.133.44.136 .MBGh. 1 u 1 64 1 263.325 18.109 3.761
185.125.190.56 145.238.203.14 2 u 1 64 1 364.959 -44.132 0.000
tick.ntp.infoma .GPS. 1 u 2 64 1 192.234 -13.950 1.211
185.125.190.58 86.23.195.30 2 u 4 64 1 380.550 -38.439 0.000
time.neu.edu.cn .PTP. 1 u 2 64 1 54.862 -15.519 1.330
alphyn.canonica 132.163.96.1 2 u 5 64 1 243.903 1.015 0.000