【问题标题】:Is it possible to change the name of a running Elixir node是否可以更改正在运行的 Elixir 节点的名称
【发布时间】:2020-03-17 07:55:32
【问题描述】:

我想动态更改一个梁实例的节点名称。

用例位于 VM 集群中,我希望启动过程查找 ip 信息,然后从中选择一个名称。

node()
# => :nonode@nohost

# Lookup ip and change name

node()
# => :myapp@x.x.x.x

【问题讨论】:

    标签: erlang elixir distributed


    【解决方案1】:

    是的,你可以在 Erlang 中使用 net_kernel:start/1 或在 Elixir 中使用 Node.start/{1,2,3}

    1> node().
    nonode@nohost
    2> net_kernel:start(['myapp@1.2.3.4']).
    {ok,<0.60.0>}
    (myapp@1.2.3.4)3> node().
    'myapp@1.2.3.4'
    
    iex(1)> Node.self
    :nonode@nohost
    iex(2)> Node.start :"myapp@1.2.3.4"
    {:ok, #PID<0.83.0>}
    iex(myapp@1.2.3.4)3> Node.self
    :"myapp@1.2.3.4"
    

    【讨论】:

    • 从新的 iex shell 开始尝试此操作时出现错误。 {:error, {{:shutdown, {:failed_to_start_child, :net_kernel, {:EXIT, {:function_clause, [{:net_kernel, :start_link, [:"dev@172.28.128.7", false], [file: 'net_kernel .erl',行:357]},
    • 看起来epmd 没有在系统上运行。看看这个问题和答案:stackoverflow.com/questions/18240319/ensure-epmd-started
    猜你喜欢
    • 1970-01-01
    • 2012-07-03
    • 2019-12-03
    • 1970-01-01
    • 2018-10-12
    • 2016-08-28
    • 2019-06-28
    • 2019-10-25
    • 1970-01-01
    相关资源
    最近更新 更多