当前位置: 首页 > 编程日记 > 正文

vagrant 介绍,安装与使用

可以帮你统一团队成员的开发环境。如果你或者你的伙伴创建了一个Vagrantfile,那么你只需要执行vagrant up就行了,所有的软件都会安装并且配置好。团队成员可以通过相同的Vagrantfile来创建他们的开发环境,无论他们是在Linux, Mac OS X, 或者Windows下,这样就可以保证你团队成员的代码是跑在相同的环境中。
安装非常简单,直接下载对应操作系统的版本就可以了
https://www.vagrantup.com/downloads.html
Vagrant 安装后还不能直接使用,因为它只是一个虚拟机管理和配置工具,虚拟机系统的安装和运行还得靠专门的虚拟化软件。Vagrant 默认已经内置了 VirtualBox Provider 用来跟 VirtualBox 交互,所以再去 VirtualBox 官网下载并安装 VirtualBox 就可以正式开始使用了。

程序员搞最多的就是码代码了,可能做很多个项目,公司里搞java的,php的,自己回家再玩个python什么的,想体验下新版本的mongodb或者nginx,Emacs或者vim的配置啦,保不准哪个项目前个版本的数据库是mysql,下个版本用了postgresql, 这么多东西全都搞在一起,装在一个电脑上,肯定会被这各种配置环境搞的晕晕的,烦不胜烦。
怎么办呢,最好是每个项目都有一个干净的开发环境,只为这个项目,可是我们不可能为每一个项目配一个电脑吧,有了,虚拟机,给每一个项目配一个虚拟机,开发A的时候就启A的虚拟机,这样各个开发环境互相独立,干干净净。还有一个问题,我们的项目有多个开发人员,如何保障大家的开发环境都一样呢,总不能每个人都一个个点击鼠标,填写配置参数,建好后上支一个个软件安装吧,这太麻烦了,太不geek了。我们想要的是,环境只配置一遍,然后可以把这个环境打包deliver给别人,别人拿到后,直接启起来就可以用。那有没有这样的东西呢,肯定是有的,Vagrant,它就是用来干这个的。
Create a single file for your project to describe the type of machine you want, the software that needs to be installed, and the way you want to access the machine. Store this file with your project code.
Run a single command — "vagrant up"
SSH into this machine with vagrant ssh
The first step in configuring any Vagrant project is to create aVagrantfile:
  1. Mark the root directory of your project. Many of the configuration options in Vagrant are relative to this root directory.
  2. Describe the kind of machine and resources you need to run your project, as well as what software to install and how you want to access it.

$ mkdir vagrant_getting_started $ cd vagrant_getting_started $ vagrant init
This will place a Vagrantfile in your current directory. 
specifying the box to use for your Vagrant environment is always the first step after creating a new Vagrantfile.
vagrant box add hashicorp/precise64
the username is "hashicorp", and the box is "precise64". 
run vagrant destroy back on your host machine, and Vagrant will terminate the use of any resources by the virtual machine.
The vagrant destroy command does not actually remove the downloaded box file. To completely remove the box file, you can use the vagrant box remove command.
By default, Vagrant shares your project directory (remember, that is the one with the Vagrantfile) to the /vagrant directory in your guest machine.
Note that when you vagrant ssh into your machine, you're in/home/vagrant. /home/vagrant is a different directory from the synced/vagrant directory.
logout退出!
installing packages, users, and more with provisioning:
Let us now serve those files using a webserver.
We could just SSH in and install a webserver and be on our way, but then every person who used Vagrant would have to do the same thing. Instead, Vagrant has built-in support for automated provisioning. Using this feature, Vagrant will automatically install software when youvagrant up so that the guest machine can be repeatably created and ready-to-use.
Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.provision :shell, path: "bootstrap.sh" end
The "provision" line is new, and tells Vagrant to use the shellprovisioner to setup the machine, with the bootstrap.sh file. The file path is relative to the location of the project root (where the Vagrantfile is).
If the guest machine is already running from a previous step, run vagrant reload --provision
port forwarding allows you to specify ports on the guest machine to share via a port on the host machine外面的宿主机. This allows you to access a port on your own machine, but actually have all the network traffic forwarded to a specific port on the guest machine.
Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.provision :shell, path: "bootstrap.sh" config.vm.network :forwarded_port, guest: 80, host: 4567 end
 load http://127.0.0.1:4567 in your browser. 
