I am running an Elixir app on my 3 servers. I recently needed to connect nodes so that I can sync something between them, and for that I set short names for each node.
I am using Edeliver/Distillery to generate release and deploy. I copied var/vm.args to release directory on each node and changed -name blah@ip to -sname name@nodename. Nodes can see and connect to each other without problem.
Before I given each node a name, I used ssh to remotely connect to my nodes when I needed to debug my app. I used this approach:
ssh node -L 4369:127.0.0.1:4369- run
epmd -nameson my local machine to find out port of my app - kill last ssh and run
ssh node -L 4369:127.0.0.1:4369 -L port:127.0.0.1:portto have access to running node on my machine - run
iex --hidden --erl '-name debug -setcookie cookie_like_server'on my machine - now I had access to remote node, e.g. I could use
observerto see my remote node
The same procedure won't work now.
First I see an error saying nodes using short and long names cannot connect to each other, obviously.
I changed my iex command to iex --hidden --erl '-sname debug -setcookie cookie_like_server' to use short name. This way connection times out when I try to connect to remote node on observer.
I don't really get the problem. Am I doing something wrong? Is here another way to get access to a running node that uses short name?
BTW, I used ssh so that my traffic will be encrypted. Please do tell me if there is a solution that makes my connection non-encrypted, though I will probably not use it, or somehow tunnel it through ssh.
UPDATE
I tried method suggested by @christophe-de-troyer. TLDR, didn't work.
vahid@arch-adtube ~/ % iex --sname debug --cookie 'cookie' --remsh backend-platform@prod-1
Erlang/OTP 20 [erts-9.0.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]
Could not contact remote node backend-platform@prod-1, reason: :nodedown. Aborting...
ssh prod-1 -L 4369:127.0.0.1:4369 was running, and epmd -names reports backend-platform as a running node correctly.
If you want to connect to a remote node you will have to pass a full name (
--name) instead of a short name (--sname), from my experience.So on Node A, with ip 192.168.1.10, you run:
iex --name [email protected] --cookie secretOn node B, with ip 192.168.1.11, you run:
iex --name [email protected] --cookie secretAnd then on your computer, with ip 192.168.1.12, you can attach to these remote shells using. First of all you have to make sure that your local EPMD port (4369) is bound to the remote server's EPMD port, by tunneling it over SSH.
ssh a -L 4369:127.0.0.1:4369Then you can connect with a remote shell to these nodes using:
iex --name [email protected] --cookie secret --remsh [email protected]I have experimented a bit on my machines, and I found out that it only works with IP addresses. My machine running at
machine.example.com, with hostnamemachine, was not connectable if the name on the remote machine was not qualified with its ip address, or domain name. And I had to match that with the DNS name, or ip address on my connecting client.There is some interesting traffic on the mailing list of Erlang about this[1].
[1] http://erlang.org/pipermail/erlang-questions/2006-December/024270.html
Edit
I did some further experimentation and succeeded in connecting to remote nodes with shortnames.
As you already mentioned, you indeed need the two nodes to be running in the same naming mode (i.e., both short, or both fully qualified).
On node
A, with ip12.12.12.12, and FQDNa.example.com, I spawned a shell as such:iex --sname bob --cookie secretOn my local machine
L, with ip5.5.5.5, and FQDNl.notanexample.com, I spawned a shell as such:ssh a -L 4369:127.0.0.1:4369iex --sname alice --cookie secret --remsh bob@aThe reason this works, and did not before, was because on my local machine, in the
/etc/hostsfile, I did not put a line that bound the hostname (short hostname) to the remote IP.So in
/etc/hostson my local machine I have the following line now:12.12.12.12 a.