Vagrant使用指南:Vagrant命令使用简介
发布日期:2021-06-30 20:22:17
浏览次数:2
分类:技术文章
本文共 6020 字,大约阅读时间需要 20 分钟。
Vagrant是用ruby写的一个工具, 它的出现是为了更加容易的解决开发环境的一致性问题. 我们将会在本系列教程中学习到如何使用vagrant。在上一篇文章中我们使用了vagrant version/init/up/ssh等命令, 在本篇中对一些常用命令将做简单介绍.
命令一览
以下是vagrant1.8.5的命令一览。
命令 | 详细解释 |
---|---|
box | manages boxes: installation, removal, etc. |
connect | connect to a remotely shared Vagrant environment |
destroy | stops and deletes all traces of the vagrant machine |
global-status | outputs status Vagrant environments for this user |
halt | stops the vagrant machine |
help | shows the help for a subcommand |
init | initializes a new Vagrant environment by creating a Vagrantfile |
login | log in to HashiCorp’s Atlas |
package | packages a running vagrant environment into a box |
plugin | manages plugins: install, uninstall, update, etc. |
port | displays information about guest port mappings |
powershell | connects to machine via powershell remoting |
provision | provisions the vagrant machine |
push | deploys code in this environment to a configured destination |
rdp | connects to machine via RDP |
reload | restarts vagrant machine, loads new Vagrantfile configuration |
resume | resume a suspended vagrant machine |
share | share your Vagrant environment with anyone in the world |
snapshot | manages snapshots: saving, restoring, etc. |
ssh | connects to machine via SSH |
ssh-config | outputs OpenSSH valid configuration to connect to the machine |
status | outputs status of the vagrant machine |
suspend | suspends the machine |
up | starts and provisions the vagrant environment |
version | prints current and latest Vagrant version |
vagrant status
使用status命令可以确认当前vagrant的状态
[root@host31 ~]# vagrant statusCurrent machine states:default running (virtualbox)The VM is running. To stop this VM, you can run `vagrant halt` toshut it down forcefully, or you can run `vagrant suspend` to simplysuspend the virtual machine. In either case, to restart it again,simply run `vagrant up`.[root@host31 ~]#
vagrant suspend
使用suspend命令可以将vm挂起, 下面执行后可以看到状态从running变成saved了。
[root@host31 ~]# vagrant suspend==> default: Saving VM state and suspending execution...[root@host31 ~]# vagrant statusCurrent machine states:default saved (virtualbox)To resume this VM, simply run `vagrant up`.[root@host31 ~]#
vagrant halt
使用halt命令可以彻底关闭vm到poweroff状态。
[root@host31 ~]# vagrant halt==> default: Discarding saved state of VM...[root@host31 ~]# vagrant statusCurrent machine states:default poweroff (virtualbox)The VM is powered off. To restart the VM, simply run `vagrant up`[root@host31 ~]#
vagrant reload vmname
使用reload命令可以重新启动vm,其后要跟vm名,因为目前只有一个default,所以vagrant reload default即可以将其再启动。
[root@host31 ~]# vagrant reload default==> default: Checking if box 'hashicorp/precise64' is up to date...==> default: Clearing any previously set forwarded ports...==> 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: Booting VM...==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Remote connection disconnect. Retrying...==> 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: 4.2.0 default: VirtualBox Version: 5.1==> default: Mounting shared folders... default: /vagrant => /root==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`==> default: flag to force provisioning. Provisioners marked to run always will still run.[root@host31 ~]# vagrant statusCurrent machine states:default running (virtualbox)The VM is running. To stop this VM, you can run `vagrant halt` toshut it down forcefully, or you can run `vagrant suspend` to simplysuspend the virtual machine. In either case, to restart it again,simply run `vagrant up`.[root@host31 ~]#
vagrant port
port命令将会列出和宿主机之间的port的mapping关系
[root@host31 ~]# vagrant portThe forwarded ports for the machine are listed below. Please note thatthese values may differ from values configured in the Vagrantfile if theprovider supports automatic port collision detection and resolution. 22 (guest) => 2222 (host)[root@host31 ~]#
vagrant box
vagrant box下有6个命令,我们已经用过list命令确认vm列表,还有remove用以删除,以及add等
[root@host31 ~]# vagrant boxUsage: vagrant box[ ]Available subcommands: add list outdated remove repackage updateFor help on any individual subcommand run `vagrant box -h`[root@host31 ~]# vagrant box listhashicorp/precise64 (virtualbox, 1.1.0)[root@host31 ~]#
add命令失败由于网络状况下载时非常不安定而且超级慢,就不再演示了。
[root@host31 ~]# vagrant box add centos/7==> box: Loading metadata for box 'centos/7' box: URL: https://atlas.hashicorp.com/centos/7This box can work with multiple providers! The providers that itcan work with are listed below. Please review the list and choosethe provider you will be working with.1) libvirt2) virtualboxEnter your choice: 2==> box: Adding box 'centos/7' (v1607.01) for provider: virtualbox box: Downloading: https://atlas.hashicorp.com/centos/boxes/7/versions/1607.01/providers/virtualbox.boxAn error occurred while downloading the remote file. The errormessage, if any, is reproduced below. Please fix this error and tryagain.transfer closed with 494391624 bytes remaining to read[root@host31 ~]#
另外还有vagrant destroy命令起到从停止到删除的一系列动作的命令,以及vagrant login等连接到HashiCorp的 操作,这里也不再一一赘述。
常用vagrant网址
说明 | URL |
---|---|
官网 | |
box查询和下载 | |
box查询和下载 |
转载地址:https://liumiaocn.blog.csdn.net/article/details/52332055 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年05月02日 02时30分38秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
golang中的time包
2019-04-30
golang fmt包中的占位符
2019-04-30
Docker下使用Redis
2019-04-30
Redis的主从和集群设置
2019-04-30
对Redis Cluster的理解
2019-04-30
清华师哥丢了个在Github下载量50万+的项目给我,让(附源码下载地址)
2019-04-30
The MASM32 SDK version 10 发布了!
2019-04-30
发布软件:TreeInfo(分层信息管理器)
2019-04-30
c++二分图的最大匹配
2019-04-30
c++点的距离
2019-04-30
c++实现彩色炫酷(?)画面
2019-04-30
c++马拦过河卒
2019-04-30
2019NOIP D4题 加工领奖
2019-04-30
1997年世界黑客大赛获奖作品
2019-04-30
论DEV-C++怎样才能做窗口
2019-04-30
Failed to connect to github.com port 443: Operation timed out和弹出无法打开"GoogleSoftwareUpdate.bundle"
2019-04-30
2021.5.19 JS高级第二天
2019-04-30
2021.5.20 JS高级第三天
2019-04-30
2021.5.21 Jquery
2019-04-30
2021.5.22 Jquery
2019-04-30