vagrant 虚拟机工具

#vagrant

[TOC]

##install

创建文件夹

vagrant init ubuntu/trusty64

vagrant up --provider virtualbox

##cmd
|cmd|描述|
|:|
|vagrant status|状态
|vagrant halt|强制关闭,立刻释放所有的ram
|vagrant suspend|挂起|
|vagrant up|启动|
|vagrant destroy|摧毁机器|
|vagrant reload|重启机器|

##访问控制

1
2
3
4
5
6
7
8
9
10
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
Add the following directly below those comments: config.vm.network :forwarded_port, guest: 80, host: 8080
Save the file and start your Vagrant virtual machine using the vagrant up command. If your virtual machine is currently running, you can reload it using the vagrant reload command.
This configuration change will setup port forwarding from port 8080 on the host machine (your computer) to the guest machine (your Vagrant virtual machine) when your virtual machine is running. This will allow you to access your web server using the URL http://localhost:8080.

##smoe lesson

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Vagrant Commands
We’re now ready to get started working within our Linux virtual machine. If your download hasn’t completed from the initial setup, go ahead and take a break and come back when that has completed. You won’t be able to make further progress until the virtual machine is up and running as much of the course will take place within this environment.
Before we access our machine, let’s quickly review a few commands that vagrant provides to make managing your virtual machines much simpler. Remember, your vagrant machine lives within this specific folder on your computer so make sure you’re within that same folder your created earlier; otherwise these commands won’t work as expected.
Type vagrant status
This command will show you the current status of the virtual machine. It should currently read “default running (virtualbox)” along with some other information.
Type vagrant suspend
This command suspends your virtual machine. All of your work is saved and the machine is put into a “sleep mode” of sorts. The machines state is saved and it’s very quick to stop and start your work. You should use this command if you plan to just take a short break from your work but don’t want to leave the virtual machine running.
Type vagrant up
This gets your virtual machine up and running again. Notice we didn’t have to redownload the virtual machine image, since it’s already been downloaded.
Type vagrant ssh
This command will actually connect to and log you into your virtual machine. Once done you will see a few lines of text showing various performance statistics of the virtual machine along with a new command line prompt that reads vagrant@vagrant-ubuntu-trusty-64:~$
Here are a few other important commands that we’ll discuss but you do not need to practice at this time:
vagrant halt
This command halts your virtual machine. All of your work is saved and the machine is turned off - think of this as “turning the power off”. It’s much slower to stop and start your virtual machine using this command, but it does free up all of your RAM once the machine has been stopped. You should use this command if you plan to take an extended break from your work, like when you are done for the day. The command vagrant up will turn your machine back on and you can continue your work.
vagrant destroy
This command destroys your virtual machine. Your work is not saved, the machine is turned off and forgotten about for the most part. Think of this as formatting the hard drive of a computer. You can always use vagrant up to relaunch the machine but you’ll be left with the baseline Linux installation from the beginning of this course. You should not have to use this command at any time during this course unless, at some point in time, you perform a task on the virtual machine that makes it completely inoperable.

参考链接:
first up帮助文档