1. 初始化环境(在线)
vagrant init centos6.7 https://github.com/CommanderK5/packer-centos-templa te/releases/download/0.6.7/vagrant-centos-6.7.box
2. 初始化环境(离线)
vagrant init centos6.7 /path/to/vagrant-centos-6.7.box ==>正确执行完init命令后,会输出如下信息: 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. 启动
vagrant up ==>正常启动,会输出如下信息 Bringing machine ‘default‘ up with ‘virtualbox‘ provider... ==> default: Box ‘centos‘ could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: >= 0 ==> default: Box file was not detected as metadata. Adding it directly... ==> default: Adding box ‘centos‘ (v0) for provider: virtualbox default: Unpacking necessary files from: file://C:/me/vagrant-centos-6.7.box ......
4. ssh连接
#由于windows本身不带ssh工具,我们可以根据下面的信息,通过xshell远程
vagrant ssh `ssh` executable not found in any directories in the %PATH% variable. Is an SSH client installed? Try installing Cygwin, MinGW or Git, all of which contain an SSH client. Or use your favorite SSH client with the following authentication information shown below: Host: 127.0.0.1 Port: 2222 Username: vagrant Private key: C:/me/.vagrant/machines/default/virtualbox/private_key
5. 查看主机状态
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`.
6. 保存虚拟机当前状态
vagrant suspend ==>输出如下 ==> default: Saving VM state and suspending execution...
7. 关闭主机
vagrant halt ==>输出如下 ==> default: Attempting graceful shutdown of VM...
8. 查看主机列表
vagrant box list ==>输出如下 centos (virtualbox, 0)
9. 移除主机
vagrant box remove centos ==>输出如下 Box ‘centos‘ (v0) with provider ‘virtualbox‘ appears to still be in use by at least one Vagrant environment. Removing the box could corrupt the environment. We recommend destroying these environments first: default (ID: 53661dff77cf466a88eb73346d11e488) Are you sure you want to remove this box? [y/N] y Removing box ‘centos‘ (v0) with provider ‘virtualbox‘...
10. 删除所有vagrant主机
vagrant destory ==>输出如下 default: Are you sure you want to destroy the ‘default‘ VM? [y/N] y ==> default: Destroying VM and associated drives...
时间: 2024-10-11 10:57:55