警告:远程连接断开,连接到169.254.169.254超时

时间:2014-09-26 05:24:36

标签: ubuntu ssh vagrant virtualbox

我有一个Ubuntu 14.04 Vagrant盒子。它似乎在大多数时间都很好,但是每隔几天我就会遇到问题。当Vagrant试图进入机器时,它会得到一个

Warning: Remote connection disconnect. Retrying...

这是每隔几秒打印一段时间,直到我收到错误说它等待机器启动超时。我发现this question建议使用以下内容启动gui:

config.vm.provider :virtualbox do |vb|
  vb.gui = true
end

看看是什么让VM起来了。看起来VM正在调用url_helper.py

url_helper.py[WARNING]: Calling 'http://169.254.168.254/2009-04-04/meta/instance-id'
failed [101/120s]:request error [(<urllib3.connectionpool.HTTPConnectionPool object 
at 0x7ff2d6691450>, 'Connection to 169.254.168.254 timed out. 
(connect timeout=50.0)')]
url_helper.py[WARNING]: Calling 'http://169.254.168.254/2009-04-04/meta/instance-id'
failed [119/120s]:request error [(<urllib3.connectionpool.HTTPConnectionPool object 
at 0x7ff2d6682f50>, 'Connection to 169.254.168.254 timed out. 
(connect timeout=50.0)')]
DataSourceEc2.py[CRITICAL]: Giving up on md from 
['http://169.254.168.254/2009-04-04/meta/instance-id'] after 120s

这将继续打印出来,直到Vagrant失败:

<machine name>: Warning: Remote connection disconnect. Retrying...
<machine name>: Warning: Remote connection disconnect. Retrying...
<machine name>: Warning: Remote connection disconnect. Retrying...
Timed out while waiting for the machine to boot. This means that Vagrant was 
unable to communicate with the guest machine within the configured 
("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that Vagrant had 
when attempting to connect to the machine. These errors are usually good hints 
as to what may be wrong.

If you're using a custom box, make sure that networking is properly working and 
you're able to connect to the machine. It is a common problem that networking 
isn't setup properly in these boxes. Verify that authentication configurations 
are also setup properly, as well.

If the box appears to be booting properly, you may want to increase the timeout 
("config.vm.boot_timeout") value.

但稍后会继续登录屏幕。此时我可以登录或者输入,除非有些事情不对。即。共享文件夹未安装。我能找到的唯一解决方案是销毁和重新启动机器:

vagrant destroy -f && vagrant up

这可能需要一段时间,具体取决于机器的配置。

之前有其他人遇到过这个问题吗?有关如何解决此问题的任何建议吗?

这是我目前的Vagrantfile:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "trusty64"
  config.vm.box_url = "/media/resources/Development/Vagrant/Boxes/trusty64.box"

  config.vm.define "name" do |name|
    name.vm.hostname = "name"
    name.vm.network :private_network, ip: "192.168.45.12"
    name.vm.network :forwarded_port, guest: 7070,  host: 7070
    name.vm.network :forwarded_port, guest: 7443,  host: 7443

    name.vm.provider :virtualbox do |vb|
      vb.name = "name"
      vb.customize ["modifyvm", :id, "--memory", "2048"]
    end
  end

  config.vm.provision "ansible" do |ansible|
      ansible.playbook = "provisioning/playbook.yml"
      ansible.sudo = true
      ansible.verbose = "v"
      ansible.extra_vars = "@provisioning/user_vars.yml"
  end
end

顺便说一下,上面链接问题的另一个答案(通过vboxmanage将回车键发送到虚拟机不起作用,因为我对该问题的提问者有不同的问题。)

更新:按照@ ElfElix的建议,我查看了/ etc / network / interfaces并看到了这个:

#VAGRANT-BEGIN
#The contents below are automatically generated by Vagrant. Do not modify
auto eth1
iface eth1 inet static
    address 192.168.45.11
    netmask 255.255.255.0
#VAGRANT-END

虽然在/etc/network/interfaces.d/eth0.cfg中是:

# The primary network interface
auto eth0
iface eth0 inet dhcp

我尝试删除此文件以禁用DHCP,但这使情况变得更糟。 vagrant up不仅失败了,因为它无法连接,但在等待一段时间后我无法进入。

有没有人有其他想法?

更新II : VM似乎只会在创建和配置机器的初始vagrant up之后启动。暂停机器后,由于遇到上述错误,它将不再正常运行。

1 个答案:

答案 0 :(得分:0)

如果通过DHCP设置了机器ip,请尝试将其设置为静态并手动设置。它每隔几天一直这样做的原因是DHCP必须检查ip并再次分配它。

虚拟机,服务器,ftp服务器等应始终具有用于远程连接的静态IP。正如xlembouras所说“在网络问题的特殊情况下使用169.254.x.x范围的IP”,所以我收集的是DHCP服务器为其分配了无效的IP(或旧的IP)。因此,您必须将其设置为静态并手动设置计算机上的IP,(子网)掩码和网关。这可以通过执行以下操作(从终端)在ubuntu服务器(或* buntu机器)上完成: (注意:如果您愿意,可以使用sudo而不是su。注意:如果您愿意,可以使用VIM)

sudo su
cd /
cd etc/network
vi interfaces

默认情况下应设置DHCP(即使它不在文本中)。如果您看到一行

"iface eth0 inet dhcp"

用静态替换“dhcp”并继续在它下面设置IP和其他东西。

示例(使用此逐字逐句,因为它是一个例子):

iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.254

现在通过

重启网络配置
/etc/init.d/networking restart

如果你想要一份详细的指南,我会省去谷歌搜索的麻烦, Change DHCP IP to Static IP on Linux