想要使用本地镜像而不更改 /etc/apt/sources.list 吗?

想要使用本地镜像而不更改 /etc/apt/sources.list 吗?

我们有 Ubuntu (Debian) 的本地镜像http://ubuntu.wikimedia.org/ubuntu/https://mirrors.wikimedia.org/debian/)。我想配置客户端优先从这些镜像下载/仅从这些镜像下载软件包,而不是http://nova.clouds.archive.ubuntu.com/ubuntu/http://httpredir.debian.org/debian/)。我可以通过替换中的 URL 成功完成此操作/etc/apt/sources.list,但我对此很感兴趣没有进行更改/etc/apt/sources.list,以便定制显而易见并且可以轻松恢复。

我创建的/etc/apt/sources.list.d/wikimedia-mirror.list内容如下:

deb http://ubuntu.wikimedia.org/ubuntu/ trusty main universe
deb-src http://ubuntu.wikimedia.org/ubuntu/ trusty main universe

/etc/apt/preferences.d/wikimedia-mirror.pref

Package: *
Pin: origin "ubuntu.wikimedia.org"
Pin-Priority: 501

此后apt-get update,这将导致镜像中的软件包具有优先级 501,但apt-get会从原始源下载这些软件包:

scfc@toolsbeta-t68121-trusty:~$ apt-cache policy zsh-doc
zsh-doc:
  Installed: (none)
  Candidate: 5.0.2-3ubuntu6
  Version table:
     5.0.5-4ubuntu1~ubuntu14.04.1 0
        100 http://nova.clouds.archive.ubuntu.com/ubuntu/ trusty-backports/main amd64 Packages
     5.0.2-3ubuntu6 0
        500 http://nova.clouds.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
        501 http://ubuntu.wikimedia.org/ubuntu/ trusty/main amd64 Packages
scfc@toolsbeta-t68121-trusty:~$ sudo apt-get install zsh-doc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  zsh-doc
0 upgraded, 1 newly installed, 0 to remove and 35 not upgraded.
Need to get 2,274 kB of archives.
After this operation, 5,856 kB of additional disk space will be used.
Get:1 http://nova.clouds.archive.ubuntu.com/ubuntu/ trusty/main zsh-doc all 5.0.2-3ubuntu6 [2,274 kB]
Fetched 2,274 kB in 3s (631 kB/s)    
Selecting previously unselected package zsh-doc.
(Reading database ... 38984 files and directories currently installed.)
Preparing to unpack .../zsh-doc_5.0.2-3ubuntu6_all.deb ...
Unpacking zsh-doc (5.0.2-3ubuntu6) ...
Processing triggers for install-info (5.2.0.dfsg.1-2) ...
Setting up zsh-doc (5.0.2-3ubuntu6) ...
scfc@toolsbeta-t68121-trusty:~$

此行为与中的文档一致apt_preferences(5)

来源列表(5)`文件包含对多个来源的引用。在这种情况下apt-get下载最早列出的实例来源列表(5)文件。APT 首选项不会影响实例的选择,只会影响版本的选择。

有没有办法在不进行更改的情况下优先选择镜像而不是原始源/etc/apt/sources.list? 中的文件/etc/apt/sources.list.d是否可以“早于” /etc/apt/sources.list? 是否有可能存在可用于“映射” URL 的配置选项?

相关内容