共享和自动化的vagrant box
我正在考虑使用 Vagrant 来开发 Django 应用程序,但我有点困惑,我不确定我想做的是否可能。
我成功安装了 lucid32 盒子,并创建了一个新的 vagrant “实例”,其中包含 Vagrantfile、一些共享目录和转发端口。
第一个问题是,在我看来,这并不是团队合作的最佳选择。我们(例如,我和其他 10 位开发人员)如何共享该盒子,以便共享它的每项更改?例如,如果在 6 个月内我们需要 postgresql,我需要让它正常工作,而不必安装 postgresql 11 次。
另外,我怎样才能让东西(如:postgresql、django、this-service 等)在盒子启动时启动?我不认为我必须通过 ssh 来启动它并手动启动
n
次我每次需要的所有n
东西。最后:我不太明白像 puppet 和 Chef 这样的东西是否意味着完全替代手动安装(例如通过 pip 或 apt-get)。是这样吗?
谢谢。
我很抱歉英语不好。 :-)
I'm thinking of using Vagrant to develop Django applications, but I'm a little confused and I'm not sure if what I would like to do is even possible.
I installed the lucid32 box successfully and created a new "instance" of vagrant, with a Vagrantfile, some shared directories and forwarded ports.
The first issue is that this doesn't seem to me the best choice when working in a team. How can we (me and other 10 developers, for example) share the box so that every change to it is shared? For example, if in 6 months we need postgresql, I need to have it working without having to install postgresql 11 times.
Also, how can I make things (like: postgresql, django, this-service, etc.) to start when the box has started up? I don't think that I have to ssh it and manually start
n
times all then
things I need every time.And finally: I don't understand well if things like puppet and chef are meant to completely substitute the manual installation (through pip or apt-get, for example). Is that so?
Thank you.
And I'm sorry for bad english. :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说,您选择的 Vagrant 已经是您所寻找的一个良好的开始,但现在您需要更深入地了解 Chef 或 Puppet,以进一步自动化您的配置过程。
我想在您的场景中,一个不错的选择是首先将 Vagrantfile 和相应的 Puppet 清单置于版本控制之下,作为项目的一部分。此外,与该机器相关的所有配置也应纳入版本控制和/或通过某种工件存储库提供。
其次,在团队中建立规则,如果认为环境变化(至少是那些应该持续更长时间的变化)需要被检查,如果它们被认为已为其他团队成员做好了准备。
关于你的第二个问题,回到我的开场白:Puppet(我喜欢)或 Chef 是你选择的工具,可以在未来为你和你的同事节省大量工作。我在这里坚持使用 Puppet,因为我不太了解 Chef。
使用 puppet,您可以管理您想要的所有内容,包的安装、更改配置并确保某些服务正在运行,或者一般来说系统具有您想要的状态。更好的是,如果您或其他团队成员对他/她的盒子进行了一些恶意更改,您只需回滚 Vagrantfile/Puppet 清单中的更改,输入内容
即可轻松将盒子恢复到最后的版本控制状态。
例如,采用以下清单文件:
它的作用是,首先检查您机器中操作系统的软件包机制(示例中的名称假定为最新的 Ubuntu),如果软件包“mysql-server-5.1”是已安装,如果没有,它将安装它。通过“require”属性,第二个指令将在第一个指令之后执行(并且仅当它有效时),将 MySQL 配置更改为您也已签入和/或在您可以访问的地方发布的配置(也可以是放入与 Vagrantfile 相同的文件夹中,然后将在 /vagrant 下的框中可用)。最后一步,只有在配置更改有效时才会执行,这将确保“mysql”服务启动并运行,或者如果配置更改时它已经在运行,则重新启动。
现在你可以在你的 Vagrantfile 中连接这个清单:
除了对这样的环境进行“尝试”之外的所有更改,所有团队成员都可以保证轻松地拥有相同的设置,并且可以在他们的指尖进行复制。
我个人喜欢手动尝试现成的东西,当我找到正确的设置和配置时,将其转换为 Puppet 清单,以便以后使用并与团队成员共享。
由于 Puppet(还有 Chef)可以管理几乎所有您需要的内容(用户、cron 作业、程序包、服务、文件……),因此它是解决此类问题的不错选择,并且您甚至可以使用如果您选择的话,可以稍后配置临时或测试环境。 Puppet 有更多选择,通读语言指南应该会给你一个好主意你还可以用它做些什么。
希望我能帮忙:)
I would say that your choice of Vagrant already was a good start to what you are looking for, but now you need to dig a little deeper into either Chef or Puppet, to further automate your provisioning process.
I guess a good choice in your sceneraio would be to first put both, the Vagrantfile and the corresponding Puppet manifest under version control as part of your project. Additionally, all of the configurations concerning this machine should also be put into version control and/or be made available through some sort of artifact repository.
Second, establish the rule in the team that changes (at least these that should live on for longer) to the environment need to be checked in if they are considered ready for the other team members.
Concerning your second question and coming back to my opening: Puppet (which I like) or Chef are your tools of choice and can save you and your colleagues a lot of work in the future. I'll stick to Puppet here, as I don't know Chef too good.
With puppet, you can manage all of what you want, the installation of packages, changing configurations and ensuring that certain services are running, or in general that the system has the state you want it to be. Even better, if you or another team-member made some malicious chages to his/her box, you can just rollback the changes in your Vagrantfile/Puppet manifest, type in
and the box is easily taken back to the last versioned state.
For example, take the following manifest file:
What this does is, it first of all checks the package mechanism of the OS in your box (the names in the example assume a recent Ubuntu) if the package "mysql-server-5.1" is installed, and if not it'll install it. Through the 'require' attribute, the second directive will be executed after the first (and only if it worked), changing the MySQL configuration to the one you have also checked in and/or published somewhere you can reach it (that could also be put into the same folder as the Vagrantfile, and will then be available in the box under /vagrant). The last step, which again only will be executed if the altering of the configuration worked, will ensure that the "mysql" service is up and running or is getting restarted if it already was running when the configuration was changed.
Now you can hook up this manifest in your Vagrantfile:
With all changes besides the 'trying-stuff-out' ones made to the environment like this, all team mebers are guaranted to have the same setup easily and reproducable just at their fingertips.
I personally like to try stuff out on the box by hand, and when I found the right setup and configuration, translate it into a Puppet manifest to have if ready for later use and sharing with team members.
As Puppet (and Chef also) can manage almost all you need (users, cron jobs, packages, services, files, ...) it is a good choice for exactly such problems, and you have the benefit to even be able to use the configurations to provision staging or testing environments later on if you choose to. Their are much more options with Puppet, and a read through the language guide should give you a good idea what more you can do with it.
Hope I could help :)