使用PuPHPet轻松构建虚拟机

Does creating and managing development environments frustrate you, slow you down, or distract you from development? Do you have issues because your development and deployed environments differ? If so, I've got the solution for you – PuPHPet!

创建和管理开发环境是否会使您沮丧,减慢速度或使您无法进行开发? 您是否因为开发环境和部署环境不同而遇到问题? 如果是这样,我为您找到了解决方案-PuPHPet!

介绍 (Introduction)

I can't speak for you, but one of my pet peeves about software development is environments. Whether it's creating and maintaining them for different projects with different needs; ensuring environment parity across a development team, (especially when they're remote); or between environments such as development, testing, and production. Across all of these, it can be a laborious task, especially when done manually.

我不能为您说话,但是我对软件开发的烦恼之一就是环境。 是否为具有不同需求的不同项目创建和维护它们; 确保整个开发团队的环境均等(尤其是在他们处于远程状态时); 或在开发,测试和生产等环境之间。 在所有这些方面,这可能是一项艰巨的任务,尤其是在手动完成时。

As we all know, the amount of options, the variety of choice, the demands of the IT manager, team lead, or client can be stressful. They can (and do) pull us in a multitude of directions, oftentimes simultaneously.

众所周知,选择的数量,选择的多样性,IT经理,团队负责人或客户的需求可能会让人感到压力重重。 他们可以(并且确实)经常向多个方向拉我们。

There's database choices such as MySQL, PostgreSQL, Oracle and SQLServer. There's NoSQL choices such as Cassandra, Hadoop, and Redis. There's webserver choices such as Apache and Nginx. The list goes on and on.

有数据库选择,例如MySQLPostgreSQLOracleSQLServer 。 有NoSQL选项,例如CassandraHadoopRedis 。 有Web服务器选择,例如ApacheNginx 。 清单不胜枚举。

And when we don't have a dedicated sys admin team (say we're a solo freelancer or in a very small team), time taken to maintain development environments becomes really precious – we become DEVOPS.

而且,当我们没有专门的sys管理员团队时(例如我们是一个自由职业者,或者是一个非常小的团队),维护开发环境所花费的时间就变得非常宝贵–我们成为DEVOPS。

In pursuit of ending this pain and making the entire process as efficient as possible, I set about the task of learning Vagrant & Puppet. From discussions with colleagues and internet research, these two tools seem to be the standard for creating reusable environments. If you're not familiar with these excellent tools, here are two short excerpts from their respective manuals:

为了结束这种痛苦并使整个过程尽可能高效,我着手学习VagrantPuppet的任务。 从与同事的讨论和互联网研究来看,这两个工具似乎是创建可重用环境标准。 如果您不熟悉这些出色的工具,请参考以下两个简短摘录:

Vagrant:

流浪汉:

Create and configure lightweight, reproducible, and portable development environments. Vagrant will change how you work

创建和配置轻量级,可复制且可移植的开发环境。 流浪汉将改变你的工作方式

Puppet:

木偶:

Puppet is IT automation software that helps system administrators manage infrastructure throughout its lifecycle, from provisioning and configuration to orchestration and reporting. Using Puppet, you can easily automate repetitive tasks, quickly deploy critical applications, and proactively manage change, scaling from 10s of servers to 1000s, on-premise or in the cloud.

Puppet是IT自动化软件,可帮助系统管理员在整个生命周期(从供应和配置到编排和报告)中管理基础架构。 使用Puppet,您可以轻松地自动执行重复性任务,快速部署关键应用程序并主动管理更改(从10台服务器扩展到1000台),无论是在本地还是在云中。

However, like most people in the modern world, I'm impatient. Like you, I have a lot going on, plus I was not seeking to become a guru. I felt there must be a way to come up to speed quickly but without becoming an aficionado.

但是,像现代世界中的大多数人一样,我很不耐烦。 像您一样,我有很多事情要做,而且我并不想成为一名大师。 我觉得必须有一种方法可以加快速度,但又不能成为狂热者。

输入PuPHPet (Enter PuPHPet)

