Skip to main content

Vagrant installs virtual machine

Vagrant installs virtual machine

Vagrant installs [virtual machine](/search?q=virtual machine)

Advantages: simple and convenient operation

The vagrant repository provides a configured mirror system, and you can quickly initialize and run a virtual machine with simple commands.

1. Install virtualBox

Official website: Oracle VM VirtualBox

Vagrant installs virtual machine

If the virtual machine installation fails, CPU virtualization may not be enabled on the computer.

Vagrant installs virtual machine

2. Install Vagrant

Vagrant official image repository: Discover Vagrant Boxes - Vagrant Cloud (vagrantup.com)

Vagrant software download: Install | Vagrant | HashiCorp Developer

Vagrant installs virtual machine

AMD64 corresponds to the x86 platform

3. Run the virtual machine

  1. Start virtualBox

  2. Open the windows cmd window and run the following command to initialize the centos7 system. The system name can be viewed through the official image warehouse in the second step.

    
  1. Run the following command to start the virtual machine. The system root user password is vagrant.
    

After successful startup, the corresponding virtual machine will appear on the virtualBox interface.

Vagrant installs virtual machine

4. Other commonly used commands in vagrant

  • Automatically connect to the virtual machine using vagrant user
    
  • upload files
    
  • Restart
    

Vagrant command line: vagrant init - Command-Line Interface | Vagrant | HashiCorp Developer

5. Configure a fixed IP for the virtual machine

The default IP address of the virtual machine is not a fixed IP, which is inconvenient for development.

  • Modify Vagrantfile
    

The IP here needs to be found using the ipconfig command under the physical machine.

    

Vagrant installs virtual machine

  • Reload vagrantfile
	vagrant reload # reboot
vagrant ssh # login

Check the ip address after logging in

	ip addr

Vagrant installs virtual machine

  • Ping test between host and virtual machine, normal communication in both directions

The host can ping the virtual machine, but the virtual machine can't ping the host.

After closing the following firewall, try and ping successfullyVagrant installs virtual machine

However, keeping the firewall turned off will affect host security, and the scope needs to be narrowed down. In fact, the Windows 10 firewall does not turn on ICMPv4-in, which affects packet forwarding. You can turn it on in the following way.

Vagrant installs virtual machine
Vagrant installs virtual machine

Tested again and both sides pinged normally.

6. Configure account and password to log in

By default, only ssh login is allowed. For the convenience of later operations, file upload, etc., we can configure to allow account and password login.

  1. Log in to the system vagrant ssh

  2. Modify the sshd_config file

sudo vi /etc/ssh/sshd_config

PasswordAuthentication yes

  1. Restart service
service sshd restart

  1. You can use the ssh connection tool to connect directly, user root, password vagrant

Note: VirtualBox will conflict with the following software, including but not limited to, you need to uninstall these software and then restart the computer; conflicting software: Starscream, 360, Net Master (possibly), etc.

7. Modify the mirror source

  1. Back up the original yum source
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

  1. Use new yum source
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

  1. Generate cache
yum makecache