在stream浪盒中configuration易于使用的代理

我正在使用Vagrant来设置一个虚拟机进行testing。 我希望在虚拟机内部使用主机上的代理来允许所有下载的caching在运行虚拟机的实例之间持续存在,不仅为了提高速度,而且为了让我启动stream浪实例没有networking连接。

我已经设置了正在运行的代理,并且我认为我已经通过在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' 

它的工作部分即最初的请求源打击caching和工作时,我的WiFi连接被禁用,但Squid正在运行,并有一些条目在它的caching。 我也可以看到一些从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 

然而,大部分下载的软件包并没有被caching,似乎根本没有经过Squid,也就是说,当它们被下载时,我可以看到大量的networking使用,并且它们不会出现在Squid访问日志中。

所以我的问题如何configurationApt为所有请求使用代理?

顺便说一句我也尝试通过设置环境variableshttp_proxyconfiguration:

  config.vm.provision :shell, :inline => "echo 'export http_proxy=http://10.0.2.2:3128' >> /etc/profile.d/proxy.sh" 

这也有同样的效果 – 有些请求似乎是打到Squid,但不是所有的,特别是不是真正的包。

    它有可能使用squid来处理所有请求,但是squid没有caching结果。 你可以通过嗅探stream量来validation这一点,或者在apt正在下载软件包并查看它们是否失败时closures鱿鱼。 你的squidconfiguration中的maximum_object_size是多less?

    即使你的问题可能在鱿鱼configuration,回答这个话题,现在有vagrant-proxyconf插件。 你可以通过以下方式安装

     vagrant plugin install vagrant-proxyconf 

    有了它,您可以在$HOME/.vagrant.d/Vagrantfile全局指定Apt代理,而无需在所有项目特定的stream浪文件中使用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 

    或默认代理configuration:

     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 

    下面的标题问题,如果你有私人networking设置,如:

     config.vm.network "private_network", ip: "192.168.22.22" config.vm.provision "shell", path: "scripts/provision.sh" 

    我发现通过在configuration脚本中简单导出http_proxy可以轻松地设置代理,如:

     # Detect proxy. GW=$(netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10) curl -s localhost:3128 > /dev/null && export http_proxy="http://localhost:3128" curl -s $GW:3128 > /dev/null && export http_proxy="http://$GW:3128" 

    然后照常运行apt-get

    这应该检测您的本地主机上的鱿鱼代理或主机自己。

    为了增加maximum_object_size值,这个例子是:

     maximum_object_size 64 MB 

    需要在cache_dir行之前定义。