Erlang/OTP 生产应用部署介绍 [英] Introduction to Erlang/OTP production applications deployment

查看:28
本文介绍了Erlang/OTP 生产应用部署介绍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 VPS 上开发一个 Erlang/OTP 应用程序并将其部署到生产环境中.

I would like to develop and deploy an Erlang/OTP application into production on a VPS.

我非常熟悉在本地机器上开发 Erlang 代码,我的问题是关于部署.

I am pretty familiar with developing Erlang code on a local machine and my question is about deployment.

基本上,我想知道我应该采取哪些步骤才能将 Erlang 代码从本地机器移动到生产服务器并使其运行,即可供用户使用.

Basically, I would like to know what steps I should take in order to move Erlang code from a local machine to a production server and make it run, i.e. be available for users.

注意:我已经阅读了一些关于 Erlang 和命令行、Erlang code 模块,Erlang 发布,但我仍然不确定如何执行所需的任务.

Note: I have read some documentation about Erlang and command line, Erlang code module, Erlang releases, but I am still not sure how to pursue the required task.

然而,我想在服务器上部署基于 Erlang 的软件比为 LAMP.

However, I guess that deploying an Erlang-based software on a server is a bit more tricky than doing sudo tasksel for LAMP.

我计划有一个 Erlang/OTP 应用程序,其中包含 Mochiweb、CouchDB (couchbeam) 和 boss_db 作为依赖项.

I plan to have an Erlang/OTP application which has Mochiweb, CouchDB (couchbeam) and boss_db as dependencies.

所以,我的新手关于在生产服务器上部署所有这些东西的问题如下:

So, my newbie questions about deploying all that stuff on a production server are the following:

  • 我打算使用 Ubuntu Server 12.04;Linux 发行版有没有更好的选择可以在生产中用于 Erlang/OTP?
  • 应该如何组织所有代码?我应该将我的应用程序放入/home/myapp/目录,然后将所有依赖项放入/home/myapp/deps 吗?或者我应该将所有依赖项放入/usr/local/lib/erlang/lib 中?(由代码返回:get_path()).我应该以某种方式定期更新依赖项还是应该冻结它们?
  • 如何在服务器启动后启动整个应用程序?它应该是某种 bash 脚本还是其他任何东西?
  • 我知道 Erlang 允许热代码升级,但我应该如何组织它?在 Rails 上,我可以更新代码使用 git,在 Erlang 世界中是否存在类似的东西?
  • I plan to use Ubuntu Server 12.04; is there any better choice for a Linux distro to use for Erlang/OTP in production?
  • How all the code should be organized? Should I put my application into a /home/myapp/ dir and then put all the dependencies into /home/myapp/deps? Or should I put all dependencies into /usr/local/lib/erlang/lib? (returned by code:get_path()). Should I somehow update the dependencies regularly or should I freeze them?
  • How do I make the whole application start once the server starts? Should it be some kind of bash script or anything else?
  • I know that Erlang allows hot code upgrades, but how should I organize that? On Rails I could update the code with git, does anything similar exist in the Erlang world?

推荐答案

依赖有两种类型:内部和外部.如果你想以正确的方式去做(tm),它需要一些时间开始工作:

There are two types of dependencies: Internal and External. If you want to do it the right way(tm), it takes a bit of time getting to work:

首先考虑后者,外部依赖项是在您的应用程序运行之前必须运行的其他一些东西.例如 PostgreSQL 数据库或 Riak 集群.对于那些,您通常只使用 Ubuntu 中的常用东西来使其正常启动.我在使用 monit 完成这些任务方面有很好的经验:

Taking the latter first, an external dependency is some other thing that has to run before your application can run. For instance a PostgreSQL database, or a Riak cluster. For those, you usually just use the usual stuff in Ubuntu for making it start up properly. I've had good experience with using monit for these tasks:

http://mmonit.com/monit/

对于内部依赖项,您需要将您的程序安排到Erlang VM内的应用程序中.它们相互依赖,就像外部依赖一样.例如,您的主应用程序可能需要在它启动之前运行一个记录器.然后你创建一个发布.release 将 Erlang 二进制文件和必要的库/梁/应用程序复制到发布目录中,形成一个自包含的 Erlang 系统.它包含一个启动脚本,它告诉如何以正确的顺序启动应用程序并保持它们运行.因此,您可以将此版本打包,将其复制到服务器,然后启动它.这里涵盖了一些基础知识:

For internal dependencies, you need to arrange your program into applications inside the Erlang VM. These have dependencies on each other, like the external dependencies. Your main application may need a logger running before it should start, for instance. Then you create a release. A release copies the Erlang binaries and necessary libraries/beams/applications into a release directory, forming a self-contained Erlang system. It contains a boot-script which tells how to start up the applications in the right order and keep them running. So you can tar-ball up this release, copy it to the server and then start it. There are some basics covered here:

http://learnyousomeerlang.com/release-is-the-word

但也请阅读之前有关应用程序的章节.你也可以让 rebar 调用 reltool 为你构建一个版本.这是我通常做的.

but do also read the chapters before it on applications. You can also get rebar to call reltool for you to build a release. This is what I usually do.

可以通过多种方式处理生产中的热升级.你可以将beam移动到机器上然后部署它,取shell然后调用l(Module)将它加载到正在运行的系统中.这适用于较小的修复.对于大型系统升级,您可以进行发布升级,这将在不停止服务的情况下即时升级正在运行的系统.但是,如果您的系统大多不共享,则通常不值得.相反,您可以拥有多台机器并依次升级.

Handling hot upgrades in production can be done in a couple of ways. You can move the beam to the machine and then deploy it, take the shell and then call l(Module) to load it into the running system. This works for smaller fixes. For large systematic upgrades you can do a release-upgrade which will upgrade the running system on the fly without stopping service. But if your system is mostly shared nothing, it is usually not worth it. Instead, you can have multiple machines and upgrade them in sequence.

例如,您可以升级一台机器,然后使用像 HAProxy 这样的系统将所有请求的 2% 发送到新系统.然后系统地调高请求负载权重.

For instance, you can upgrade a machine and then use a system like HAProxy to send 2% of all requests to the new system. Then systematically turn up the request load weight.

这篇关于Erlang/OTP 生产应用部署介绍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