2014-09-26 558 views
1

我有一個Ubuntu 14.04 Vagrant框。它似乎大多數時間都工作正常,但是每隔幾天我都會遇到問題。當流浪試圖ssh到機器,它得到一個警告:遠程連接斷開連接,連接到169.254.169.254超時

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 

這一直遭到打印出來,直到流浪失敗:

<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,除了一些事情是不正確的。即。共享文件夾未安裝。我能找到唯一的解決方法是摧毀並重新起機器:

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回車鍵到虛擬機沒有工作,因爲我有一個不同的問題對這個問題的提問者)

UPDATE:繼@ ElfElix的意見,我在/ etc /網絡/接口,一看,只見這一點:

#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不僅失敗,因爲它無法連接,但在等待一段時間後我無法ssh進入。

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

UPDATE II: 看來,虛擬機將只有初始vagrant up這將創造和提供本機後開始。在停止機器之後,它會遇到上述錯誤,因此不能正確顯示。

+0

兩件事:不要添加日誌的屏幕截圖,複製粘貼數據,以便我t可以是有用的(例如可搜索的)。我不喜歡ip爲「169.254.168.254」,169.254.x.x的IP地址用於網絡問題的特殊場合 – xlembouras 2014-09-26 06:07:24

回答

0

如果機器ip由DHCP設置,請嘗試將其設置爲靜態並手動設置。它每隔幾天持續這樣做的原因是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 

重新啓動網絡配置(S)如果您想詳細指南我會爲您節省搜索它的麻煩, Change DHCP IP to Static IP on Linux

+0

爲了說明DHCP的問題。 DHCP服務器爲您的機器分配一個IP,並且此IP在X時間內有效。經過X時間後,計算機必須要求DHCP服務器檢查其IP地址並驗證它,或給它一個新的IP地址。您必須將其設置爲靜態,以保持不變。這樣,機器的IP不會每週更改(或者DHCP服務器分配IP的速率)。動態IP地址(例如由DHCP服務器分配的地址)將會改變,靜態將保持不變。 – Vincent 2014-09-28 10:03:50

+0

無論如何要在Vagrantfile中做到這一點?理想情況下,我希望所有必需的設置都在那裏。 – 2014-09-28 23:06:36

+0

我將我的Vagrantfile添加到問題中。我不認爲它是用DHCP設置的,因爲我手動設置IP地址。 – 2014-09-29 01:43:12