使用Vagrant配置本地開發環境
從二零一四年開始使用vagrant+VirtualBox搭建linux開發環境,配置簡單靈活,后臺運行占用內存少,比vmware好用很多,果斷棄用vmware轉投vagrant的懷抱;無論是個人搭建開發環境還是團隊統一開發環境,vagrant是最方便快捷的方式。

問題一:
但是最近在使用的時候遇到一些坑,記錄下來以免下次遇到浪費時間去查找解決;經過是這樣的:從家里的agrant打包了一份開發環境到公司的新電腦上,vagrant init {boxname}初始化后使用vagrant up啟動虛擬機卻一直啟動失敗,提示如下:
D:\webroot\vagrant>vagrant up
Bringing machine 'default' up with 'VirtualBox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. 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.
通過查找資料,在stackowverflow上有網友也遇到過相同問題并給出解決方案如下:
將Vagrantfile配置文件中vb.gui = true的注釋去掉
config.vm.provider "virtualbox" do |vb|
# # Don't boot with headless mode
vb.gui = true
#
# # Use VBoxManage to customize the VM. For example to change memory:
# vb.customize ["modifyvm", :id, "--memory", "1024"]
end
運行vagrant up 啟動 virtualbox 后,GUI會給出提示
VT-x/AMD-V硬件加速在您的系統中不可用。您的64-位虛擬機將無法檢測到 64-位處理器,從而無法啟動。
這是由于在BOIS中沒有開啟cpu虛擬化支持,重啟F2或F10等進入BIOS設置Virtualization為Enable(我的Thinkpad是Security=>Virtualizatio設置為Enable);
電腦重啟后,再次vagrant up啟動虛擬機還是有一些問題,當時也沒有記錄下來錯誤信息,只記得解決方案是使用vagrant destroy將虛擬機從磁盤中刪除,然后使用vagrant up命令重新創建。
問題二 (2015.5.7更新)
vagrant啟動報錯The following SSH command responded with a non-zero exit status.
D:\vagrant_web>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 80 => 8080 (adapter 1)
default: 3000 => 3000 (adapter 1)
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
ARPCHECK=no /sbin/ifup eth1 2> /dev/null
Stdout from the command:
Device eth1 does not seem to be present, delaying initialization.
Stderr from the command:
雖然vagrant up啟動報錯,但是vagrant ssh還是能登陸虛擬機的,進入虛擬機后,執行如下命令
sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
對, 問題就處在在持久網絡設備udev規則(persistent network device udev rules)是被原VM設置好的,再用box生成新VM時,這些rules需要被更新。而這和Vagrantfile里對新VM設置private network的指令發生沖突。刪除就好了。
vagrant reload 再次啟動就OK。
以上問題完美解決,記錄下來,避免忘記!
Vagrant官網 文檔齊全.
segment安裝使用方法 網友分享的使用說明,簡單明了!
虛擬化
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。