Erlang access to remote shell console, erlangshell Console
Erlang shell is the interface program for system interaction between users and erlang runtime. In fact, the running of erlang VM does not rely on any shell, as long as the parameter detached is added at startup, it can be detached from the terminal. -DetachedStarts the Erlang runtime system detached from the system console. Useful for running daemons and backgrounds processes. Implies-noinput. In fact, detached is equivalent to noshell with noinput. # Erl-Detached-Emu_args
Executing: /home/erl/lib/erlang/erts-5.10.3/bin/beam/home/erl/lib/erlang/erts-5.10.3/bin/beam ---root/home/erl/lib/erlang- progname erl ---home/root ---Noshell-noinput
In addition, windows does not directly support detached, but runs in the background as a service. For details, see erlsrv.
Now we will discuss several ways for erlang to access the remote shell console. Press the ^ G key in Erlang shell in job (JCL) mode to view the menu of Job control mode (JCL mode. In the menu, there is an option for us to connect to a remote shell. Run a node 1 with detached: # erl-name1@127.0.0.1-Setcookie 123456-detached: Check whether the erlang process is running.
# Ps-ef | grep beamroot 20672 1 0 0:32? 00:00:00/home/erl/lib/erlang/erts-5.10.3/bin/beam ---root/home/erl/lib/erlang-progname erl ---home/root ---name1@127.0.0.1-Setcookie 123456-noshell-noinput start another node 2 and connect to node 1
# Erl-name2@127.0.0.1-Setcookie 123456: Erlang R16B02 (erts-5.10.3) [source] [64-bit] [async-threads: 10] [hipe] [kernel-poll: false] Eshell V5.10.3 (abort with ^ G) (2@127.0.0.1) 1> User switch command --> H C [nn]-connect to job I [nn]-interrupt job K [nn]-kill job J-list all jobs S [shell]-start local shell R [node [shell]-start remote shell Q-quit erlang ? | H-this message --> R'1@127.0.0.1' --> J 1 {shell, start, [init]} 2*{'1 @ 127.0.0.1 ', shell, start, []} --> C 2 Eshell V5.10.3 (abort with ^ G) (1@127.0.0.1) 1> |
Note that werl should be used in windows.
After connecting to the remote shell, all terminal input parsing operations are completed by the local shell, but the evaluation is completed in the remote process. The remote result output is all forwarded to the local shell. To exit the shell, press ^ G to return to the JCL mode. Terminal input parsing is performed locally. Therefore, it is safe to exit shell through ^ G q. Eshell V5.10.3 (abort with ^ G)
1@127.0.0.1 1>
User switch command
--> Q
The Remsh and JCL modes are similar, but the calling methods are different. With this mechanism, all operation steps in JCL mode can be bypassed. You only need to start the shell as follows, for long names:
-Remsh NodeStarts Erlang with a remote shell connected to Node.
Start Node 2 in the following way and directly Access Node 1 Console: # erl-name
2@127.0.0.1-Setcookie 123456:
-Remsh1@127.0.0.1Erlang R16B02 (erts-5.10.3) [source] [64-bit] [async-threads: 10] [hipe] [kernel-poll: false] Eshell V5.10.3 (abort with ^ G )(
1@127.0.0.1) 1> node (). '1 @ 127.0.0.1 'is similar to JCL. An erlang node is also started locally to access a remote shell.
The SSH mode erlang comes with the SSH function. We can easily enable the SSH service and provide remote shell services. To use SSH, you must enable crypto. If erlang displays the following errors, refer to this article. 1> crypto: start (). ** exception error: undefined function crypto: start/0 to use this function. Usually, you need to prepare a key with the remote access to SSH. However, to perform a quick test, you can do this: node 1 starts the ssh service:
Eshell V5.10.3 (abort with ^ G )(1@127.0.0.1) 1> ssh: start (). OK (1@127.0.0.1) 2> ssh: daemon (8888, [{password, "12345"}]). {OK, <0.57.0>} |
If you do not need to start the erlang node locally, you can directly connect to it using ssh. Enter the password set above to access the shell console of Node 1.
# Ssh-p 88881@127.0.0.1The authenticity of host' [127.0.0.1]: 8888 ([127.0.0.1]: 8888) 'Can't be established. RSA key fingerprint is ad: 03: b4: 6b: df: 51: 97: 23: dc: 47: cb: 75: 85: 15: 44: 89.Are you sure you want to continue connecting (yes/no )?YesWarning: Permanently added '[127.0.0.1]: 100' (RSA) to the list of known hosts.1@127.0.0.1's password: Eshell V5.10.3 (abort with ^ G )(1@127.0.0.1) 1> |
In this way, all the operations of erlang shell are performed on the remote node.
Pipeline (pipe) mode when using pipeline (pipe) to connect to an Erlang node, you do not need to start a local erlang node like SSH. This method is rarely used, and fsync is called every time the output is made. If there are too many outputs, there will be a huge performance loss.
Specifically, use run_erl to start erlang, which is equivalent to package the erlang process in a pipe: # mkdir/tmp/erl_log # cd/home/erl/bin #. /run_erl-daemon/tmp/erl_pipe/tmp/erl_log "erl-name
1@127.0.0.1-Setcookie 123456 "where daemon indicates that subsequent processes are running,/tmp/erl_pipe indicates the name of the pipeline file,/tmp/erl_log specifies the log storage folder, and then uses the to_erl program to connect to the node: #. /to_erl/tmp/erl_pipeAttaching to/tmp/erl_pipe (^ D to exit)
(
1@127.0.0.1) 1> node ().
'1 @ 127.0.0.1'
Reference: http://blog.csdn.net/mycwq/article/details/43850735https://s3.amazonaws.com/erlang-in-anger/text.v1.0.3.pdf