After some further googling, I came across the subject of this article, PuPHPet, an excellent GUI tool providing a simple wizard, which creates a Puppet-powered Vagrant configuration, usable immediately.

经过进一步的搜索之后,我遇到了本文的主题PuPHPet ,这是一个出色的GUI工具,提供了一个简单的向导,它创建了由Puppet驱动的Vagrant配置, 可以立即使用

Originally started a few short months ago by Juan Treminio, PuPHPet makes creating environments perfectly tailored for PHP developers on stacks such as {W,M,L}AMP dead simple.

PuPHPet最初是由Juan Treminio于几个月前开始创建的, 使在{W,M,L} AMP之类的堆栈上为PHP开发人员量身打造完美的环境变得非常简单。

It focuses on 5 areas:

它专注于5个领域:

  • Deploy Target (memory, ip address, port forwarding)

    部署目标(内存,IP地址,端口转发)
  • Server Basics

    服务器基础
  • PHP (modules, libraries, config settings)

    PHP(模块,库,配置设置)
  • Database (PostgreSQL, MySQL)

    数据库(PostgreSQL,MySQL)
  • Webserver (Apache 2, Nginx)

    网络服务器(Apache 2,Nginx)

Whether you want to have PHP 5.5 running PostgreSQL and Nginx or PHP 5.4 running Apache 2 and MySQL, you can rapidly create and download the configuration, getting going in minutes.

无论您是要运行PostgreSQL和NginxPHP 5.5,还是要运行Apache 2和MySQLPHP​​ 5.4,都可以在几分钟之内快速创建和下载配置。

Admittedly, there's a lot more to an environment than these choices; but, to be fair, it's early days and what it already provides, it does really well.

诚然,除了这些选择外,环境还有很多。 但是,公平地说,现在还处于初期阶段,并且已经提供了它,它确实做得很好。

With PuPHPet, you'll be up and running inside a half hour, and all you have to do is run:

使用PuPHPet,您将在半小时内启动并运行,而您所要做的就是运行:

vagrant up

That's right. In the uncompressed PuPHPet archive, you need only run that command, wait a bit, and you're ready to go. Don't believe me? Let's step through the process from start to finish together.

那就对了。 在未压缩的PuPHPet归档文件中,只需运行该命令,稍等片刻,就可以开始了。 不相信我吗 让我们一起从头到尾逐步完成整个过程。

After we're done, I wholeheartedly encourage you to play to your hearts content, changing options, adding removing packages and more and see what you find. I'm confident you'll be impressed.

完成之后,我全心全意地鼓励您发挥自己的心意,更改选项,添加删除程序包等等,然后看看您发现了什么。 我相信您会留下深刻的印象。

必备软件 (Required Software)

A word of warning before we start. One of the biggest problems I faced when I first started was having the right versions of both Vagrant and VirtualBox. It appeared as though I'd only get part way and have to do the rest manually. It was never clear what had gone wrong or how complete the process was.

在我们开始之前要提个警告。 我刚开始时遇到的最大问题之一是拥有正确版本的Vagrant和VirtualBox。 看来,我只会得到部分帮助,而必须手动完成其余的工作。 目前还不清楚什么地方出了问题或该过程的完成程度。

So if you're finding things aren't working, try different versions of both packages. I'm currently running Vagrant 1.3.5 and VirtualBox 4.3.2 and they've worked flawlessly every time.

因此,如果您发现事情不正常,请尝试使用两个软件包的不同版本。 我目前正在运行Vagrant 1.3.5VirtualBox 4.3.2 ,它们每次都可以完美工作。

Firstly, install a copy of these two packages.

首先,安装这两个软件包的副本。

创建配置 (Creating the Configuration)

With them installed, open up https://puphpet.com. You can see, right at the top, that there are four initial choices: Local, Digital Ocean, Rackspace and Amazon Web Services. Choose Local as we're not using these online services in this tutorial.

安装它们后,打开 https://puphpet.com 。 您可以在顶部看到四个初始选择: LocalDigital OceanRackspaceAmazon Web Services 。 选择本机,因为我们在本教程中不使用这些在线服务。

Under "Local VM Details", we can specify the VM's: – Operating System – Hostname – IP Address – Memory Allocation

