Vagrant工具的安装
Vagrant工具的安装
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
这篇博客源于我的北京一位好友:崔佳。在此,为了感激崔佳的帮助,特意写下这篇博客。希望对一些开发的小伙伴有些帮助。
不怕大家笑话啊,再次之前,我对Vagrant一无所知,一般我在MAC上或是在WINDOWS操作系统上开发的代码想呀偶在linux上测试,我会用远程工具CRT进行远程,然后把代码贴上去进行测试。其实也就是2分钟就可以搞定的事情。但是还有一种更简单的方法去实现,再次特意跟大家分享一下。
都说FQ是运维的基本功,那么问题来了,你会FQ么?有的人是花钱买VPN进行FQ,有的人是用免费的工具进行FQ,我在网上看到有大牛给出了教程实现浏览器的FQ,我觉得蛮靠谱的,分享给大家,可参考该网有的教程进行FQ哟!链接:https://laod.cn/hosts/2017-google-hosts.html。好了,接下来我们一起来详解一下Vagrant的安装步骤吧~
2.安装VirtualBox程序;
安装步骤我就省略了,直接点下一步就好,整个过程一直点下一步,提示什么就点什么就OK。
二.安装Vagrant软件;
运行你刚刚下载的文件,对了,我刚刚给大家推荐的FQ是通过修改DNS实现的,并不能提升你的下载效率,只是让你可以FQ了而已。想要FQ还是得需要专门的下载工具。
1.点击下一步进行安装;
2.点击同意授权;
3.配置安装路径;
4.点击安装;
5.点击完成安装;
6.需要重启操作系统(重启之前请确认是否有重要数据未保存。);
三.安装ssh服务;
1.下载ssh安装程序,地址:https://www.mls-software.com/opensshd.html
2.点击安装;
3.点击下一步;
4.点击同意并进行下一步;
5.默认设置,点击下一步;
6.指定安装路径;
7.设置工作目录;
8.默认设置;(如果你不是2003的windows server就没有必要选择下面的特权分离)
9.默认端口;
10.默认即可;
11.点击下一步;
12.点击完成,完成安装;
13.测试是否安装成功;
四.添加环境;
1.添加镜像;(只是把镜像从官网下载到本地而已);
命令行中执行:C:\Users\Administrator>vagrant box add ubuntu/trusty64
2.初始化环境;(在哪个目录下初始化就会生成一个对应的“Vagrantfile”配置文件)
命令行执行:D:\>cd D:\VirtualBox\Vagrant_tools
命令行中执行:C:\Users\Administrator>vagrant init ubuntu/trusty64
3.配置虚拟机;
Vagrant 初始化成功后,会在初始化的目录里生成一个 Vagrantfile
的配置文件,可以修改配置文件进行个性化的定制。
用"Notepad++"编辑“Vagrantfile
”文件,修改你自己想要的参数修改的参数。
4.启动环境;
命令行中执行:C:\Users\Administrator>vagrant up
启动成功后,会在启动的目录中生成一个“.vagrant”的目录,里面存放着虚拟机的信息,与此同时你也可以切换到VirtualBox查看会多出来一台虚拟机,就是就说明你启动成功了,在启动的过程中,命令行会 出输出一些列的参数,这些参数你可以用windows的ssh去远程这台启动的虚拟机。
五.远程启动的虚拟机;
我们在启动的过程中会看到登录的账户密码;这个时候我们只需要在命令行中远程登录即可。
命令行输入:D:\VirtualBox\Vagrant_tools>ssh -p 2222 -l vagrant 127.0.0.1
这个时候我们需要可以测试一些命令,看是否真的是我们的ubantu系统。
测试网络的是否畅通。
六.在虚拟机安装Golang环境。
还记得我们刚刚配置的IP生效了吗?这个时候我们可以在局域网任何一台终端进行远程,然后我们可以进行上传或是下载文件等等,当然安装环境也是随你啦~哈哈~
安装具体步骤请参考:http://www.cnblogs.com/yinzhengjie/p/6482675.html
七.关联目录
其实就是虚拟环境中liunx目录和windows目录的一个映射关系,即你在windows创建一个目录,这个被关联的目录在linux操作系统上也会出现。
我们可以举个例子来说明一下:
先看一下windows系统的路径:
再看虚拟机的环境:
将windows的文件在虚拟机中运行测试:
该Vargrant目前pycharm已经支持了,但是goland目前版本还没有完善该功能,不过不就得将来或许会加上这个功能。
再附上Vagrantfile文件的内容一份,如果感兴趣的可以百度一下,进行深入学习一下。我这里就只介绍安装和基本的使用,其他功能我也用不着也没有打算在做深一步研究,哈哈~
1 # -*- mode: ruby -*- 2 # vi: set ft=ruby : 3 4 # All Vagrant configuration is done below. The "2" in Vagrant.configure 5 # configures the configuration version (we support older styles for 6 # backwards compatibility). Please don't change it unless you know what 7 # you're doing. 8 Vagrant.configure("2") do |config| 9 # The most common configuration options are documented and commented below. 10 # For a complete reference, please see the online documentation at 11 # https://docs.vagrantup.com. 12 13 # Every Vagrant development environment requires a box. You can search for 14 # boxes at https://vagrantcloud.com/search. 15 config.vm.box = "ubuntu/trusty64" 16 17 # Disable automatic box update checking. If you disable this, then 18 # boxes will only be checked for updates when the user runs 19 # `vagrant box outdated`. This is not recommended. 20 # config.vm.box_check_update = false 21 22 # Create a forwarded port mapping which allows access to a specific port 23 # within the machine from a port on the host machine. In the example below, 24 # accessing "localhost:8080" will access port 80 on the guest machine. 25 # NOTE: This will enable public access to the opened port 26 # config.vm.network "forwarded_port", guest: 80, host: 8080 27 28 # Create a forwarded port mapping which allows access to a specific port 29 # within the machine from a port on the host machine and only allow access 30 # via 127.0.0.1 to disable public access 31 # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" 32 33 # Create a private network, which allows host-only access to the machine 34 # using a specific IP. 35 # config.vm.network "private_network", ip: "192.168.33.10" 36 config.vm.network "private_network", ip: "172.16.30.1" 37 # Create a public network, which generally matched to bridged network. 38 # Bridged networks make the machine appear as another physical device on 39 # your network. 40 # config.vm.network "public_network" 41 42 # Share an additional folder to the guest VM. The first argument is 43 # the path on the host to the actual folder. The second argument is 44 # the path on the guest to mount the folder. And the optional third 45 # argument is a set of non-required options. 46 # config.vm.synced_folder "../data", "/vagrant_data" 47 48 # Provider-specific configuration so you can fine-tune various 49 # backing providers for Vagrant. These expose provider-specific options. 50 # Example for VirtualBox: 51 # 52 # config.vm.provider "virtualbox" do |vb| 53 # # Display the VirtualBox GUI when booting the machine 54 # vb.gui = true 55 # 56 # # Customize the amount of memory on the VM: 57 # vb.memory = "1024" 58 # end 59 # 60 # View the documentation for the provider you are using for more 61 # information on available options. 62 63 # Enable provisioning with a shell script. Additional provisioners such as 64 # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the 65 # documentation for more information about their specific syntax and use. 66 # config.vm.provision "shell", inline: <<-SHELL 67 # apt-get update 68 # apt-get install -y apache2 69 # SHELL 70 end