分享
Vagrant Share lets you share your Vagrant environment to anyone around the world with an Internet connection. It will give you a URL that will route directly to your Vagrant environment from any device in the world that is connected to the Internet.
https://www.vagrantup.com/docs/getting-started/share.html
Before being able to share your Vagrant environment, you will need an account on HashiCorp's Atlas. Do not worry, it is free.
Once you have an account, log in using vagrant login:
$ vagrant login Username or Email: mitchellh Password (will be hidden): You are now logged in!
SHARE
Once you are logged in, run vagrant share:
$ vagrant share ... ==> default: Your Vagrant Share is running! ==> default: URL: http://frosty-weasel-0857.vagrantshare.com ...
Your URL will be different, so do not try the URL above. Instead, copy the URL that vagrant share outputted for you and visit that in a web browser. It should load the Apache page we setup earlier.
To end the sharing session, hit Ctrl+C in your terminal.
-----------------------------------
停止:
Suspending the virtual machine by calling vagrant suspend will save the current running state of the machine and stop it. When you are ready to begin working again, just run vagrant up, and it will be resumed from where you left off. The main benefit of this method is that it is super fast, usually taking only 5 to 10 seconds to stop and start your work. The downside is that the virtual machine still eats up your disk space, and requires even more disk space to store all the state of the virtual machine RAM on disk.
Halting the virtual machine by calling vagrant halt will gracefully shut down the guest operating system and power down the guest machine. You can use vagrant up when you are ready to boot it again. The benefit of this method is that it will cleanly shut down your machine, preserving the contents of disk, and allowing it to be cleanly started again. The downside is that it'll take some extra time to start from a cold boot, and the guest machine still consumes disk space.
Destroying the virtual machine by calling vagrant destroy will remove all traces 痕迹of the guest machine from your system. It'll stop the guest machine, power it down, and remove all of the guest hard disks. Again, when you are ready to work again, just issue a vagrant up. The benefit of this is that no cruft is left on your machine. The disk space and RAM consumed by the guest machine is reclaimed 回收的and your host machine is left clean. The downside is that vagrant up to get working again will take some extra time since it has to reimport the machine and re-provision it.

转载于:https://www.cnblogs.com/elesos/p/7094692.html

相关文章:

HTML元素的基本特性

1,Disabled 特性: 1 //Disabled 设置元素不可用: 2 3 $(this).attr("disabled","disabled") 4 5 //移除push元素的diasble特性: 6 7 $("#push").removeAttr(disabled) 2,z-index 特性…

