2013-06-18 140 views
39

我意識到這基本上是OSCeption(操作系統初始),但我認爲它可能對我最有意義(請告訴我是否有更好的選項,這看起來真的很糟糕)。在VMWare虛擬機中運行Vagrant

這種情況: 我有一個Windows 8機器。我喜歡它 - 它適用於除開發以外的任何事情。對於開發,我一直在使用運行Ubuntu的VMWare虛擬機。我已經涉足了使用Cygwin,但它感覺不對。

我現在加入他們一直在使用Vagrant來管理開發環境的項目,所以我需要能夠使用Vagrant。但是,從我看到的,Vagrant主要用於在一致的環境中運行代碼,但不一定要編寫它。如果我想通過SSH進入我的流浪箱來編寫代碼,那麼我將不得不重新配置我的喜好,比如我的.vimrc文件,以及哪些不適用於每臺機器。

然後在我的Ubuntu VirtualMachine中安裝Vagrant是否有意義?我覺得虛擬機中的虛擬機在某些時候會失控並導致問題。有沒有更好的方法來做到這一點?

編輯:所以我試了一下 - 正如我預料的那樣,我遇到了一些錯誤。當我嘗試啓動機器,我得到了以下錯誤消息:

Failed to open a session for the virtual machine vagranttest_1371583212. 

VT-x is not available. (VERR_VMX_NO_VMX). 

Result Code: NS_ERROR_FAILURE (0x80004005) 
Component: Console 
Interface: IConsole {db7ab4ca-2a3f-4183-9243-c1208da92392} 

看起來像我的VMware虛擬機不能運行其他虛擬機。任何關於如何去做這件事的想法?

+0

看起來您正在嘗試運行嵌入式類型2的虛擬機管理程序。首先,不是所有的hypervisors都支持在其中運行另一個hypervisor(相同或差異)。第二,你真的啓用了虛擬機的設置 - CPU - '可視化Intel VT-x或AMD-V'選項嗎? –

+4

順便說一句:只要啓用VT-x/AMD-V加速,VirtualBox內部的VirtualBox就是可能的。 –

+0

我可以證實Terry的評論 - 在我以前的地方,我們在vSphere虛擬機內部運行Vagrant虛擬機,以便構建和測試新的核心​​Vagrant框圖像:) –

回答

50

今天我遇到了同樣的問題。解決方案非常簡單。

  1. 關閉vmware虛擬機。
  2. 轉到「編輯虛擬機設置」
  3. 轉到處理器。那裏有三個複選框。
  4. 選中第二個複選框(啓用VT-x/AMD-V)
  5. 啓動機器。

之後這個virtualbox應該在vmware裏面工作。

+1

@ b.long:不,實際上它聽起來很粗魯。我希望我的解決方案能幫助你:) –

+0

確實如此,謝謝! – blong

+0

在使用CentOS安裝在VMWare虛擬機上並在CentOS內部使用VirtualBox的情況下,您是否遇到過任何問題?無論我做什麼,我的內部虛擬機都運行緩慢。我不希望這樣,因爲我給了CentOS VM 7140MB的內存,以及來自我的2.7GHz Core i7的2個內核。 當我嘗試啓動我的內部虛擬機(有或沒有Vagrant)時,它們運行緩慢,似乎沒有分配太多的內存。在虛擬機引導時,我看到CPU 1和2有點尖峯,然後最終下降,但內存使用量永遠不會超過1GB。當試圖啓動VM時,它會像這樣超時:https://gist.github.com/b-long/3ef3a726f9f4d28f4d59 – blong

4

要回答原來的問題以及@ blong的Vagrant論壇帖子,這是我所做的工作。我正在嘗試做類似的事情(實際上是Vagrant/VMware託管Vagrant/Vbox),我已經執行了所有我能想到的優化,爲我的「主機」虛擬機提供了大量的RAM(24GB)和6個通過設置「將所有虛擬機內存裝入保留的主機內存」,並允許每個虛擬機頁面文件(否則它們將存在於限制多少虛擬機的系統頁面文件中),禁止將虛擬機交換到磁盤(在Windows上發生這種情況)你可以一次運行)。

我正在做的工作一直很完美,我遇到的網絡問題是由於我背後的公司代理。一旦我配置了我的虛擬機可以訪問互聯網,並且全世界都是正確的。

除了在我的示例(Virtualbox)Vagrantfile中已經設置的natdnsproxy1和naddnshostresolver1之外,我必須通過Vagrantfile手動設置--natbindip1和--natnet1。這些設置可以在Virtualbox文檔中找到,以獲取正確的用法。總結一下,在虛擬機CPU設置中使用VT-x passthrough /「虛擬化」選項,爲虛擬機提供足夠的內存,不允許在「根」主機上交換內存,並且儘量確保你的網絡範圍不重疊,否則你會遇到路由問題。

