Erlang - Nodes don't recognize

江枫思渺然 提交于 2019-12-11 12:37:11

问题


I'm trying to use distributing programming in Erlang.

But I had a problem, I can't communicate two Erlang's nodes to communicate.

I tried to put the same atom in the "Magical cookies", but it didn't work.

I tried to use command net:ping(node), but reponse was pang (didn't reconigze another node), or used nodes(), to see if my first node see the second node, but it didn't work again.

The first and second node is CentOS in VMWare, using bridge connection in network adaptor.

I entered command ping outside Erlang between VM's and they reconigze each one.

I start the first node, but the second node open process, but can't find the node pong.

(pong@localhost)8> tut17:start_pong().
true


(ping@localhost)5> c(tut17).
{ok,tut17}
(ping@localhost)6> tut17:start_ping(pong@localhost).
<0.55.0>

Thank you!


回答1:


A similar question here.

The distribution is provided by a daemon called Erlang Port Mapper Daemon. By default it listens on port 4369 so you need to make sure that that port is opened between the nodes. Additionally, each started Erlang VM opens an additional port to communicate with other VMs. You can see those ports with epmd -names:

g@someserv1:~ % epmd -names
epmd: up and running on port 4369 with data:
name hbd at port 22200

You can check if the port is opened by doing telnet to it, e.g.:

g@someserv1:~ % telnet 127.0.0.1 22200
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
^]
Connection closed by foreign host.

You can change the port to the port you want to check, e.g. 4369, and also the IP to the desired IP. Doing ping is not enough because it uses its own ICMP protocol which is different that TCP used by the Erlang distribution to communicate, e.g. ICMP may be allowed but TCP may be blocked.

Edit:

Please follow this guide Distributed Erlang to start an Erlang VM in distributed mode. Then you can use net_adm:ping/1 to connect to it from another node, e.g.:

(hbd@someserv1.somehost.com)17> net_adm:ping('hbd@someserv2.somehost.com').
pong

Only then epmd -names will show the started Erlang VM on the list.

Edit2:

Assume that there are tho hosts, A and B. Each one runs one Erlang VM. epmd -names run on each host shows for example:

Host A:

epmd: up and running on port 4369 with data:
name servA at port 22200

Host B:

epmd: up and running on port 4369 with data:
name servB at port 22300

You need to be able to do:

On Host A:

telnet HostB 4369
telent HostB 22300

On Host B:

telnet HostA 4369
telnet HostA 22200

where HostA and HostB are those hosts' IP addresses (.e.g HostA is IP of Host A, HostB is IP of Host B).

If the telnet works correctly then you should be able to do net_adm:ping/1 from one host to the other, e.g. on Host A you would ping the name of Host B. The name is what the command node(). returns.




回答2:


You need to make sure you have a node name for your nodes, or they won't be available to connect with. E.g.:

erl -sname somenode@node1

If you're using separate hosts, then you need to make sure that the node names are resolvable to ip addresses somehow. An easy to way to do this is using /etc/hosts.

# Append a similar line to the /etc/hosts file
10.10.10.10 node1

For more helpful answers, you should post what you see in your terminal when you try this.


EDIT

It looks like your shell is auto picking "localhost" as the node name. You can't send messages to another host with the address "localhost". When specifying the name on the shell, try using the @ syntax to specify the node name as well:

# On host 1:
erl -sname ping@host1

# On host 2
erl -sname pong@host2

Then edit the host file so host1 and host2 will resolve to the right IP.



来源:https://stackoverflow.com/questions/35762894/erlang-nodes-dont-recognize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!