1. 程式人生 > >erlang接入遠端shell控制檯的幾種方式

erlang接入遠端shell控制檯的幾種方式

erlang shell是使用者與 erlang 執行時系統互動的介面程式。事實上,erlang VM的執行不依賴任何shell,只要在啟動的時候新增引數detached就可以脫離終端。

-detached

Starts the Erlang runtime system detached from the system console. Useful for running daemons and backgrounds processes. Implies -noinput.
實際上,detached 等效於noshell 加上 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

另外,需要注意的是,windows不直接支援detached,而是以服務的形式在後臺執行,見 erlsrv

現在討論erlang 接入遠端shell控制檯的幾種方式。

  • 作業(JCL )模式

在 Erlang shell 中按下^G鍵,就可以看到作業控制模式(JCL mode)的選單。在選單中,有個選項能讓我們連線到一個遠端 shell。
先以detached執行一個節點1:

erl -name [email protected] -setcookie 123456 -detached

檢查這個erlang程序是否執行

ps -ef | grep beam
root 20672 1 0 01:32 ? 00:00:00 /home/erl/lib/erlang/erts-5.10.3/bin/beam – -root /home/erl/lib/erlang -progname erl – -home /root – -name

[email protected] -setcookie 123456 -noshell -noinput

啟動另外一個節點2,並接入到節點1

erl -name [email protected] -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)
([email protected])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 ‘

[email protected]
–> j
1 {shell,start,[init]}
2* {‘[email protected]’,shell,start,[]}
–> c 2
Eshell V5.10.3 (abort with ^G)
([email protected])1>

注意了,windows下要使用werl

連線到遠端 shell 後,所有的終端輸入解析操作都由本地 shell 完成,不過求值的工作是在遠 程完成的。遠端求值的結果輸出全部被轉發給本地 shell。

要退出 shell, 按^G回到 JCL 模式。 終端輸入解析操作是在本地進行的, 因此通過^G q 的方式退出 shell 是安全的。

Eshell V5.10.3 (abort with ^G)
([email protected])1>
User switch command
–> q

  • Remsh 模式

Remsh和 JCL 模式很類似,但是呼叫方式不同的機制。使用這種機制,JCL 模式的所有 操作步驟都可以被繞過,只需像下面這樣啟動 shell,對於長名字:

-remsh Node
Starts Erlang with a remote shell connected to Node.

以下方式啟動節點2,將直接接入節點1控制檯:

erl -name [email protected] -setcookie 123456 -remsh [email protected]
Erlang R16B02 (erts-5.10.3) [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V5.10.3 (abort with ^G)
([email protected])1> node().
[email protected]

這種方式和JCL很相像,本地也會啟動一個erlang節點用於接入遠端shell

  • SSH 模式

erlang自帶了SSH的功能,我們可以很方便的開啟SSH服務,對外提供遠端 shell服務。 SSH的使用需要開啟crypto,如果erlang顯示以下錯誤,可以參考這篇文章。

1> crypto:start().
** exception error: undefined function crypto:start/0

要使用該功能,通常需要先準備好具有遠端訪問 SSH 許可權的 key,不過這裡為了快速測試,可以這樣做:
節點1啟動ssh服務:

Eshell V5.10.3 (abort with ^G)
([email protected])1> ssh:start().
ok
([email protected])2> ssh:daemon(8888, [{password, “12345”}]).
{ok,<0.57.0>}

本地不需要啟動erlang節點,直接使用ssh連線即可,輸入以上設定的密碼,就可以接入節點1的shell控制檯。

ssh -p 8888 [email protected]
The 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)? yes
Warning: Permanently added ‘[127.0.0.1]:8888’ (RSA) to the list of known hosts.
[email protected]’s password:
Eshell V5.10.3 (abort with ^G)
([email protected])1>

這種方式,erlang shell所有操作都是在遠端節點完成的。

  • 管道(pipe)模式

在使用管道(pipe)連線到一個Erlang節點時,和SSH一樣不需要啟動本地erlang節點。這種方法很少用,每次輸出時都呼叫fsync,如果輸出過多時,會有很大的效能損失。

具體做法為:用 run_erl 啟動 erlang,相當於把 erlang 程序包在一個管道中:

mkdir /tmp/erl_log
cd /home/erl/bin
./run_erl -daemon /tmp/erl_pipe /tmp/erl_log “erl -name [email protected] -setcookie 123456”

其中,daemon 表示以後臺程序執行,/tmp/erl_pipe是管道檔案的名稱,/tmp/erl_log指定了日誌儲存資料夾
然後使用 to_erl 程式來連線節點:

./to_erl /tmp/erl_pipe
Attaching to /tmp/erl_pipe (^D to exit)
([email protected])1> node().
[email protected]

相關推薦

erlang接入遠端shell控制檯方式

erlang shell是使用者與 erlang 執行時系統互動的介面程式。事實上,erlang VM的執行不依賴任何shell,只要在啟動的時候新增引數detached就可以脫離終端。 -detached Starts the Erlang r

遠端呼叫的方式

      在分散式服務框架中。最基礎的問題就是遠端服務是怎麼通訊的。首先來看看計算機系統網路通訊的基本原理。網路通訊須要做的就是將流從一臺計算機傳輸到另外一臺計算機,基於傳輸協議和網路IO來實現。當中傳輸協議有tcp、udp等等。tcp、udp都是在基於Socket概念上為某類應用場景而擴展出的傳輸協議。網

