vagrant虚拟机_与Vagrant Share在网络上共享您的虚拟机

vagrant虚拟机

Vagrant Share is a new feature of Vagrant 1.5+ that lets you share your local development environment to the web in literally seconds. You can even set it up to let others SSH into your virtual machine. I not only find this incredibly useful, but it's quite cool as well.

Vagrant ShareVagrant 1.5+的一项新功能,可让您在几秒钟内将本地开发环境共享到Web。 您甚至可以对其进行设置,以允许其他人SSH进入您的虚拟机。 我不仅发现这非常有用,而且也很酷。

喜欢流浪汉吗? 签出苏格兰威士忌盒-我们死了的简单LAMP流浪者盒 ( Like Vagrant? Check out Scotch Box - Our Dead Simple LAMP Vagrant Box )

I'm a huge fan of Vagrant! If you don't know what it is, 我是Vagrant的忠实粉丝! 如果您不知道它是什么, Vagrant is a tool for easily creating development environments. In layman's terms, you set a whole bunch of config options in a file, then tell Vagrant to use that configuration to provision and build you a server. Your server can be provisioned locally (making local development painless) or even on a provider such as Amazon or Digital Ocean. Here's a tutorial I wrote on Vagrant是一种轻松创建开发环境的工具 。 用外行的话来说,您在文件中设置了一整套配置选项,然后告诉Vagrant使用该配置来配置和构建服务器。 您的服务器可以在本地进行配置(使本地开发变得轻松),甚至可以在诸如Amazon或Digital Ocean之类的提供商上进行配置。 这是我写的 getting started with Vagrant. By the end of that tutorial, you'll have a PHP 5.4 LAMP stack running locally on your machine. Vagrant入门教程。 在该教程结束时,您将在计算机上本地运行一个PHP 5.4 LAMP堆栈。

什么是流浪云? ( What is Vagrant Cloud? )

I finally updated my Vagrant to 1.5+ (1.6.3 to be exact). I never liked to upgrade because I was afraid of things breaking or plugins not being compatible. With Vagrant 1.5+ though, Vagrant promised more stability and a ton of cool new features. It also comes with the new and awesome service Vagrant Cloud. Vagrant Cloud makes collaboration with Vagrant easy for teams small or large. Some things Vagrant Cloud offers are:

终于将我的Vagrant更新为1.5+(准确地说是1.6.3)。 我从不喜欢升级,因为我担心事情会破裂或插件不兼容。 不过,随着Vagrant 1.5+的发布,Vagrant承诺了更高的稳定性和大量酷炫的新功能。 它还带有新的,强大的服务Vagrant Cloud 。 Vagrant Cloud使无论规模大小的团队都能轻松地与Vagrant进行协作。 Vagrant Cloud提供的一些功能是:

  • Box Hosting (You may have to host the box yourself)

    Box Boxing(您可能必须自己托管Box)
  • Discover Public and Private Boxes

    发现公共箱和私人箱
  • Vagrant Share

    流浪者份额
  • Vagrant Share Static Names

    流浪者共享静态名称
  • Vagrant Share Custom Domain

    流浪者共享自定义域
  • Organization/Teams/ACLs

    组织/团队/ ACL

So, say I need a virtual environment for Node.js, PHP, or Ruby, I can login to Vagrant Cloud, search some shared boxes, and then find one to help me get started with my development environment. Some of these boxes are full-featured and require almost no overhead configuration. This collaboration from community boxes is really cool for small teams who don't have the luxury of full-time Server Admin and Operations people.

因此,说我需要一个用于Node.js,PHP或Ruby的虚拟环境,我可以登录到Vagrant Cloud,搜索一些共享框,然后找到一个可以帮助我开始开发环境的框。 其中一些功能齐全,几乎不需要任何开销配置。 对于那些没有专职服务器管理员和运营人员的小团队来说,社区箱的协作真的很棒。

Vagrant Share is the other huge part of Vagrant Cloud. Vagrant Share lets you easily share your Vagrant Virtual Machine to the web and make it accessible to anyone. So, say you quickly need to share with a client or team member your progress - rather than setting up a full-blown staging environment, you can just run vagrant share to get a temporary URL on vagrantcloud.com.

Vagrant Share是Vagrant Cloud的另一个重要组成部分。 通过Vagrant Share,您可以轻松地将您的Vagrant虚拟机共享到Web,并使任何人都可以访问。 因此,假设您很快需要与客户或团队成员分享您的进度-而不是建立完善的登台环境,您只需运行vagrant share即可在vagrantcloud.com上获取临时URL。

