In this video, learn how to user VirtualBox and Vagrant to create a Linux VM. Also, learn how to manage the life cycle of the VM by preserving state and cleaning up files when you're done.
- [Narrator] Now that we have VirtualBox and Vagrant installed, let's create our first VM. On my system, I've downloaded the exercise files, and unzipped the content into my downloads folder. I've opened a terminal and navigated to the folder for Chapter One, Lesson One. This directory has a vagrant file that describes the VM we'll be creating. If you already have something running on your system that uses this IP address, you can avoid IP address conflicts by using a different IP address for your Vagrant Box.
Let's take a look inside this file. Even if you don't know Ruby, the programming language that Vagrant files are written in, it's fairly straight forward to figure out what's going on. The first line in this file sets the IP address that the VM will be configured to use. The following lines configure the VM by calling out the base box and a network configuration. In this case, the base box is the ubuntu 18.04 box from the Bento library.
This base box and others like it are freely available on the web. The last few lines of the Vagrant file print out a message with a URL for the VM's IP address. To start the VM, we simply run Vagrant Up. This will start the process of loading the base box. If you haven't downloaded the base box before, Vagrant will download it for you now. After this download, you won't have to download the base box again for any other VMs you create that use the same base box.
After the Vagrant Up command completes, the VM is running and all we need to do is connect to it. We do that with a Vagrant SSH command. This logs up into the VM with SSH, or Secure Shell, as the default user, which in this case is named Vagrant. Once we're logged in, we have full control of the VM, just like any other Linux server. To log out, we can type exit or type control+D.
To stop the VM, we run the command Vagrant Halt. Doing this powers down the VM, and preserves the current state. If we want to pick up where we left off, we can restart the VM by running Vagrant Up again. If we're done with the VM, we can completely remove it by running Vagrant Destroy. I'll type the Vagrant Destroy command here, just to show you what it looks like, but you don't need to run the command at this time. Before the VM is destroyed, we're prompted to confirm that we really want to destroy it.
The default is no, so you have to type y, and then press return. This stops the VM if it's running, and then removes any files associated with the VM. This command does not remove the Vagrant file. Using Vagrant and these few commands, we can easily create and manage VMs for our Sandbox Environment. For more in-depth lesson on using Vagrant, you can review Learning Vagrant in the Course Library.
- Installing NGINX on Linux
- Configuring a virtual host
- Installing PHP and MariaDB for the LEMP stack
- Securing sites with NGINX
- Creating SSL certificates
- Reverse proxies
- Load balancing