在“本地VM详细信息”下,我们可以指定VM的:–操作系统–主机名– IP地址–内存分配

For today's example, we're using Debian Wheezy 7.2 x64 with VirtualBox 4.3. This allows us to use PHP 5.5 or 5.4. Feel free to leave the remaining three settings as they are, or adjust as suits you best.

对于今天的示例,我们将Debian Wheezy 7.2 x64与VirtualBox 4.3一起使用 。 这使我们可以使用PHP 5.5或5.4。 随意保留其余三个设置,或根据自己的需要进行调整。

Next comes Local VM Forwarded Ports. I've not configured it, but if you want to setup some ports on your host machine to forward to ports on the guest VM, then configure them here, as necessary.

接下来是本地VM转发端口 。 我尚未对其进行配置,但是如果您要在主机上设置一些端口以转发到来宾VM上的端口,则可以根据需要在此处进行配置。

alt

与本地VM共享文件夹 (Sharing Folders with Local VM)

Here we begin to see the power and flexibility that Vagrant and Puppet provide. In Box Sync Folder Source you specify a local directory which will map to a directory on the guest VM at the location specified by Box Sync Folder Target. I've left the defaults for both of these and also for Shared Folder Type.

在这里,我们开始看到Vagrant和Puppet提供的功能和灵活性。 在Box Sync Folder Source中 ,指定一个本地目录,该目录将映射到Guest VM上Box Sync Folder Target指定的位置上的目录。 我为这两个以及共享文件夹类型都保留了默认值。

This option is handy if you want to set up a number of custom directories on your VM. Say you have an existing working copy under ~/Documents/workspace/your-project. You could map this to a directory directly in the web root of your VM's web server. That way you can develop locally, with no syncing or copying requirements to the virtual machine.

如果要在VM上设置许多自定义目录,此选项非常方便。 假设您在~/Documents/workspace/your-project下有一个现有的工作副本。 您可以将此映射直接映射到VM Web服务器的Web根目录中。 这样,您可以在本地进行开发,而无需同步或复制到虚拟机。

alt

服务器基础 (Server Basics)

If there are specific packages that you need available, such as git, subversion, vim, etc, then list them here. One thing to remember, is you need to know the package name as specified in your chosen operating system. No list is provided in the popup when you type.

如果有您需要的特定软件包,例如gitsubversionvim等,请在此处列出。 要记住的一件事是,您需要知道所选操作系统中指定的软件包名称。 键入时,弹出窗口中没有提供列表。

alt

网络服务器 (Webserver)

Apache(2) or Nginx? For this tutorial, I'm going with Apache. The configuration choices are simple and straight-forward. First specify the modules to be installed and enabled by typing in the Apache Modules field. This will popup a list of available options for you to choose from – helping ensure an error free process.

Apache(2)还是Nginx? 对于本教程,我将使用Apache。 配置选择简单明了。 首先,通过在Apache Modules字段中输入指定要安装和启用的模块。 这将弹出一个可用选项的列表供您选择-帮助确保无错误的过程。

Next comes the Virtual Host configuration. What is the server name and alias of your application? First specify them, then the root directory and port. What we'll do is set the same directory for the Document Root as we specified in Box Sync Folder Target, to keep things nice and simple. Unless you have a specific need, leave the port at the default 80.

接下来是虚拟主机配置。 您的应用程序的服务器名称和别名是什么? 首先指定它们,然后指定根目录和端口。 我们要做的是为Box Root Folder Target中指定的文档根目录设置相同的目录,以使事情变得简单明了。 除非有特殊需要,否则请保留默认端口80。

The final two settings, Environment Variables and AllowOverride, only change if your application needs it. For today, the defaults are fine.

最后两个设置( 环境变量AllowOverride )仅在您的应用程序需要时更改。 对于今天,默认值很好。

alt

PHP (PHP)

Only a few options are available here, but they're good enough for what we need. I've left the default of PHP 5.5 (why would you want anything else?). I've also left Composer selected. If you've not used Composer, or are not sure what all the fuss is about, read this excellent post by Ben Ramsey, or this post on Composer here on SitePoint.