This is neat, but Vagrant actually takes this a a step further. With Vagrant Share you can even share SSH access to your VM with anyone from anywhere in the world! I've heard of some people setting this up while on the same network, but with this, as long as the user is connected to the Vagrant Cloud, it doesn't matter which network they are on. This is super useful for debugging and collaborating. The rest of this tutorial will walk you though how to set this up.

这很干净,但是Vagrant实际上又向前迈了一步。 借助Vagrant Share,您甚至可以与世界各地的任何人共享对VM的SSH访问 ! 我听说有人在同一网络上进行设置,但是有了这个,只要用户连接到Vagrant Cloud,他们在哪个网络上都没有关系。 这对于调试和协作非常有用。 本教程的其余部分将带您逐步了解如何进行设置。

更新无业游民 ( Update Vagrant )

The first thing you need to do is make sure you have the latest Vagrant version installed. I completely uninstalled Vagrant and reinstalled from scratch (including Virtual Box) since it's quick, easy, and clean. Here's the official instructions on uninstalling Vagrant. To uninstall Vagrant on Mac, just run these commands from the terminal:

您需要做的第一件事是确保您安装了最新的Vagrant版本。 我完全卸载了Vagrant,并从头开始重新安装(包括Virtual Box ),因为它既快速,简便又干净。 这是有关卸载Vagrant的官方说明。 要在Mac上卸载Vagrant,只需在终端上运行以下命令:

sudo rm -rf /Applications/Vagrant
sudo rm /usr/bin/vagrant
sudo rm -rf ~/.vagrant.d

Then install Vagrant and reinstall any plugins you use. Here are the ones from my last tutorial so you can continue to use that setup:

然后安装Vagrant ,然后重新安装您使用的所有插件。 这是我上一篇教程中的内容,因此您可以继续使用该设置:

vagrant plugin install vagrant-berkshelf --plugin-version '>= 2.0.1'
vagrant plugin install vagrant-hostmanager
vagrant plugin install vagrant-omnibus

创建一个Vagrant Cloud帐户 ( Create a Vagrant Cloud Account )

The next thing you'll need to do is create a Vagrant Cloud account if you already don't have one. Vagrant Cloud is completely free for basic users (which provides plenty of support). If you need some of the more advanced options, they have some very cheap and reasonable membership prices. Everything we'll be doing is under the free tier, however.

接下来您需要做的就是创建一个Vagrant Cloud帐户(如果您还没有)。 Vagrant Cloud对基本用户完全免费(提供大量支持)。 如果您需要一些更高级的选择,则它们的价格非常便宜且合理。 但是,我们要做的一切都是免费的。

Create a Vagrant Cloud Account

使用Vagrant验证您的Vagrant Cloud帐户 ( Authenticate Your Vagrant Cloud Account with Vagrant )

Now that you have successfully signed up for a Vagrant Cloud account, you'll need to authenticate Vagrant Cloud with your install of Vagrant. From the command line, run the following code :

现在您已经成功注册了Vagrant Cloud帐户,您将需要使用Vagrant安装对Vagrant Cloud进行身份验证。 在命令行中,运行以下代码:

vagrant login

It should prompt you with steps that would look something like this:

它应该提示您一些类似以下的步骤:

Vagrant Login CLI

That's it! You're now authenticated. For whatever reason, if you ever need to logout, you can just run:

而已! 您现在已通过身份验证。 无论出于何种原因,如果您需要注销,都可以运行:

vagrant login --logout
.

创建一个无所事事的环境 ( Create an Environment with Vagrant )

Now that we have our Vagrant Cloud setup, we'll create a virtual environment so we can share it. We're going to be using the exact same LAMP Stack from the last Vagrant tutorial to make things easy. Make sure you have Berkshelf installed if you didn't follow the last tutorial.

现在我们已经有了Vagrant Cloud设置,我们将创建一个虚拟环境以便我们可以共享它。 我们将使用与上一期Vagrant教程完全相同的LAMP Stack ,以简化操作。 如果不遵循上一教程,请确保已安装Berkshelf

git clone git@github.com:MiniCodeMonkey/Vagrant-LAMP-Stack.git vagrant-share-demo
cd vagrant-share-demo
vagrant up
Note: You can name this whatever you want. You can also open up the 注意:您可以随意命名。 您也可以打开 Vagrantfile and name the project something else besides "projectname". Vagrantfile并为项目命名,除了“ projectname”。

After that runs, you can now navigate to http://projectname.local to see your Vagrant LAMP stack is working:

运行之后,您现在可以导航到http://projectname.local以查看您的Vagrant LAMP堆栈正在工作:

Vagrant LAMP Stack