Erlang 接入遠端控制檯方法

目錄 目錄 測試環境 JCL Remsh SSH PIPE 這篇部落格源自於除錯過程中發現的一個比較有意思的問題。 平時我們的專案生產環境一般都是在 linux 作業系統後臺中執行,但我們在執行中勢必有連線到線上環境的需求,這時候就需要有

linux指令碼中父shell與子shell 執行的方式

本文主要介紹以下幾個命令的區別: shell subshell source $ (commond) `commond` Linux執行Scripts有兩種方式,主要區別在於是否建立subshell 1. source filename or . filename 不建立subshell,在當前shel

Shell中整數計算的方式

在Shell中可以使用下列方式來做整數的計算(+,-,*,/) 方式一: linux:~ # A=1 linux:~ # B=2 linux:~ # C=$(($A+$B)) linux:~ # echo $C 3 方式二: linux:~ # A=1 linux:~ # B=2

Shell中表示數字跨度的方式

在Shell指令碼中,如果要輸出數字為0-20中3的倍數。可以使用下面三種方式來完成 方式一:  ((i=0;i<=20;i+=3)) for((i=0;i<20;i+=3)) do echo $i done 方式二: {0..20..3} for

spring mvc 實現遠端服務呼叫的方式

org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter 實現遠端服務呼叫 (1)httpinvoker方式 伺服器客戶端都是spring時推薦這種方式 服務端 必須要實現 bean實體類

shell for語句 (+算數運算的方式)

for語句的格式為: for 變數 in 引數1 引數2.....引數n do            命令序列 done 在for迴圈語句中,關鍵字為for,in,do,done,變數的賦值會貫穿for迴圈的執行過程,引數列表是一串由空格或者tab鍵分開的字串組成的,在每

Perl執行shell命令的方式及其區別

There are many ways to execute external commands from Perl. The most commons are: system functionexe

Eclipse安裝svn插件的方式 轉帖....

如果 version name feature help sin 鏈接 exe 文件 Eclipse安裝svn插件的幾種方式 1.在線安裝: (1).點擊 Help --> Install New Software... (2).在彈出的窗口中點擊add按鈕,輸

解決瀏覽器跨域的方式

doc cor 求和 對象 跨域 http onf 從服務器 console 1、什麽是跨域問題 在頁面中使用js訪問其他網站的數據時,就會出現跨域問題,比如在網站中使用ajax請求其他網站的天氣、快遞或者其他數據接口時,以及hybrid app中請求數據,

前端跨域方式

div ner dev 修改 ati hash 標簽 nbsp 端口 跨域問題的直接原因是瀏覽器存在同源策略,瀏覽器同源指的是:兩個頁面的協議、端口和主機相同,則兩個頁面具有相同的源。IE下滿足協議、主機相同,就認為是同源。 想象一下,如果沒有同源策略,誰都可以修改你站點

Python 與 C/C++ 交互的方式

pythonpython作為一門腳本語言,其好處是語法簡單,很多東西都已經封裝好了,直接拿過來用就行,所以實現同樣一個功能,用Python寫要比用C/C++代碼量會少得多。但是優點也必然也伴隨著缺點(這是肯定的,不然還要其他語言幹嘛),python最被人詬病的一個地方可能就是其運行速度了。這這是大部分腳本語言

php中實現頁面跳轉的方式

腳本 timeout location clas replace asc idt lee 實現 親測,not復制粘貼 PHP中實現頁面跳轉有一下幾種方式,看了幾個人寫的不是很條理,自己整理一下 在PHP腳本代碼中實現 <?php header("locati

Java 修改編碼格式的方式

格式 text cnblogs 修改 .com pac 方式 src -1 1、工作空間 workspase Window→Preferences→General→Workspace→Text file encoding→other→UTF-8 2、項目編碼格式 右鍵項目

Oracle數據庫遷移的方式

備份與恢復 行遷移 target span spf 位置 server create 設備 面試: 一、exp/imp邏輯備份與恢復: 二、Storage存儲遷移: 將數據文件、控制文件、日誌文件、spfile掛到新機器上,然後在新機器上啟動數據庫。 三、利用data gu

C#打開SDE數據庫的方式總結

tex 用戶 ops 總結 param word editor conn tor 轉自謝燦軟件原文 C#打開SDE數據庫的幾種方式總結 1.通過指定連接屬性參數打開數據庫 /// <param name="server">數據庫服務器名&

數組去重的方式

strong class 一個 spl spa cnblogs 不變 數字 {} 一、利用indexOf查找,ie9以下不兼容 function noRepeat(ary) { if (ary instanceof Array) { var new

即時通信常見的方式,此處只做學習記錄

維護 時間 最簡 安裝 記錄 htm websocket 雙向 new 1. 輪詢 利用ajax每隔一段時間就請求一次服務器,服務器返回數據。 優點:最簡單的解決方案 缺點:對服務器壓力很大,浪費帶寬 2. 長輪詢 利用ajax請求服務器,當有數據變化

IOC創建對象的方式

pri clas ati div 參數 system 實例方法 tex 通過 接上一篇IOC入門 IOC創建對象的幾種方式 1)調用無參數構造器 2)帶參數構造器 3)工廠創建對象   工廠類:靜態方法創建對象   工廠類:非靜態方法創建對象 1、對之前的User類