如何使用 apt-cacher-ng 的镜像选项进行 debootstrap?

opt*_*lic 4 scripts debootstrap

debootstrap是这样跑的:

sudo debootstrap --verbose --arch=amd64 zesty chroot
Run Code Online (Sandbox Code Playgroud)

我已经安装了apt-cacher-ng

如何让它们一起工作,以便在我多次运行 debootstrap 时使用缓存而不是重复下载相同的包?

我曾尝试使用 MIRROR 选项并设置 http_proxy 变量,但是当我离线运行时它会出错:

$ sudo http_proxy="http://localhost:3142" debootstrap --verbose --arch=amd64 zesty chroot http://localhost:3142/uburep
I: Retrieving InRelease 
I: Failed to retrieve InRelease
I: Retrieving Release 
E: Failed getting release file http://localhost:3142/uburep/dists/zesty/Release
Run Code Online (Sandbox Code Playgroud)

我使用,http://localhost:3142/uburep因为这是我在缓存中找到的内容:

$ find /var/cache/apt-cacher-ng -name Release
/var/cache/apt-cacher-ng/security.ubuntu.com/ubuntu/dists/zesty-security/Release
/var/cache/apt-cacher-ng/uburep/dists/zesty-updates/Release
/var/cache/apt-cacher-ng/uburep/dists/zesty-backports/Release
/var/cache/apt-cacher-ng/uburep/dists/zesty/Release
Run Code Online (Sandbox Code Playgroud)

我尝试添加 Defaults env_keep += "http_proxy https_proxy ftp_proxy"到 /etc/sudoers(通过 sudo visudo),但也无济于事。

如果我删除 MIRROR 选项并离线运行 debootstrap,那么它似乎根本不使用 apt-cacher-ng(注意它是如何不再寻找 localhost 的)。

E: Failed getting release file http://archive.ubuntu.com/ubuntu/dists/zesty/Release
Run Code Online (Sandbox Code Playgroud)

0xC*_*22L 5

有一个技巧可以在没有显式代理设置的情况下使其工作。实际上,您可以apt-cacher-ng像这样使用您配置的镜像 URL:

http://localhost:3142/us.archive.ubuntu.com/ubuntu/
Run Code Online (Sandbox Code Playgroud)

因此,正如您在指定apt-cacher-ng实例的基本 URL 后所见,您可以按照这篇 Wiki 文章提供服务器和路径。我已经在我自己的引导脚本中使用了这种方法,它的作用就像一个魅力。

注意:您可能希望apt-cacher-ng通过检查lsof -i :3142(需要lsof包)来验证您的实例是否正在运行。