[erlang-questions] net_kernel:start/1 and net_kernel:connect_node/1 errors

Bengt Kleberg <>
Mon Mar 7 06:19:24 CET 2016


Greetings,

To start epmd , if it might not have been started automatically by 
"erl", I do
os:cmd( "epmd" ).

If you want to see what epmd knows, you can do
"epmd -names"
from the Unix CLI.

If you want to run on multiple nodes, take a look at the slave module. 
Especially the bit about I/O happening on the master.


bengt

On 03/06/2016 10:28 AM, Khitai Pang wrote:
> Hi,
>
> I'm having some problems with distributed erlang on Linux.
>
> I have two ubuntu hosts, and on each node the ERL_EPMD_PORT 
> environment variable is set to 5779.
>
> Hostnames are properly set in /etc/hosts on both hosts.  Erlang is 
> started on the two hosts by
>
> $ erl -sname 
>
> ()1> node().
> 
>
> $ erl -sname 
>
> ()1> node().
> 
>
> and epmd is running on both hosts listening on 5779.
>
>
> Question 1:  Why does connecting to  using 
> net_kernel:connect_node/1 fail?
>
> ()4> net_kernel:connect_node().
> false
>
> It runs for a couple seconds and returns false.
>
> Is it because epmd is not listening on the default port?
>
>
> Question 2: If epmd is not running, when I run 
> net_kernel:start([, shortnames]), it returns error.  Why? If 
> it's caused by epmd not running, how to make sure that epmd is started 
> when you start an OTP release?
>
> 1> net_kernel:start([, shortnames]).
> {error,
>     {{shutdown,
> {failed_to_start_child,net_kernel,{'EXIT',nodistribution}}},
>      {child,undefined,net_sup_dynamic,
>          {erl_distribution,start_link,[[,shortnames]]},
>          permanent,1000,supervisor,
>          [erl_distribution]}}}
>
>
> Question 3: After starting erl with -sname, if you run netstat, you'll 
> see a process listening on a random port, what is it?
>
> tcp        0      0 0.0.0.0:23333           0.0.0.0:* LISTEN 
> 12650/beam.smp
>
>
> Question 4: If an OTP release is meant to run on multiple nodes, how 
> to properly set node name and start distribution on each node 
> automatically?  I want to start running the release on all nodes by 
> running one command on one of the nodes.
>
> Currently I'm planning to do it this way:
>
> 1) hardcode all participating hostnames in sys.conf, something like 
> [{"er1", "host1"}, {"er2", "host2"}]
> 2) on each host, when the erlang application starts, it reads the 
> config from sys.conf, finds its own name and use net_kernel:start/1 to 
> set the node name and start distribution
>
> What is the best practice to do it?
>
>
> Thanks
> Khitai
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list