您的位置:首页 > 运维架构 > Linux

在Mac下面使用rebar3制作应用,发布到CentOS7

2017-08-08 00:00 316 查看
摘要: 在生产环境下,你可以创建一个product的profile,里面定义 {include_erts, true} ,这样执行 rebar3 as product release 时,ERTS会被拷贝到发布文件夹中,在服务器上部署不需要安装Erlang。

在Mac下面使用rebar3制作应用,发布到CentOS7

在生产环境下,你可以创建一个product的profile,里面定义 {include_erts, true} ,这样执行 rebar3 as product release 时,ERTS会被拷贝到发布文件夹中,在服务器上部署不需要安装Erlang。

其他环节可以如法炮制。

安装rebar3,初始化项目

brew rebar3

cd ~/workspace/erl/
rebar3 new release es_client && cd es_client

or

cd ~/workspace/erl/

wget https://s3.amazonaws.com/rebar3/rebar3 && chmod +x rebar3

rebar3 new release es_client && cd es_client
mv ../rebar3 ./

项目开发若干过程

% 编译
./rebar3 clean && ./rebar3 compile

% 启动 开发环境
erl -boot start_sasl -pa _build/default/lib/*/ebin -config config/sys.config

% 测试
./rebar3 eunit

% 生成文档
./rebar3 edoc

发布之前准备工作

在一个CentOS7的虚拟机上面源码安装erlang(我这里的版本是 Erlang/OTP 20.0)

我的CentOS7虚拟机上面源码安装好的 erlang_otp20.0_for_centos7.tar.gz下载地址

Erlang/OTP 20.0 源码是在官方网站下载的

Erlang/OTP 20.0 源码安装参考

配置rebar.config

重点内容如下,其他配置更加需求自己调整

{profiles, [
{ prod, [
{relx, [
{dev_mode, false},
{include_erts, true}
]}
]},
{'centos-7', [
{relx, [
{dev_mode, false},
{include_erts, true},

{sys_config, "./config/prod.config"},
{include_erts, "/Users/leeyi/workspace/erl/erlang_otp20.0_for_centos7"},
{system_libs, "/Users/leeyi/workspace/erl/erlang_otp20.0_for_centos7"}
]}
]}
]}.

{include_erts, false} ,开发时使用这个配置,在执行 rebar3 release 时,只是创建一个ERTS的软链接,省下了拷贝文件的时间。在生产环境下,你可以创建一个product的profile,里面定义 {include_erts, true} ,这样执行 rebar3 as product release 时,ERTS会被拷贝到发布文件夹中,在服务器上部署不需要安装Erlang。

config/vm.args 设置 -mnesia dir

vim config/vm.args :

-sname es_client

-mnesia dir '"mnesia.db"'

-setcookie es_client_cookie

+K true
+A30

src/es_client.app.src 设置 applications

这里之所以发布的是要设置,而不是一直都这么({applications, [kernel,stdlib,jsx,erlastic_search,mnesia]})设置applications,是因为:

发布的时候要不所有依赖的applications附带到发布包里面去;

而在本地开发环境如果这么设置为报错:

(es_client2@leeyideiMac)1> application:start(es_client).
{error,{not_started,jsx}}

这个问题目前没有找到解决办法,有时间了在研究下,

发布的时候 src/es_client.app.src 配置如下:

{application, es_client,
[{description, "elasticsearch client"},
{vsn, "0.1.0"},
{author, "leeyi"},
{email, "leeyisoft@icloud.com"},
{registered, []},
{mod, { es_client_app, []}},

% 注意这个配置节是指定当前应用程序依赖哪些应用程序,类似Windows服务的依赖关系
% 发布release的依赖
{applications, [kernel,stdlib,jsx,erlastic_search,mnesia]},
% local 的依赖
% {applications, [kernel,stdlib]},
{env,[]},
{modules, [file_scaner, esc_db,func]},

{maintainers, []},
{licenses, ["Apache 2.0"]},
{links, []}
]}.

发布

rebar3 as product release

rebar3 as prod tar

rebar3 as centos-7 tar

scp _build/centos-7/rel/es_client/es_client-0.1.0.tar.gz root@192.168.2.207:/usr/local/es_client/

发布之后

tar -xvf es_client-0.1.0.tar.gz

bin/es_client console

bin/es_client start

参考资料

https://www.rebar3.org/v3.0/docs/publishing-packages

https://github.com/erlang/rebar3/issues/954

我刚刚做的一个项目,就是这么发布的( http://git.oschina.net/leeyi/es_client
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Rebar3 Erlang CentOS7