這是我工作的Vagrantfile,它幾乎完全基於andreptb的要求,爲現代流行的流浪設置。 https://gist.github.com/andreptb/57e388df5e881937e62a

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

# box name into env var, same script can be used with different boxes. Defaults to win7-ie11. 
box_name = box_name = ENV['box_name'] != nil ? ENV['box_name'].strip : 'win7-ie11' 
# box repo into env var, so private repos/cache can be used. Defaults to http://aka.ms 
box_repo = ENV['box_repo'] != nil ? ENV['box_repo'].strip : 'http://aka.ms' 

Vagrant.configure("2") do |config| 
    # If the box is win7-ie11, the convention for the box name is modern.ie/win7-ie11 
    config.vm.box = "modern.ie/" + box_name 
    # If the box is win7-ie11, the convention for the box url is http://aka.ms/vagrant-win7-ie11 
    config.vm.box_url = box_repo + "/vagrant-" + box_name 
    # big timeout since windows boot is very slow 
    config.vm.boot_timeout = 500 

    # rdp forward 
    config.vm.network "forwarded_port", guest: 3389, host: 3389, id: "rdp", auto_correct: true 

    # winrm config, uses modern.ie default user/password. If other credentials are used must be changed here 
    config.vm.communicator = "winrm" 
    config.winrm.username = "IEUser" 
    config.winrm.password = "Passw0rd!" 

    config.vm.provider "virtualbox" do |vb| 
    # first setup requires gui to be enabled so scripts can be executed in virtualbox guest screen 
    #vb.gui = true 
    vb.customize ["modifyvm", :id, "--memory", "1024"] 
    vb.customize ["modifyvm", :id, "--vram", "128"] 
    vb.customize ["modifyvm", :id, "--cpus", "2"] 
    vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] 
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] 
    vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000] 
    end 
end 

我額外的變化:

# Need the WinRM gem for managing from Linux 
$ sudo gem install winrm 

    config.vm.communicator = "winrm" 
+ config.winrm.host = "localhost" 
    config.winrm.username = "IEUser" 
    config.winrm.password = "Passw0rd!" 
# This one may not be necessary, I added it for completeness 
+ config.vm.guest = :windows 

# In order to USE the two CPUs you need the ioapic 
# Virtualbox gives an error in the GUI and only shows 1 CPU in the VM otherwise 
     vb.customize ["modifyvm", :id, "--cpus", "2"] 
+ vb.customize ["modifyvm", :id, "--ioapic", "on"] 
# We had to modify the network range because we are running Virtualbox inside VMware 
+ vb.customize ["modifyvm", :id, "--natnet1", "192.168.199.0/24"] 

取出+跡象,並添加這些行到Vagrantfile上面,你應該有一個相當的工作系統,我一直使用的是什麼。

+0

我必須添加 v.customize [「modifyvm」,:id ,「--cpus」,「2」] v.customize [「modifyvm」,:id,「 - hwvirtex」,「on」]。 @ dragon788你是如何設定IP地址的? – vodich

+0

@vodich我做的和其他參數一樣。 [「modifyvm」,:id,「 - natbindip1」,「true」]。我將仔細檢查語法,但基本上它需要修改命令,VM ID,要更改的參數以及將其設置爲的值。 – dragon788

+0

謝謝,我想我會在一個關於配置的新線程中詢問一個關於配置的問題,而不是我們在這裏討論的,因爲我花了6個小時試圖弄清楚它沒有成功: – vodich

1

如果您在vsphere的VM中運行virualbox,則必須ssh到ESXi才能更新配置。

步驟:

  1. SSH到ESXi服務器。
  2. 找到屬於你的虛擬機VMX文件find/-name *.vmx
  3. 執行poweroff你的虛擬機(很重要的,否則你的改變將是覆蓋)
  4. 編輯VMX,在該文件的底部添加一個新的配置:vhv.enable = "TRUE"
  5. 虛擬機上的電源
  6. 享受流浪者。 :)
1

我已經在兩個VMware產品中嘗試了此操作。在虛擬機上單擊鼠標右鍵:

  • 在硬件選項卡上的vCloud Director 5.5 VM屬性有一個「暴露的硬件輔助的CPU虛擬化客戶機操作系統」複選框,但它變灰我。因人而異。
  • 在vSphere版本5.5.0編輯設置>虛擬硬件> CPU中,該複選框被稱爲「公開硬件輔助虛擬化到客戶操作系統」,並且這對我很有用。
相關問題