为什么我需要不断更新我的 apt 缓存?

Der*_*ler 6 debian apt

当我想安装新软件包时,通常会收到如下响应:

oliver@cloud:~$ sudo apt-get install unison
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package unison
Run Code Online (Sandbox Code Playgroud)

我已经知道了这种模式,我继续:

oliver@cloud:~$ sudo apt-get update
Hit http://downloads-distro.mongodb.org dist Release.gpg
Ign http://downloads-distro.mongodb.org/repo/debian-sysvinit/ dist/10gen Translation-en
Ign http://downloads-distro.mongodb.org/repo/debian-sysvinit/ dist/10gen Translation-en_US
Hit http://downloads-distro.mongodb.org dist Release
Ign http://downloads-distro.mongodb.org dist/10gen amd64 Packages
Ign http://downloads-distro.mongodb.org dist/10gen amd64 Packages
Ign http://http.debian.net/debian/ squeeze/contrib Translation-en_US
Ign http://http.debian.net/debian/ squeeze/main Translation-en_US
Ign http://http.debian.net/debian/ squeeze/non-free Translation-en_US
...

oliver@cloud:~$ sudo apt-get install unison
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  unison
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 693 kB of archives.
Run Code Online (Sandbox Code Playgroud)

如果我明天想安装一个新的软件包,服务器将不会知道它,直到我update再次安装。我只在 Debian 服务器上注意到这一点,并且我不知道有任何调整会导致这种情况。

我了解本地缓存的需要,我的问题是每当我想安装新东西时它似乎都会被重置。我希望缓存能够在更长的时间内保持填充状态。通常,当我第二天想安装新的东西时,apt-get会告诉我它无法找到该软件包。

在此服务器上,cron-apt已安装。我必须假设它是默认安装的。cron-apt设置为每晚 4:00 运行。它似乎是我丢失缓存的原因:

oliver@cloud:/var/lib/apt/lists$ sudo apt-get update
...
Fetched 12.1 MB in 11s (1,023 kB/s)
Reading package lists... Done
oliver@cloud:/var/lib/apt/lists$ ls /var/lib/apt/lists/ | wc -l
24
oliver@cloud:/var/lib/apt/lists$ sudo /usr/sbin/cron-apt
oliver@cloud:/var/lib/apt/lists$ ls /var/lib/apt/lists/ | wc -l
8
Run Code Online (Sandbox Code Playgroud)

我不太确定为什么会发生这种情况,因为据我所知, 的工作之一cron-apt是实际调用 apt-get update

oliver@cloud:/var/lib/apt/lists$ cat /etc/cron-apt/action.d/0-update
update -o quiet=2
Run Code Online (Sandbox Code Playgroud)

Der*_*ler 2

我终于能够解决这个问题了。正如之前所假设的那样,cron-apt这是罪魁祸首。或者更具体地说它的配置。

让我困惑的第一件事是,它cron-apt甚至已经安装了。因为我的其他机器上没有默认安装它。仅在我遇到此问题的 VPS 提供商的计算机上。我发现它的存在令人困惑,因为我假设脚本已经提供了类似的机制/etc/cron.daily/apt。无论哪种方式,如问题所示,运行cron-apt都会减少缓存的信息量。

我一开始不明白为什么会这样,因为cron-apt实际上每天都在执行更新。

oliver@cloud:/$ cat /etc/cron-apt/action.d/0-update
update -o quiet=2
Run Code Online (Sandbox Code Playgroud)

那么这是怎么回事呢?

我只是通过逐行执行脚本才发现问题所在/usr/sbin/cron-apt。我意识到这$APTCOMMAND总是会被$OPTIONS附加额外的内容。结果调用如下所示:

/usr/bin/apt-get -o quiet=1 -o Dir::Etc::SourceList=/etc/apt/security.sources.list update -o quiet=2

因此,我查看/etc/cron-apt/config并发现了该$OPTIONS块:

# General apt options that will be passed to all APTCOMMAND calls.
# Use "-o quiet" instead of "-q" for aptitude compatibility.
#  OPTIONS="-o quiet=1"
# You can for example add an additional sources.list file here.
#  OPTIONS="-o quiet=1 -o Dir::Etc::SourceList=/etc/apt/security.sources.list"
# You can also set an alternative sources.list file here.
#  OPTIONS="-o quiet=1 -o Dir::Etc::SourceList=/etc/apt/security.sources.list -o Dir::Etc::SourceParts=\"/dev/null\""
OPTIONS="-o quiet=1 -o Dir::Etc::SourceList=/etc/apt/security.sources.list"
# If you want to allow unauthenticated and untrusted packages add the
# following to your options directive.
#  OPTIONS="-o quiet=1 -o APT::Get::AllowUnauthenticated=true -o aptitude::Cmdline::ignore-trust-violations=yes"
# To limit the bandwidth used use the following line. This example limit the
# bandwidth usage to 25 kB/s.
#  OPTIONS="-o Acquire::http::Dl-Limit=25"
Run Code Online (Sandbox Code Playgroud)

一根线伸出来。没评论的那个。很明显,默认情况下这条线不存在(我也在另一个系统上很快确认了这一点)。

如果不明显,这些选项的原因是缓存的源每天晚上都会被安全列表的内容覆盖(并且只有这些内容)。

VPS 提供商已确认这是对其 Debian 安装映像的定制。我已经删除了有问题的设置,现在一切都恢复正常了。