ubuntu - 警告 : remote connection disconnect, 连接到 169.254.169.254 超时

标签 ubuntu ssh vagrant virtualbox

我有一个 Ubuntu 14.04 Vagrant 盒子。它似乎大部分时间都可以正常工作,但是每隔几天我就会遇到问题。当 Vagrant 尝试 ssh 进入机器时,它会得到一个

Warning: Remote connection disconnect. Retrying...

每隔几秒钟就会打印一段时间,直到我收到一个错误,说它在等待机器启动时超时。我找到了this question建议使用以下命令启动 gui:
config.vm.provider :virtualbox do |vb|
  vb.gui = true
end

看看是什么阻碍了虚拟机。看起来虚拟机在调用 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.

但稍后将继续进入登录屏幕。此时我可以登录或 ssh 登录,除了有些地方不对。 IE。未安装共享文件夹。我能找到的唯一解决方案是销毁并重新启动机器:
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失败,因为它无法连接,但等待一段时间后我无法进入。

有没有人有任何其他想法?

更新二 :
似乎虚拟机只会在初始 vagrant up 之后启动这将创建和配置机器。停止机器后,由于遇到上述错误,它将不再正确出现。

最佳答案

如果机器 ip 由 DHCP 设置,请尝试将其设置为静态并手动设置。它每隔几天就会这样做的原因是 DHCP 必须检查 ip 并重新分配它。

虚拟机、服务器、ftp 服务器等应始终具有用于远程连接的静态 IP。正如 xlembouras 所说“169.254.xx 范围的 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

关于ubuntu - 警告 : remote connection disconnect, 连接到 169.254.169.254 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26052604/

相关文章:

python - 有没有办法让anaconda变小?

javascript - 在 Ubuntu 上托管后查找 MongoDB 详细信息

java - 通过 ssh jenkins 构建工件 - PHP

Laravel 和 Vagrant : Don't have/home/vagrant folder

python - virtualenv 的 Upstart 问题 - Python/Ubuntu

ubuntu - 如何开启ubuntu计算器编程模式

ssl - rsync后无法ssh进入远程机器

linux - 如何使用 ssh 将变量值传递给另一台服务器

cygwin - chmod无法更改Vagrant VM中的权限

amazon-ec2 - 将 Amazon EC2 AMI 转换为虚拟盒或 Vagrant 盒