这里只有几个选项可用,但它们足以满足我们的需求。 我保留了PHP 5.5的默认设置(为什么还要其他功能?)。 我还选择了Composer。 如果您没有使用过Composer,或者不确定引起什么大惊小怪,请阅读Ben Ramsey撰写的出色文章 ,或在SitePoint 上的Composer上阅读此文章

Under INI Settings, I've accepted the defaults and then added in allow_url_fopen, allow_url_include, error_log, file_uploads, and apc.enabled. Feel free to do the same, or browse and choose from the extensive list.

INI设置下 ,我接受了默认值,然后将其添加到allow_url_fopenallow_url_includeerror_logfile_uploadsapc.enabled中 。 随意进行相同操作,或浏览并从广泛的列表中进行选择。

I've changed my PHP Timezone to Europe/Berlin as that's the closest to me. But change yours as best suits your location. For PHP Modules, my list is cli, intl, mcrypt, cgi, curl, memcached, memcache, pspell, tidy and sqlite. Scroll through the list and add the ones that you need (or would like). For PEAR and Pecl modules, I've left these as they were.

我已将PHP时区更改为Europe / Berlin,因为它离我最近。 但是请更改您的位置,以最适合您的位置。 对于PHP模块,我的列表是cliintlmcryptcgicurlmemcachedmemcachepspelltidysqlite 。 滚动浏览列表,然后添加您需要(或想要)的列表。 对于PEARPecl模块,我将它们保持原样。

I've elected to install Xdebug, taking the default settings, but not Xhprof. XDebug is just excellent, so I highly recommend you use it.

我选择使用默认设置安装Xdebug,但不选择Xhprof。 XDebug非常出色,因此我强烈建议您使用它。

alt

数据库 (Database)

Ok, we're getting serious now. For today's example, I've chosen MySQL, setting the root password to password and left privileges at all. The DB name is sitepoint, the username is testuser and the password, testpassword. I've kept the choices here simple, so as not to overcomplicate the situation. I don't have a SQL script to run on VM load, so have left this blank.

好吧,我们现在变得认真了。 对于今天的示例,我选择了MySQL,将root密码设置为password并完全保留了特权。 数据库名称是sitepoint ,用户名是testuser ,密码是testpassword 。 我将此处的选择保持简单,以免使情况复杂化。 我没有在虚拟机负载下运行SQL脚本,因此将其留空。

alt

创建并下载配置 (Create & Download the Config)

alt

Now, just click the extremely large button Go ahead then, make it. You'll see the download appear in your downloads directory. After it's finished, extract the archive and cd into the directory in your terminal. From there, run vagrant up.

现在,只需点击非常大按钮继续前进的话,做出来 。 您会看到下载出现在您的下载目录中。 完成后,将归档文件和cd解压缩到终端的目录中。 从那里开始vagrant up

This begins the process of building the VM. If you've not downloaded a Box file yet or don't have one matching the operating system you've specified, you'll have to wait a bit longer as it's downloaded, before the VM can be built. All being well, you'll see output like the following:

这开始构建虚拟机的过程。 如果尚未下载Box文件,或者没有与您指定的操作系统匹配的文件,则在构建VM之前,必须等待更长的时间下载文件。 一切都很好,您将看到类似以下的输出:

✗ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'debian-wheezy72-x64-vbox43'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Running 'pre-boot' VM customizations...
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant
[default] -- /var/www
[default] -- /tmp/vagrant-puppet/manifests
[default] Running provisioner: shell...
[default] Running: /var/folders/_w/k6fxbl615w700lgkrtt0vb3w0000gn/T/vagrant-shell20131126-3538-kid3ga
stdin: is not a tty

 ____        ____  _   _ ____      _      generated using
|  _ \ _   _|  _ \| | | |  _ \ ___| |_   ___ ___  _ __ ___
| |_) | | | | |_) | |_| | |_) / _ \ __| / __/ _ \| '_ ` _ \
|  __/| |_| |  __/|  _  |  __/  __/ |_ | (_| (_) | | | | | |
|_|    \__,_|_|   |_| |_|_|   \___|\__(_)___\___/|_| |_| |_|