js base64 解码

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 解码函数 function base64_decode (input) { // 解码,配合decodeURIComponent使用var base64EncodeChars "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/";…

esl8266开发之旅_从ESL老师到越南软件开发人员的旅程

esl8266开发之旅by alberto montalesi通过阿尔贝托蒙塔莱西 从ESL老师到越南软件开发人员的旅程 (My Journey from an ESL Teacher to Software Developer in Vietnam) 介绍 (Introduction) Hi, my name is Alberto, and this is the story of how I learned to code, wrote a…

洛谷P2429 制杖题 [2017年6月计划 数论10]

P2429 制杖题 题目描述 求不大于 m 的、 质因数集与给定质数集有交集的自然数之和。 输入输出格式 输入格式:第一行二个整数 n,m。 第二行 n 个整数,表示质数集内的元素 p[i]。 输出格式:一个整数,表示答案&#xff0c…

微信小程序框架封装登录,网络请求等公共模块及调用示例

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 这个公共模块封装了session的获取,和fromId发送,showToast成功和失败的弹窗。 微信小程序公共通用模块 const util require(../utils/util.js);function init() {var that th…

安装centos后无法引导启动windows7的解决方法

在电脑Windows7系统上安装Centos7,安装后找不到Windows7引导菜单。 原因:因为CentOS 7已采用新式的grub2系统,所以需要进入/boot/grub2目录后使用vi编辑grub.cfg文件。 解决方法一:修改Centos 7的Grub2引导,添加Window…

git最佳实践_Git最佳实践如何为我节省大量的返工时间

git最佳实践by Hemal Patel通过赫马尔帕特尔 Git最佳实践如何为我节省大量的返工时间 (How Git best practices saved me hours of rework) Recently I was working on the task to upgrade a certificate for a NodeJS application. This was last touched two years ago for…

商品列表选择尺寸和颜色高亮,并且把选择的数据传递到下一个页面

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 需求:商品列表选择属性,给中的属性显示高亮,并且把选择的数据记录下来传递到下一个页面。 项目下载地址:点击去下载 效果图: 选择商品的属性…

Android studio 使用心得(三)—从Eclipse迁移到Android studio

断断续续的也算是把eclipse上的代码成功迁移到android studio上来了,现在,我同事继续用eclipse,我用android studio,svn上还是之前eclipse的项目,迁移成功后,我也能happy的开发了,两不误.直接来分享我捉摸的…

代码改变世界_改变世界,一次只写一行代码

代码改变世界People like to look at changing the world as a big task. I believe changing the world can be done in little steps.人们喜欢将改变世界视为一项艰巨的任务。 我相信,改变世界可以一步步完成。 The key is identifying a problem and taking a l…

14_传智播客iOS视频教程_instancetype

12312312转载于:https://www.cnblogs.com/ZHONGZHENHUA/p/7097094.html

HDU 1011-Starship Troopers(树形背包)

题意: 有n个洞,连接像一棵树,每个包含一定数量的怪和价值,给你m个士兵,每个士兵能打20个怪,杀完一个洞的怪可得该洞的价值才可继续打相连的下面的洞(每个士兵只能打一个洞)&#xff…

微信小程序自定义组件之Picker组件

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 需求: 通过JS条件判断,满足条件就弹出Picker给用户选择一个数组里面的数据。 有些朋友可能会有疑问: 1.为什么要使用自定义的Picker组件,不是有原生的组…

kotlin ++ --_顺便说一句-探索Kotlin代表团

kotlin --by Adam Arold亚当阿罗德(Adam Arold) 顺便说一句-探索Kotlin代表团 (By the way — exploring delegation in Kotlin) Kotlin has an interesting keyword, by, which can be used for delegation. There is a lot of confusion around it, so in this article we’…

网页制作之html基础学习3-css样式表

样式:CSS(Cascading Style Sheets,层叠样式表),作用是美化HTML网页。 在样式里面用 /* */ 进行注释。 1、样式表的基本概念 1.1、样式表分类 1、内联样式表 和html联合显示,控制精确,但是可重用性差&#…

Mac OS X 下查看和设置JAVA_HOME

原文链接 : http://blog.csdn.net/done58/article/details/51138057 1, 查看Java版本 打开Mac电脑,查看JAVA版本,打开终端Terminal,通过命令行查看笔者的java版本:: [html] view plaincopy bogon:~ donny$ java -vers…

微信小程序获取用户设备的信息

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 可以获取用户的手机型号,手机操作系统,微信版本,屏幕宽高等等。 Object wx.getSystemInfoSync() wx.getSystemInfo 的同步版本 返回值 Object res 属性类型说明最…

php 命令执行crud_如何使用原始JavaScript执行CRUD操作

php 命令执行crudby Zafar Saleem通过Zafar Saleem 如何使用原始JavaScript执行CRUD操作 (How to perform CRUD operations using vanilla JavaScript) Nowadays there are a number of JavaScript frameworks around such as React, Angular, Vue and so on. They all offer …

关于手机系统信息的总结

获取IMEI号: /*** 获取IMEI号* * Description:* param param activity* param return* return String*/public static String getIMEI(Activity activity) {TelephonyManager manager (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);return manage…

pat1011. World Cup Betting (20)

1011. World Cup Betting (20) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueWith the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing b…

如何清空定时器

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 看代码 var aaaa; //利用slice function truncate(arr) {return arr.slice(0, -1); } Page({data: {},onShow() {console.log(yyyyyyyyyyyyyyyyyyy)clearInterval(aaaa)aaaa setInterval(function () {…

如何解决JavaScript中的根查找

介绍 (Introduction) I’ve been wanting to write about this topic for a while now. I recently had the opportunity to work on simulating the GoalSeek functionality of Excel for a web application. I found the whole purpose of GoalSeek and how it works fascina…

菜单样式1:鼠标悬停向下弹出列表

JS部分:var qcloud{};$([_t_nav]).hover(function(){var _nav $(this).attr(_t_nav);clearTimeout( qcloud[ _nav _timer ] );qcloud[ _nav _timer ] setTimeout(function(){$([_t_nav]).each(function(){$(this)[ _nav $(this).attr(_t_nav) ? addClass:remo…

JS 保持数组长度为3位并且值不重复

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 需求:保存用户搜索的3次历史记录,新的代替旧的,重复的不录入。 这里有几种情况: 1.第一次搜索,搜索的历史缓存数组为空,就直接添…

Mysql 查询 字符串 (索引和通配符)

需要查询的 Mission_Info 字段 值 CYVR-0220-1240-ZYTX-1415-1740-ZUUU-9999-9999-ZZZZ-9999-9999-ZZZZ SELECT Mission_Info FROM flightplan WHERE Mission_Info LIKE %CYVR-____-____% AND Mission_Info LIKE %-ZYTX%AND instr(Mission_Info, CYVR) <instr(Mission_In…

使用Python和NLTK的自然语言处理(NLP)教程

Natural language processing (NLP) is a branch of artificial intelligence that helps computers understand, interpret, and manipulate human language.自然语言处理(NLP)是人工智能的一个分支&#xff0c;可以帮助计算机理解&#xff0c;解释和操纵人类语言。 This vid…

微信公众号网页获取用户信息

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 效果图 html 代码&#xff1a; <!DOCTYPE html> <html><head><meta name"viewport" content"widthdevice-width, initial-scale1.0, user-scalableno, minimum-sc…

React Native —— App

使用 React Native 作为 app 框架&#xff0c;Redux 作为数据层&#xff0c;因此我们需要选用一些支持性的技术和工具&#xff1a; 开源的 Parse Server 做数据存储 - 运行在 Node.js 上。Flow 用来做 React Native 的 JavaScript 输入错误检查&#xff0c;防止低级的输入错误。…

数据库访问性能优化

数据库访问性能优化 转载于:https://www.cnblogs.com/daishuguang/p/4707357.html

如何使用日志进行程序调试_如何使用日志节省调试时间

如何使用日志进行程序调试by Maya Gilad通过Maya Gilad 如何使用日志节省调试时间 (How to save hours of debugging with logs) A good logging mechanism helps us in our time of need.一个 良好的日志记录机制可以在需要时帮助我们。 When we’re handling a productio…