zoukankan      html  css  js  c++  java
  • 本机连接调试Erlang结点与rebar3编译

        今天需要实时查看目标结点上的相关信息,于是查阅了关于远程Shell使用的资料,最终采用JCL的方式与本机上的erlang结点交互。在使用erl shell时需要指定目标结点的cookie以及当前结点名,才能正确连接到目标结点。比如:

        erl -name Jack@127.0.0.1 -setcookie xxxxx

        注意-name指定的long-name必须包含@,不然会报'Can't set long name, please check your configuration'的错误。然后Ctrl+G进入到User Switch Command模式进行操作。测试发现目标结点执行io:format时的输出并未在本地shell中输出,因此只好在目标结点上编写api并返回字符串信息,在本地shell通过io:format再输出。比如:

        io:format(gen_server:call(xxx, {debug, dump})).

        考虑到目标机上没有erlang环境,因此需要发布release镜像包布署到目标机上,再ssh到上面执行。这里是使用rebar3编译打包的,git地址为:

        https://github.com/erlang/rebar3

        执行命令如下:

        $ git clone https://github.com/erlang/rebar3.git

        $ cd rebar3

        $ ./bootstrap

        $ ./rebar3 local install # 本地安装

        ==> Extracting rebar3 libs to ~/.cache/rebar3/lib...

        ==> Writing rebar3 run script ~/.cache/rebar3/bin/rebar3...

        ==> Add to $PATH for use: export PATH=$PATH:~/.cache/rebar3/bin

        $ export PATH=$PATH:~/.cache/rebar3/bin # 添加到环境变量

        rebar3环境安装好后,创建工程:

        $ rebar3 new release test

        编写好代码后,编译:

        $ rebar3 compile

        打包发布:

        $ rebar3 as prod tar

        详细内容见rebar3官方文档:http://www.rebar3.org/docs/basic-usage

        这时,在_build/prod/rel/test目录下就可以看到生成的tar.gz文件了。注意在启动时有多个参数可以选择,因为要在shell界面输入命令,因此在bin目录下应该输入如下命令:

        $ ./test console # 如果想在后台运行应该输入./test start

        在启动shell连接目标结点时,首先需要设置cookie:

        erlang:set_cookie(node(), xxxx).

        之后又报错:erlang System NOT running to use fully qualified hostnames; 127.0.0.1 is illegal hostname for Erlang nodes

        从提示来看,是因为test工程是以短命名启动结点的。找到config目录下的vm.args文件,修改其中的-sname test@localhost为-name test@localhost,再重新启动,成功连接。

    
    
  • 相关阅读:
    典型用户
    站立会议5
    站立会议4
    《构建之法》阅读笔记05-需求分析
    站立会议3
    编写Android程序Eclipse连不上手机。
    站立会议2
    站立会议1
    第七周学习进度
    shiro之 散列算法(加密算法)
  • 原文地址:https://www.cnblogs.com/Jackie-Snow/p/9324001.html
Copyright © 2011-2022 走看看