Created directory /.puphpet-stuff
Running initial-setup apt-get update
Finished running initial-setup apt-get update
[default] Running provisioner: shell...
[default] Running: /var/folders/_w/k6fxbl615w700lgkrtt0vb3w0000gn/T/vagrant-shell20131126-3538-1116fzj
stdin: is not a tty
Downloading http://apt.puppetlabs.com/puppetlabs-release-wheezy.deb
Finished downloading http://apt.puppetlabs.com/puppetlabs-release-wheezy.deb
Running update-puppet apt-get update
Finished running update-puppet apt-get update
Updating Puppet to latest version
dpkg-preconfigure: unable to re-open stdin: No such file or directory
Finished updating puppet to latest version: Puppet v3.3.2
Created empty file /.puphpet-stuff/update-puppet
...
Info: Creating state file /var/lib/puppet/state/state.yaml
Notice: Finished catalog run in 436.21 seconds

This indicates that everything has gone well.

这表明一切进展顺利。

检查一切正常 (Check Everything's Working)

Now that the Virtual Machine's built, login and check it out. To do that, from the same directory, run vagrant ssh. Once you're in, to quickly validate all's ok, run sudo netstat -tlnp. This shows what services are running. It should give you output matching the following

既然已经构建了虚拟机,请登录并签出。 为此,请从同一目录运行vagrant ssh 。 进入后,要快速验证一切正常,请运行sudo netstat -tlnp 。 这显示了正在运行的服务。 它应该给您输出匹配以下内容

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1643/rpcbind    
tcp        0      0 0.0.0.0:39284           0.0.0.0:*               LISTEN      1678/rpc.statd  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2643/sshd       
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      13637/postgres  
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2399/exim4      
tcp6       0      0 :::111                  :::*                    LISTEN      1643/rpcbind    
tcp6       0      0 :::80                   :::*                    LISTEN      31623/apache2   
tcp6       0      0 :::22                   :::*                    LISTEN      2643/sshd       
tcp6       0      0 ::1:5432                :::*                    LISTEN      13637/postgres  
tcp6       0      0 ::1:25                  :::*                    LISTEN      2399/exim4      
tcp6       0      0 :::37887                :::*                    LISTEN      1678/rpc.statd

There you see that Apache and PostgreSQL are running. If you look under /etc/apache2/sites-enabled/ you'll see a configuration for your virtual host, using a pseudo-random name. If you've added the hostname to /etc/hosts on your local machine, then you can open up the hostname in your browser and view the page that results.

在那里,您可以看到Apache和PostgreSQL正在运行。 如果您在/etc/apache2/sites-enabled/查看,您将看到使用伪随机名称的虚拟主机配置。 如果已将主机名添加到本地计算机上的/etc/hosts ,则可以在浏览器中打开主机名并查看结果页面。

我们做完了! (We're Done!)

So there you have it. Ok, the first time through, like anything, it might seem like a lot of steps to perform. But as you become more familiar, you'll get a lot faster. What's more, you don't need to recreate from scratch every time.

所以你有它。 好的,第一次像任何事情一样,似乎要执行很多步骤。 但是,随着您变得越来越熟悉,您会变得更快。 而且,您不需要每次都从头开始重新创建。

If you drag puppet/hieradata/common.yaml onto puphpet.com, it will automatically fill out the form to match the configuration contained. Then just adjust to match you needs. So once you've done the first one, subsequent ones are much quicker and easier.

如果将puppet/hieradata/common.yaml拖到puphpet.com上,它将自动填写表格以匹配其中包含的配置。 然后根据您的需要进行调整。 因此,一旦您完成了第一个操作,后续操作就会变得更快,更容易。

有什么想法吗? (Thoughts?)

What do you think? Are you keen to use it, and leave the days of building Virtual Machines by hand behind? Share your thoughts in the comments.

你怎么看? 您是否热衷于使用它,而忘记了手动构建虚拟机的日子? 在评论区分享你的观点。

翻译自: https://www.sitepoint.com/build-virtual-machines-easily-puphpet/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值