I am using net_adm:world() to connect to Nodes on other hosts, but the only way I got this to work is once I manually created a hosts file and list the name of the other host in the file. If I had 10 hosts I would have to put this file on all ten machines and update the list ten times every time a new host is added to the cluster.
Is there no way this file can be automatically updated each time a connection to a Node on a new host is made?
your .hosts.erlang file doesn't need to be complete or 100% correct. a node only needs to connect to one other to learn about every other node in the cluster.
you could skip maintaining the .hosts.erlang file and use mutlicast UDP to dynamically discover nodes. See nodefinder for example code.
we started down the multicast UDP route but then decided to just maintain a central hosts file and use rsync to distribute it to all hosts. we restart nodes infrequently so it hasn't been a big problem.
We use chef to prepopulate the .hosts.erlang
file for nodes that belong to a cluster. The function net_adm:world()
can be used to determine the nodes that are currently part of a cluster which does not necessarily match what is contained .hosts.erlang
, e.g., when one of the nodes is down. An alternative to using net_adm:world()
is the function net_adm:world_list(Hosts)
which takes a list of hosts (instead of reading from .hosts.erlang
) and does the same as net_adm:world()
to determine the currently connected nodes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With