Vagrant 的熟悉和使用

简介:工作由于忘形大,隔断时间常常忘记当初的情景和解决方案,归结原因是没有记录和记笔记的习惯,从今天开始希望 好好记笔记&总结

一方面可以提升自己的总结能力,另一方面可以方便以后查看,提高工作效率

前沿:

vagrant 需要和virtualbox 搭配使用,可查询virtualbox 下载版本即可,如果觉得太慢,可以私信我~我virtualbox版本是最新的

一、我的Vagrant版本:

[D:\HashiCorp\Vagrant\bin]$ vagrant.exe --version
Vagrant 2.2.4

二、添加一个Box

我这里是添加本机的一个下载好的box

[D:\HashiCorp\Vagrant\bin]$ vagrant.exe box add Ubuntu D:\BaiduNetdiskDownload\xenial-server-cloudimg-amd64-vagrant(1).box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'Ubuntu' (v0) for provider:
box:
The box you're attempting to add already exists. Remove it before
adding it again or add it with the `--force` flag.

Name: Ubuntu
Provider: virtualbox
Version: 0

三、查看一下当前的Box 列表

【D:\HashiCorp\Vagrant\bin】这里是安装路径

【D:\Applications\Vagrant】这里为了不混淆 我重新起了一个路径

[D:\Applications\Vagrant]$ Vagrant box list
ubuntu (virtualbox, 0)

四、启动命令

[D:\Applications\Vagrant]$ Vagrant up
==> default: Matching MAC address for NAT networking...==> default: Setting the name of the VM: Vagrant_default_1555125507464_27514==> 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: SSH address: 127.0.0.1:2222
default: SSH username: ubuntu
default: SSH auth method: password
default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Remote connection disconnect. Retrying... default: Warning: Connection reset. Retrying... 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: 6.0
==> default: Mounting shared folders...
default: /vagrant => D:/Applications/Vagrant

五、登陆vm

不要用xshell 使用该命令,虽然我不知道有什么限制,但是就是无法运行该命令

vagrant ssh

六、查看状态 vagrant status

七、关闭vm vagrant halt

八、销毁 vagrant destory Ubuntu

其他、

关于vagrantfile 其中的一些配置可以搜索一下相关的文件,这里就不多阐述了

最后,参考文章的链接:https://www.jianshu.com/p/b7d599403aa6

猜你喜欢

转载自www.cnblogs.com/santachi/p/10700460.html
今日推荐