分布式Elixir示例不起作用 [英] Distributed Elixir example doesn't work
问题描述
我有一个非常简单的Elixir代码示例,希望在不同的节点上运行。
I have a very simple Elixir code sample I want to run on different nodes.
第一个节点在笔记本电脑上,第二个节点在Raspberry Pi上,
The first node is on my laptop, the second one is a Raspberry Pi, accessed via SSH.
代码很简单:
# node1@my-computer
defmodule Hello do
def world, do: IO.puts "hello world"
end
# node2@raspberrypi
iex> Node.spawn_link :"node1@my-computer", fn -> Hello.world end
我希望 Node.spawn_link
会在Raspberry Pi上打印 hello world
,但显示错误消息 **(退出#PID< 0.66.0> ;)no connect
I expected that Node.spawn_link
would print "hello world"
on the Raspberry Pi, but instead it shows an error saying ** (EXIT from #PID<0.66.0>) no connect
在同一台机器上,有两个不同的 iex
实例,此代码
On the same machine with two different iex
instances this code works just fine.
我在 node1
和 iex上启动IEx会话- -sname node1 --cookie机密
,并在 node2
上,并带有 iex --sname node2 --cookie机密
。
I'm starting the IEx session on node1
with iex --sname node1 --cookie secret
and on node2
with iex --sname node2 --cookie secret
.
还值得注意的是,在我的Raspberry Pi iex
上出现以下警告:
It's also worth noting that on my Raspberry Pi iex
starts with this warning:
警告:VM运行时的本地名称编码为latin1,这可能会导致Elixir如预期的utf8那样发生故障。请确保您的语言环境设置为UTF-8(可以通过在外壳程序中运行 locale来验证)
Interactive Elixir(1.0.5)-按Ctrl + C退出(键入h()ENTER以获取帮助)
推荐答案
我认为您需要输入 @
登录节点名称,将其解释为单独的联网计算机
I think you need to put the @
sign in the node-names to get them to be interpreted as separate networked machines
iex --name node@machinename1 --cookie mycookie
iex --name node@machinename2 --cookie mycookie
然后在第一个iex shell中连接节点:
and then in the first iex shell connect the nodes:
Node.connect :"node@machinename2"
请注意使节点名称成为长生不老药原子的冒号语法。由于 @
符号,所以需要使用引号。
如果遇到问题,您可以先尝试使用具有原始IP地址的机器名,然后再尝试dns名称。
Nb:我使用-name
而不是您的-名称
Note the colon syntax that make the node name into a elixir atom. The quotes are needed because of the @
sign.
You might try machinenames with the raw ip addresses first before trying dns names, if you are having problems
Nb: I use --name
rather than your --sname
这篇关于分布式Elixir示例不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!