1. IntroductionVagrant is a tool for building and managing virtual machines (VirtualBox). My environment: Mac + Vagrant + VirtualBox Download address: https://pan.baidu.com/s/1LKacXPQcgh3MjgWiIZ0zhQ Password: n998 2. Installation VirtualBox: https://www.virtualbox.org/wiki/Downloads 3. Create a virtual machine online1. Find the operating system you want to install on the official website: https://app.vagrantup.com/boxes/search 2. Click in and execute the command to create and start the virtual machine: https://app.vagrantup.com/centos/boxes/7 Note: You need to create a separate directory and execute the vagrant command in the directory . One directory corresponds to one virtual machine. vagrant init creates a configuration file Vagrantfile 3. Create a virtual machine offline1. Add 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. Initialization 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. Start 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 matches 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 4. Common commands |
Order | effect |
---|---|
vagrant box add | Add box operation |
vagrant init | Initializing the box will generate the Vagrant configuration file Vagrantfile |
vagrant up | Start the local environment |
vagrant ssh | Log in to the virtual machine where the local environment is located via ssh |
vagrant halt | Close the local environment |
vagrant suspend | Pause the local environment |
vagrant resume | Restore the local environment |
vagrant reload | After modifying the Vagrantfile, make it effective (equivalent to halt first, then up) |
vagrant destroy | Completely remove the local environment |
vagrant box list | Display the list of boxes that have been added |
vagrant box remove | Delete the corresponding box |
vagrant status | Get the current state of the virtual machine |
1. Configure fixed IP, memory, and 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
Note: vagrant reload is required after configuration
2. Configure root user and ssh password-free
Vagrant user login: vagrant ssh
Set the root password: sudo passwd root
Configure ssh without password: ssh-copy-id [email protected]
SSH login: ssh [email protected]
3. Turn off the firewall
Check the firewall status: systemctl status firewalld
Turn off the firewall: systemctl stop firewalld
Set to disable the firewall at startup: systemctl disable firewalld.service
Reference Links:
https://learn.hashicorp.com/tutorials/vagrant/getting-started-index?in=vagrant/getting-started
This is the end of this article about building a virtual machine with vagrant+virtualBox. For more information about building a virtual machine with virtualBox, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!
<<: English: A link tag will automatically complete href in IE
>>: Pure CSS3 to achieve pet chicken example code
Table of contents 1. Optional Chaining 2. Null va...
Table of contents Overview 1. Test for null value...
After reading some articles, I finally figured ou...
1. Custom text selection ::selection { background...
question: In some browsers, such as 360 browser...
In normal development, we usually use convex roun...
1. Pull the image docker pull registry.cn-hangzho...
WeChat applet trajectory playback mainly uses pol...
What if you designers want to use the font below ...
1. Create a user: Order: CREATE USER 'usernam...
1. MySQL master-slave asynchrony 1.1 Network Dela...
1. Put the mask layer HTML code and the picture i...
This tutorial shares the installation and configu...
To install a virtual machine on a Windows system,...
Solution 1: Use conditional import in HTML docume...