1. <i id="s6b2k"><small id="s6b2k"></small></i>
    <b id="s6b2k"><bdo id="s6b2k"></bdo></b>
  2. <wbr id="s6b2k"></wbr>

    vagrant+virtualBox構建虛擬機的方法_VirtualBox

    來源:腳本之家  責任編輯:小易  

    一、介紹

    Vagrant是一個構建和管理虛擬機(VirtualBox)的工具。

    我的環境:Mac + Vagrant + VirtualBox

    網盤下載地址:鏈接: https://pan.baidu.com/s/1LKacXPQcgh3MjgWiIZ0zhQ 密碼: n998

    二、安裝

    VirtualBox: https://www.virtualbox.org/wiki/Downloads
    Vagrant: http://downloads.vagrantup.co

    三、在線創建虛擬機

    1.在官網找到自己想要安裝的操作系統:https://app.vagrantup.com/boxes/search

    2.點進去,執行命令創建并啟動虛擬機:https://app.vagrantup.com/centos/boxes/7

    注意:需要單獨創建一個目錄,在該目錄下執行vagrant命令,一個目錄對應一個虛擬機。vagrant init會創建一個配置文件Vagrantfile

    三、離線創建虛擬機

    1.添加

    vagrant box add centOs7 /Users/xianbin.yang/Documents/vagrant/centos-7.0-x86_64.box

    ➜ vagrant vagrant box add centOs7 /Users/xianbin.yang/Documents/vagrant/centos-7.0-x86_64.box
    ==> box: Box file was not detected as metadata. Adding it directly...
    ==> box: Adding box 'centOs7' (v0) for provider:
      box: Unpacking necessary files from: file:///Users/xianbin.yang/Documents/vagrant/centos-7.0-x86_64.box
    ==> box: Successfully added box 'centOs7' (v0) for 'virtualbox'!

    2.初始化

    vagrant init centOs7

    ➜ vagrant vagrant init centOs7
    A `Vagrantfile` has been placed in this directory. You are now
    ready to `vagrant up` your first virtual environment! Please read
    the comments in the Vagrantfile as well as documentation on
    `vagrantup.com` for more information on using Vagrant.

    3.啟動

    vagrant up

    ➜ vagrant vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Importing base box 'centOs7'...
    ==> default: Matching MAC address for NAT networking...
    ==> default: Setting the name of the VM: vagrant_default_1612583375721_1893
    ==> 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 (guest) => 2222 (host) (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:
      default: Vagrant insecure key detected. Vagrant will automatically replace
      default: this with a newly generated keypair for better security.
      default:
      default: Inserting generated public key within guest...
      default: Removing insecure key from the guest if it's present...
      default: Key inserted! Disconnecting and reconnecting using new SSH key...
    ==> default: Machine booted and ready!
    ==> default: Checking for guest additions in VM...
      default: The guest additions on this VM do not match the installed version of
      default: VirtualBox! In most cases this is fine, but in rare cases it can
      default: prevent things such as shared folders from working properly. If you see
      default: shared folder errors, please make sure the guest additions within the
      default: virtual machine match the version of VirtualBox you have installed on
      default: your host and reload your VM.
      default:
      default: Guest Additions Version: 4.3.28
      default: VirtualBox Version: 6.1
    ==> default: Mounting shared folders...
      default: /vagrant => /Users/xianbin.yang/Documents/vagrant

    四、常用命令

    命令 作用
    vagrant box add 添加box的操作
    vagrant init 初始化box的操作,會生成vagrant的配置文件Vagrantfile
    vagrant up 啟動本地環境
    vagrant ssh 通過 ssh 登錄本地環境所在虛擬機
    vagrant halt 關閉本地環境
    vagrant suspend 暫停本地環境
    vagrant resume 恢復本地環境
    vagrant reload 修改了 Vagrantfile 后,使之生效(相當于先 halt,再 up)
    vagrant destroy 徹底移除本地環境
    vagrant box list 顯示當前已經添加的box列表
    vagrant box remove 刪除相應的box
    vagrant status 獲取當前虛擬機的狀態


    五、Vagrantfile常用配置

    1.配置固定ip、內存、cpu

    # -*- mode: ruby -*-
    # vi: set ft=ruby :
     
    Vagrant.configure("2") do |config|
     config.vm.box = "centOs7"
     config.vm.network "private_network", ip: "192.168.33.10"
     config.vm.provider "virtualbox" do |vb|
       vb.cpus = 4
       vb.memory = "8192"
     end
    end

    注意:配置后需要vagrant reload

    2.配置root用戶和ssh免密

    vagrant用戶登錄:vagrant ssh

    設置root密碼:sudo passwd root

    配置ssh免密:ssh-copy-id root@192.168.33.10

    ssh登錄:ssh root@192.168.33.10

    3.關閉防火墻

    檢查防火墻狀態:systemctl status firewalld
    關閉防火墻:systemctl stop firewalld
    設置開機禁用防火墻:systemctl disable firewalld.service

    參考鏈接:

    https://learn.hashicorp.com/tutorials/vagrant/getting-started-index?in=vagrant/getting-started

    到此這篇關于vagrant+virtualBox構建虛擬機的文章就介紹到這了,更多相關virtualBox構建虛擬機內容請搜索真格學網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持真格學網!

    您可能感興趣的文章:Ubuntu系統中部署Vagrant和VirtualBox的圖文教程win10下使用virtualbox + vagrant配置ruby開發機環境手把手教你使用 virtualBox 讓虛擬機連接網絡的教程詳解VirtualBox + CentOS 虛擬機網卡配置VirtualBox虛擬機安裝Ubuntu詳細教程(圖文)

  3. 本文相關:
  4. virtualbox下osx系統盤擴容方法
  5. virtualbox6安裝centos7設置靜態ip的方法及注意事項
  6. virtualbox中centos7安裝教程
  7. virtualbox安裝centos7虛擬機以及增強工具(圖文)
  8. ubuntu 下virtualbox 如何實現共享設置
  9. virtualbox中最小化安裝centos8.1虛擬機的教程詳解
  10. vagrant+virtualbox構建虛擬機的方法
  11. virtualbox 虛擬機中安裝 ubuntu 12.04(圖文教程)
  12. virtualbox配置虛擬網卡(橋接)——實現主機-虛擬機網絡互通
  13. virtualbox安裝ubuntu server16.04虛擬機的圖文教程
  14. virtualbox虛擬機怎么創建虛擬機
  15. 怎樣在virtualbox新建虛擬機
  16. 請問如何使用Oracle VM Virtualbox創建虛擬機?
  17. 關于建立虛擬機問題,使用Oracle VM VirtualBox建...
  18. oracle vm virtualbox怎樣新建虛擬電腦
  19. 如何整合Vagrant和Puppet來創建VirtualBox虛擬主機
  20. vagrant up 怎么讓VirtualBox以服務方式運行,不出...
  21. vagrant 和virtualbox 什么關系
  22. 如何用virtualbox和vagrant安裝nachos
  23. 怎樣把它給放到VirtualBox虛擬機中
  24. 網站首頁網頁制作腳本下載服務器操作系統網站運營平面設計媒體動畫電腦基礎硬件教程網絡安全dockerhyper-vvmwarevirtualboxxenserverkvmqemuopenvzxencloudstackopenstack云計算技術云其它首頁服務器云和虛擬化ubuntu系統中部署vagrant和virtualbox的圖文教程win10下使用virtualbox + vagrant配置ruby開發機環境手把手教你使用 virtualbox 讓虛擬機連接網絡的教程詳解virtualbox + centos 虛擬機網卡配置virtualbox虛擬機安裝ubuntu詳細教程(圖文)virtualbox下osx系統盤擴容方法virtualbox6安裝centos7設置靜態ip的方法及注意事項virtualbox中centos7安裝教程virtualbox安裝centos7虛擬機以及增強工具(圖文)ubuntu 下virtualbox 如何實現共享設置virtualbox中最小化安裝centos8.1虛擬機的教程詳解vagrant+virtualbox構建虛擬機的方法virtualbox 虛擬機中安裝 ubuntu 12.04(圖文教程)virtualbox配置虛擬網卡(橋接)——實現主機-虛擬機網絡互通virtualbox安裝ubuntu server16.04虛擬機的圖文教程virtualbox詳細安裝使用教程(圖文virtualbox 配置虛擬網卡(橋接),virtualbox主機和虛擬機之間文件virtualbox不能安裝64位系統的解virtualbox安裝增強功能時【未能virtualbox虛擬機安裝centos 7圖virtualbox下centos7網絡配置教程手把手教你使用 virtualbox 讓虛virtualbox 在centos 7 中安裝增virtualbox簡體中文版下載安裝(virtualbox centos7.7.1908 python3.8 搭virtualbox主機虛擬機互通的實現方法virtualbox 在centos 7 中安裝增強功能圖詳解virtualbox虛擬機網絡環境解析和搭建oracle vm virtualbox 安裝centos7操作系virtualbox win7 iis 由于擴展配置問題而在mac上利用virtualbox搭建本地虛擬機環境virtualbox 共享文件夾權限設置及使用方法virtualbox中ubuntu和windows共享文件夾設virtualbox 虛擬機中安裝 ubuntu 12.04(
    免責聲明 - 關于我們 - 聯系我們 - 廣告聯系 - 友情鏈接 - 幫助中心 - 頻道導航
    Copyright © 2017 www.yu113.com All Rights Reserved
    战天txt全集下载