Vagrant、VirtualBox、Ansible 和 Ubuntu Server 出现奇怪的网络问题

Vagrant、VirtualBox、Ansible 和 Ubuntu Server 出现奇怪的网络问题

我们正在使用流浪汉Ansible提供虚拟盒机器。

运行良好,但最近我们在执行需要访问互联网的任务时开始遇到一些奇怪的网络问题,例如:、apt-get update等。这些问题时有发生,而且不稳定。有时它无法连接到某些服务器或无法解析域名。composer updategem install

有趣的是,当我通过 SSH()连接到盒子本身vagrant ssh并手动发出此类命令时,sudo apt-get update; sudo apt-get dist-upgrade它一直工作正常。

以下是 NPM 的示例错误:

failed: [localhost] => {"cmd": "/usr/bin/npm install --global npm-check-updates", "failed": true, "rc": 1}
stderr: npm http GET https://registry.npmjs.org/npm-check-updates
npm http GET https://registry.npmjs.org/npm-check-updates
npm http GET https://registry.npmjs.org/npm-check-updates
npm ERR! network getaddrinfo ENOTFOUND
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

以下是 APT 的示例错误:

failed: [localhost] => {"failed": true, "parsed": false}
invalid output was: SUDO-SUCCESS-qryiheatxowjxtcfbzrnzercnnwxtmyv
Traceback (most recent call last):
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1405611978.79-161922279792225/apt", line 1762, in <module>
    main()
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1405611978.79-161922279792225/apt", line 492, in main
    cache.update()
  File "/usr/lib/python2.7/dist-packages/apt/cache.py", line 440, in update
    raise FetchFailedException(e)
apt.cache.FetchFailedException: W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/main/i18n/Translation-en_US  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/main/i18n/Translation-en  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/main/i18n/Translation-en_US.UTF-8  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/universe/i18n/Translation-en_US  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/universe/i18n/Translation-en  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/universe/i18n/Translation-en_US.UTF-8  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/i18n/Translation-en_US  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/i18n/Translation-en  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/i18n/Translation-en_US.UTF-8  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/universe/i18n/Translation-en_US  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/universe/i18n/Translation-en  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/universe/i18n/Translation-en_US.UTF-8  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/main/source/Sources  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/universe/source/Sources  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/main/binary-i386/Packages  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/universe/binary-i386/Packages  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/source/Sources  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/universe/source/Sources  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/binary-i386/Packages  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/universe/binary-i386/Packages  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8c01::18). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::18 80]
, E:Some index files failed to download. They have been ignored, or old ones used instead.

软件版本

  • ansible 1.6.6
  • Vagrant 1.6.3
  • VirtualBox 4.3.14

我们正在使用以下盒子:

http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-i386-vagrant-disk1.box

主机操作系统Ubuntu 14.04

我们在完全不同的网络(不同的城市)中的不同计算机上遇到了这样的问题。

这是什么原因造成的?我们该如何调试和修复它?

更新 #1

Vagrant文​​件:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# "2" is an API version here.
Vagrant.configure("2") do |config|

  config.vm.box = "trusty32"
  config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-i386-vagrant-disk1.box"

  config.vm.hostname = "wa.local"
  config.vm.network "private_network", ip: "192.168.2.2"

  # Using NFS for now, cause native sharing is broken
  config.vm.synced_folder ".", "/vagrant", nfs: true

  # Provisioning
  config.vm.provision "ansible" do |ansible|
    ansible.host_key_checking = false
    ansible.inventory_path = "ansible/inventory.ini"
    ansible.playbook = "ansible/vagrant.yml"
    ansible.limit = "all"
  end

  # Provider Configuration: VirtualBox
  config.vm.provider :virtualbox do |vb|
    # Setting RAM to 1 GB
    vb.memory = 1024
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  end

end

更新 #2

问题暂时解决了。我仍然不知道为什么会出现这种情况。也许vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]我最近添加到 Vagrantfile 中的那行有帮助。

感谢所有建议!

答案1

您是否有任何可能导致问题的入侵防御设备或防火墙?我见过自动化方法触发旨在对抗机器人的规则。许多连接可能会被误解为端口扫描、暴力破解尝试等。然后,IDS/IPS/防火墙将开始丢弃数据包,导致奇怪的事情失败,而没有任何明确的逻辑来解释原因。当您手动执行操作时,这些规则不会触发,因此当您进行故障排除时,一切似乎都很好。

答案2

5 年后,版本升级至

  • Vagrant 2.2.4
  • Virtualbox 6.0.8

我仍然遇到同样的问题。vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]已经在 Vagrantfile 中了,现在我完全不知道还能做什么

从我目前了解的情况来看,这似乎是虚拟机内部的某种 DNS 问题

相关内容