1、init
Command: vagrant init [name [url]]
功能:用來初始化一個虛擬機的配置,在相應目錄下,會生成一個Vagrantfile文件
案例:
[root@vagrant ubuntu]# vagrant init ubuntu/xenial64
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.
[root@vagrant ubuntu]# ll
total 4
-rw-r--r--. 1 root root 3019 Jan 30 01:34 Vagrantfile
2、up
Command: vagrant up
功能:根據目錄下的Vagrantfile文件啟動虛擬機,第一次會去網上下載虛擬機,最好先下載下來
案例:
1)、由于第一次運行,下載速度慢,我事先把box文件放到七牛云咯
http://soft.51yuki.cn/ubuntu-16.04_x86-64.box
2)、把剛剛下載的添加到vagrant
[root@vagrant vbox]# vagrant box add ubuntu16.04_louis /vbox/ubuntu-16.04_x86-64.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'ubuntu16.04_louis' (v0) for provider:
box: Unpacking necessary files from: file:///vbox/ubuntu-16.04_x86-64.box
==> box: Successfully added box 'ubuntu16.04_louis' (v0) for 'virtualbox'!
3)、修改vagrantfile文件
~~~
[root@vagrant ubuntu]# vim Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
#config.vm.box = "ubuntu/xenial64"
config.vm.box = "ubuntu16.04_louis" (把這個更改成剛剛vagrant box add Name URL,這里指定的Name)
~~~
4)、啟動系統
[root@vagrant ubuntu]# vagrant up
~~~
[root@vagrant ubuntu]# vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu16.04_louis'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: ubuntu_default_1517250341422_88745
==> 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: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default:
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: 5.0.40
default: VirtualBox Version: 5.1
==> default: Mounting shared folders...
default: /vagrant => /vagrant/ubuntu
~~~
3、status 查看狀態
[root@vagrant ubuntu]# vagrant status
Current machine states:
default running (virtualbox)
The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.
4、ssh
功能: ssh登錄到虛擬機
[root@vagrant ubuntu]# vagrant ssh
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-112-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
0 packages can be updated.
0 updates are security updates.
vagrant@ubuntu-xenial:~$ sudo apt-get update
5、suspend
功能:掛起虛擬機
案例:

6、reload
vagrant reload命令
功能:重啟虛擬機
案例:

7、halt
vagrant halt
功能:關閉虛擬機
案例:

8、destroy
vagrant destroy
功能:刪除虛擬機
- 第一章:Vagrant基礎介紹
- 第二章:Vagrant的安裝部署
- 第一節:在centos7.3的系統上安裝部署vagrant
- 第二節:在windows server 2008 R2的系統上安裝部署vagrant
- 第三章:vagrant常見命令
- 第一節:box
- 第二節:虛擬機相關的命令
- 第四章:vagrant管理虛擬機
- 第一節:初始化centos6的系統
- 第二節:初始化ubuntu16.04的系統
- 第三節:打包自己的box
- 第五章:Vagrant之網絡配置
- 第一節:通過Forwarded Ports(轉發端口)
- 第二節:Private Networks(私有網絡)
- 第三節:Public Networks(公有網絡)
- 第六章:常見錯誤
- 第七章:Vagrant之文件同步方式
- 第一節:synced_folder(把物理機的目錄同步到虛擬機里某個目錄)
- 第二節:通過NFS共享
- 第三節:通過rsync共享
- 第八章:Vagrantfile配置文件