Dan*_*ack 5 proxy squid apt vagrant
我正在使用 Vagrant 设置虚拟机进行测试。我希望虚拟机内部的 apt 可以在主机上使用代理,以允许缓存所有下载内容在运行的虚拟机实例之间持续存在,不仅是为了提高速度,而且还允许我在启动 vagrant 实例时启动没有网络连接。
我已经设置了正在运行的代理,我想我已经告诉 apt 通过在 Vagrant 脚本中设置它来使用它:
config.vm.provision :shell, :inline => 'echo \'Acquire { Retries "0"; HTTP { Proxy "http://10.0.2.2:3128"; }; };\' >> /etc/apt/apt.conf'
config.vm.provision :shell, :inline => 'echo \'Acquire { Retries "0"; FTP { Proxy "ftp://10.0.2.2:3128"; }; };\' >> /etc/apt/apt.conf'
config.vm.provision :shell, :inline => 'echo \'Acquire { Retries "0"; HTTPS { Proxy "https://10.0.2.2:3128"; }; };\' >> /etc/apt/apt.conf'
Run Code Online (Sandbox Code Playgroud)
它正在部分工作,即当我的 wifi 连接被禁用但 Squid 正在运行并且它的缓存中有一些条目时,对源的初始请求命中缓存并工作。我还可以从 Squids 日志文件中看到一些击中 Squid 的请求:
1367492453.816 34 127.0.0.1 TCP_REFRESH_MODIFIED/200 592 GET http://security.ubuntu.com/ubuntu/dists/precise-security/Release.gpg - DIRECT/91.189.92.181 -
1367492453.987 168 127.0.0.1 TCP_REFRESH_MODIFIED/200 49973 GET http://security.ubuntu.com/ubuntu/dists/precise-security/Release - DIRECT/91.189.92.181 -
1367492453.999 325 127.0.0.1 TCP_MISS/404 588 GET http://us.archive.ubuntu.com/ubuntu/dists/precise/InRelease - DIRECT/91.189.91.13 text/html
1367492454.113 114 127.0.0.1 TCP_MISS/404 596 GET http://us.archive.ubuntu.com/ubuntu/dists/precise-updates/InRelease - DIRECT/91.189.91.13 text/html
Run Code Online (Sandbox Code Playgroud)
然而,大部分下载的包没有被缓存,而且似乎根本没有通过 Squid,即我可以看到下载它们时大量的网络使用,并且它们没有出现在 Squid 访问日志中。
所以我的问题是如何将 Apt 配置为对所有请求使用代理?
顺便说一句,我也尝试通过设置环境变量来配置http_proxy:
config.vm.provision :shell, :inline => "echo 'export http_proxy=http://10.0.2.2:3128' >> /etc/profile.d/proxy.sh"
Run Code Online (Sandbox Code Playgroud)
这具有相同的效果 - 一些请求似乎正在击中 Squid,但不是全部,尤其是实际的包。
即使您的问题可能出在鱿鱼配置中,为了回答该主题,现在有vagrant-proxyconf插件。您可以通过以下方式安装它:
vagrant plugin install vagrant-proxyconf
Run Code Online (Sandbox Code Playgroud)
有了它,您可以全局指定 Apt 代理,$HOME/.vagrant.d/Vagrantfile而无需在所有项目特定的 Vagrantfiles 中使用 shell 配置器。
例子:
Vagrant.configure("2") do |config|
config.apt_proxy.http = "http://10.0.2.2:3128"
config.apt_proxy.https = "http://10.0.2.2:3128"
end
Run Code Online (Sandbox Code Playgroud)
或默认代理配置:
Vagrant.configure("2") do |config|
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = "http://192.168.0.2:3128"
config.proxy.https = "http://192.168.0.2:3128"
config.proxy.no_proxy = "localhost,127.0.0.1,.example.com"
end
# ... other stuff
end
Run Code Online (Sandbox Code Playgroud)
apt 可能会使用鱿鱼来处理其所有请求,但鱿鱼不会缓存结果。您可以通过嗅探流量来验证这一点,或者在 apt 下载软件包时关闭鱿鱼并查看它们是否失败。您的鱿鱼配置中的最大对象大小是多少?