Vagrant是一個(gè)構建和管理虛擬機(VirtualBox)的工具。
我的環(huán)境:Mac + Vagrant + VirtualBox
網(wǎng)盤(pán)下載地址:鏈接: https://pan.baidu.com/s/1LKacXPQcgh3MjgWiIZ0zhQ 密碼: n998
VirtualBox: https://www.virtualbox.org/wiki/Downloads
Vagrant: http://downloads.vagrantup.co
1.在官網(wǎng)找到自己想要安裝的操作系統:https://app.vagrantup.com/boxes/search
2.點(diǎn)進(jìn)去,執行命令創(chuàng )建并啟動(dòng)虛擬機:https://app.vagrantup.com/centos/boxes/7
注意:需要單獨創(chuàng )建一個(gè)目錄,在該目錄下執行vagrant命令,一個(gè)目錄對應一個(gè)虛擬機。vagrant init會(huì )創(chuàng )建一個(gè)配置文件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.啟動(dòng)
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
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用戶(hù)和ssh免密
vagrant用戶(hù)登錄:vagrant ssh
設置root密碼:sudo passwd root
配置ssh免密:ssh-copy-id root@192.168.33.10
ssh登錄:ssh root@192.168.33.10
3.關(guān)閉防火墻
檢查防火墻狀態(tài):systemctl status firewalld
關(guān)閉防火墻:systemctl stop firewalld
設置開(kāi)機禁用防火墻:systemctl disable firewalld.service
參考鏈接:
https://learn.hashicorp.com/tutorials/vagrant/getting-started-index?in=vagrant/getting-started
到此這篇關(guān)于vagrant+virtualBox構建虛擬機的文章就介紹到這了,更多相關(guān)virtualBox構建虛擬機內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站