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

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

问题描述

我想在一个VPS上开发和部署一个Erlang / OTP应用程序。



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



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



注意:我已经阅读了一些关于 Erlang和命令行,Erlang 代码模块,Erlang 发布,但我还是不知道如何追求所需的任务。



但是,我猜在服务器上部署基于Erlang的软件比使用code> sudo ta sksel for LAMP



我打算有一个Erlang / OTP应用程序,它具有Mochiweb,CouchDB( couchbeam )和 boss_db 作为依赖关系。 p>

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



我计划使用Ubuntu Server 12.04;是否有更好的选择,Linux发行版用于生产中的Erlang / OTP?
  • 应该如何组织所有的代码?我应该把我的应用程序放在/ home / myapp / dir中,然后将所有依赖项放到/ home / myapp / deps中?还是应该把所有依赖项放到/ usr / local / lib / erlang / lib中? (由代码get_path()返回)。我应该定期更新依赖项还是应该冻结它们?

  • 服务器启动后如何启动整个应用程序?应该是某种bash脚本还是别的什么?

  • 我知道Erlang允许热代码升级,但应该如何组织?在Rails上,我可以更新代码使用git ,在Erlang世界中还有类似的东西吗?


  • 解决方案

    有两种依赖关系:内部和外部。如果你想做的正确的方式(tm),需要一些时间上班:



    外部依赖:



    首先,后一个外部依赖是在应用程序运行之前必须运行的其他一些事情。例如PostgreSQL数据库或Riak集群。对于那些,你通常只是使用Ubuntu中的通常的东西使它正常启动。对于这些任务,我使用 monit 的经验很好。



    http://mmonit.com/monit/



    内部依赖关系:



    对于内部依赖关系,您需要将程序安排到Erlang VM内的应用程序中。它们彼此依赖,如外部依赖。例如,您的主要应用程序可能需要在开始之前运行记录器。然后创建一个版本。一个版本将Erlang二进制文件和必要的库/ beam /应用程序复制到发行目录中,形成一个独立的Erlang系统。它包含一个启动脚本,它告诉如何以正确的顺序启动应用程序并保持它们的运行。所以你可以打压这个版本,将其复制到服务器,然后启动它。这里有一些基础知识:



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



    ,但也请阅读应用程序之前的章节。您还可以获得 rebar 以调用 reltool 来构建发行版。这是我通常做的。



    热门升级:



    在生产中处理热升级可以在几种方式。您可以将光束移动到机器上,然后将其部署,取出外壳,然后调用 l(Module)将其加载到正在运行的系统中。这适用于较小的修复。对于大型系统升级,您可以执行版本升级,这样可以在不停止服务的情况下即时升级运行的系统。但是如果你的系统大部分没有共享,那通常是不值得的。相反,您可以有多台机器并按顺序升级。



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


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

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

    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.

    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.

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

    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:

    • 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?

    解决方案

    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:

    External dependencies:

    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/

    Internal Dependencies:

    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

    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.

    Hot upgrades:

    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.

    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天全站免登陆