Skip to content

Ubuntu apt update error: “Release file is not yet valid”

Reyes Yang edited this page Jun 15, 2021 · 2 revisions

服务器检查更新失败

服务器上执行 sudo apt update 检查更新,返回错误如下:

Hit:1 ubuntu bionic InRelease Ign:3 linux/chrome/deb stable InRelease
Get:2 /ubuntu bionic-updates InRelease [88.7 kB]
Get:5 /linux/chrome/deb stable Release [943 B]
Get:6 http://dl.google.com/linux/chrome/deb stable Release.gpg [819 B]
Get:4 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB] Get:7 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Reading package lists... Done
E: Release file for http://dl.google.com/linux/chrome/deb/dists/stable/Release is not valid yet (invalid for another 2h 45min 28s). Updates for this repository will not be applied. E: Release file for http://us.archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease is not valid yet (invalid for another 4h 34min 33s). Updates for this repository will not be applied. E: Release file for http://us.archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease is not valid yet (invalid for another 1h 22min 16s). Updates for this repository will not be applied. E: Release file for http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease is not valid yet (invalid for another 4h 32min 36s).

AskUbuntu 上找到解决方案,说是系统时间不对,需要同步下时间。执行命令

$ sudo hwclock --hctosys

再次执行 sudo apt update 后正常。

为什么时钟没有同步?

  1. https://www.digitalocean.com/community/tutorials/how-to-set-up-time-synchronization-on-ubuntu-18-04

查看当前时区设置

$ cat /etc/timezone
America/Los_Angeles

修改时区为 Asia/Shanghai

$ sudo dpkg-reconfigure tzdata

查看当前时间同步设置:

$ timedatectl
                      Local time: Tue 2021-06-15 21:33:12 CST
                  Universal time: Tue 2021-06-15 13:33:12 UTC
                        RTC time: Tue 2021-06-15 13:33:13
                       Time zone: Asia/Shanghai (CST, +0800)
       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

可以看出时钟同步服务已经开启了(systemd-timesyncd.service active: yes),但是时钟却没能同步(System clock synchronized: no) 查看下同步服务的状态:

$ sudo systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2021-06-15 21:29:37 CST; 16s ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 31177 (systemd-timesyn)
   Status: "Connecting to time server 91.189.89.198:123 (ntp.ubuntu.com)."
    Tasks: 2 (limit: 4680)
   CGroup: /system.slice/systemd-timesyncd.service
           └─31177 /lib/systemd/systemd-timesyncd

可以看到错误 Connecting to time server 91.189.89.198:123 (ntp.ubuntu.com)。使用 ntpd 替代 timesyncd。

$ sudo timedatectl set-ntp no
$ timedatectl
                      Local time: Tue 2021-06-15 21:37:38 CST
                  Universal time: Tue 2021-06-15 13:37:38 UTC
                        RTC time: Tue 2021-06-15 13:37:38
                       Time zone: Asia/Shanghai (CST, +0800)
       System clock synchronized: no
systemd-timesyncd.service active: no
                 RTC in local TZ: no
$ sudo apt install ntp
$ 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
$ timedatectl
                      Local time: Tue 2021-06-15 21:38:12 CST
                  Universal time: Tue 2021-06-15 13:38:12 UTC
                        RTC time: Tue 2021-06-15 13:38:13
                       Time zone: Asia/Shanghai (CST, +0800)
       System clock synchronized: yes
systemd-timesyncd.service active: no
                 RTC in local TZ: no

可以看到时间已经同步成功(System clock synchronized: yes)。