Ubuntu(20.04 LTS) 配置北京时间

1,263 阅读1分钟

1. 查看当前时间

timedatectl status

输出:

               Local time: Fri 2023-05-12 07:52:49 CST
           Universal time: Fri 2023-05-12 07:52:49 UTC
                 RTC time: Fri 2023-05-12 07:52:50
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

2. 修改时区

sudo timedatectl set-timezone Asia/Shanghai

3. 修改NTP时间同步服务器

sudo vim /etc/systemd/timesyncd.conf

默认内容是这样的:

# ...

[Time]
#NTP=
#FallbackNTP=ntp.ubuntu.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

修改成下面

[Time]
NTP=ntp.tencent.com
FallbackNTP=ntp1.tencent.com,ntp2.tencent.com,ntp3.tencent.com
RootDistanceMaxSec=5
PollIntervalMinSec=32
PollIntervalMaxSec=2048

4. 重启服务

service systemd-timesyncd restart

再次查看时间

timedatectl status

输出:

               Local time: Fri 2023-05-12 16:23:11 CST
           Universal time: Fri 2023-05-12 07:52:49 UTC
                 RTC time: Fri 2023-05-12 07:52:50
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no