运行共享命令 ( Run the Share Command )

Now that everything is setup, all you need to do is run the vagrant share command:

现在已经完成了所有设置,您所需要做的就是运行vagrant share命令:

vagrant share

It will look something like this:

它看起来像这样:

Vagrant Share

That's all there is to it! Now you can visit the outputted URL and see your VM from any network anywhere in the world. As you start developing your application, it's important that you make sure things like URLs are relative and not absolute.

这里的所有都是它的! 现在,您可以访问输出的URL,并从世界上任何地方的任何网络查看您的VM。 在开始开发应用程序时,重要的是要确保URL之类的内容是相对的而不是绝对的。

Since this works by creating a local tunnel, you can make changes and see them reflected immediately. For example, change some text and visit the URL to see it updated instantly. This is really useful for when you need:

由于这是通过创建本地隧道进行的,因此您可以进行更改并立即看到更改。 例如,更改一些文本并访问URL即可立即看到它的更新。 这在需要时非常有用:

  • Help from a colleague

    同事的帮助
  • Show or demo for a client

    显示或演示客户
  • Debug using a third-party program (e.g.: BrowserStack)

    使用第三方程序进行调试(例如: BrowserStack

The connection will automatically close after about one hour. To close the connection manually, just enter:

大约一小时后,连接将自动关闭。 要手动关闭连接,只需输入:

ctrl c
SSL Support The Vagrant Share utility supports SSL as well. You can do: SSL支持 Vagrant Share实用程序也支持SSL。 您可以执行以下操作: vagrant share --https 443 to get an SSL encrypted URL. vagrant share --https 443以获取SSL加密的URL。

SSH共享 ( SSH Sharing )

HTTP sharing like the example above is great for many reasons, but you can even share SSH access to your VM through Vagrant Cloud. To do this, make sure you terminate the previous share, then enter this command:

像上面的示例一样,HTTP共享之所以很棒,有很多原因,但是您甚至可以通过Vagrant Cloud共享对VM的SSH访问。 为此,请确保终止先前的共享,然后输入以下命令:

vagrant share --ssh

This time when the command runs, you'll be prompted to create a password. After you create your password, Vagrant will actually print the code that you can share to grant SSH access to your VM to someone else. It will look something like this:

这次运行命令时,系统将提示您创建密码。 创建密码后,Vagrant实际上将打印您可以共享的代码,以将对您的VM的SSH访问权限授予其他人。 它看起来像这样:

vagrant connect --ssh terrible-bear-6896

Now, if someone is authenticated with the Vagrant Cloud and runs that command, they'll get full SSH access to your VM. They'll also have to enter the password you created. This can be really useful for debugging and quickly helping someone fix a bug or issue. Collaborating locally just got a whole lot easier. You can terminate the share the same way you did with HTTP Sharing.

现在,如果某人通过Vagrant Cloud进行了身份验证并运行了该命令,他们将获得对您的VM的完全SSH访问权限。 他们还必须输入您创建的密码。 这对于调试并快速帮助某人修复错误或问题非常有用。 在本地进行协作变得非常容易。 您可以使用与HTTP共享相同的方式终止共享。

结论 ( Conclusion )

That's all there is to using Vagrant Share. Some people mimic this or get pretty close to it with local tunnel tools or pseudo DNS tools like:

这就是使用Vagrant Share的全部内容。 有些人使用本地隧道工具或伪DNS工具(例如:

Vagrant Share makes this process easier, seamless, and ultra-fast. It also has the added benefit of allowing people SSH access to a VM from anywhere in the world.

Vagrant Share使此​​过程更加轻松,无缝和超快。 它还具有允许人们通过SSH从世界任何地方访问VM的额外好处。

I really enjoy using Vagrant, and it has made my development much more efficient. I imagine as Vagrant Cloud grows, they'll start managing deployment for users, too. So from Vagrant Cloud you can Share temporary links, one-click provision to Digital Ocean or Amazon, and more. I may be wrong, but I really can see them growing Vagrant Cloud to manage servers similar to Larvel's Forge tool does.

我真的很喜欢使用Vagrant,它使我的开发效率更高。 我想随着Vagrant Cloud的发展,他们也将开始为用户管理部署。 因此,从Vagrant Cloud中,您可以共享临时链接,到Digital Ocean或Amazon的一键式配置等等。 我可能是错的,但我确实可以看到他们正在扩大Vagrant Cloud来管理类似于Larvel的Forge工具的服务器。

翻译自: https://scotch.io/tutorials/sharing-your-virtual-machine-on-the-web-with-vagrant-share

vagrant虚拟机

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值