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

在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)

配置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

参考资料

我刚刚做的一个项目,就是这么发布的( http://git.oschina.net/leeyi/es_client

转载于:https://my.oschina.net/leeyisoft/blog/1504354

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值