如何通过局域网连接两个Elixir节点? [英] How to connect two Elixir nodes via local network?
本文介绍了如何通过局域网连接两个Elixir节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过网络连接连接两台不同计算机的两个Erlang / Elixir节点?
How can I connect two Erlang/Elixir-nodes of two different machines via network connection?
推荐答案
您必须命名您的节点并在两个节点上使用相同的cookie。
You have to name your nodes and use the same cookie on both nodes.
在机器1:
iex --name node1@machine1.com --cookie a_cookie_string
在机器2中:
iex --name node2@machine2.com --cookie a_cookie_string
现在两台机器可以通讯了。要对其进行测试,可以在machine1上执行以下操作:
Now the two machines can communicate. To test it, you can do something like this, on machine1:
iex(node1@machine1.com)1> Node.connect :"node2@machine2.com"
true
iex(node1@machine1.com)2> print_node_name = fn -> IO.puts Node.self end
#Function<erl_eval.20.80484245>
iex(node1@machine1.com)3> Node.spawn(:"node2@machine2.com", print_node_name)
node2@machine2.com
#PID<7789.49.0>
域名 machine1.com
和 machine2.com
也可以使用计算机的ip地址进行更改。
Domain names machine1.com
and machine2.com
can be changed with the ip addresses of the machines as well.
这篇关于如何通过局域网连接两个Elixir节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文