我是靠谱客的博主 乐观棒棒糖,最近开发中收集的这篇文章主要介绍在局域网内启动节点时的“Can't set long node name”异常,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

错误描述:

chenpeng@chenpeng:~/erlangWorkspace/concurrent$ erl -name chenpeng -setcookie baeeq

{error_logger,{{2010,4,3},{22,28,7}},"Can't set long node name!/nPlease check your configuration/n",[]}

{error_logger,{{2010,4,3},{22,28,7}},crash_report,[[{initial_call,{net_kernel,init,['Argument__1']}},{pid,<0.21.0>},{registered_name,[]},{error_info,{exit,{error,badarg},[{gen_server,init_it,6},{proc_lib,init_p_do_apply,3}]}},{ancestors,[net_sup,kernel_sup,<0.8.0>]},{messages,[]},{links,[<0.18.0>]},{dictionary,[{longnames,true}]},{trap_exit,true},{status,running},{heap_size,1597},{stack_size,24},{reductions,909}],[]]}

{error_logger,{{2010,4,3},{22,28,7}},supervisor_report,[{supervisor,{local,net_sup}},{errorContext,start_error},{reason,{'EXIT',nodistribution}},{offender,[{pid,undefined},{name,net_kernel},{mfa,{net_kernel,start_link,[[chenpeng,longnames]]}},{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}

{error_logger,{{2010,4,3},{22,28,7}},supervisor_report,[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,shutdown},{offender,[{pid,undefined},{name,net_sup},{mfa,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}

{error_logger,{{2010,4,3},{22,28,7}},std_info,[{application,kernel},{exited,{shutdown,{kernel,start,[normal,[]]}}},{type,permanent}]}

{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}}"}

Crash dump was written to: erl_crash.dump

Kernel pid terminated (application_controller) ({application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}})

 

 

 

使用如下ok,不加引号可以。似乎必须用@符号和合理的hostname

erl -name "chenpeng@192.168.1.2" -setcookie baeeq

但在window上如果将双引号改为单引号则会出现error,linux没有错误

 

----------------------------------------------------------------------------------

以上处理erl -name...能通过,但是在Eshell控制台进行远程函数调用会有问题:

 


整个执行过程如下:

----------方案1

chinpeng@baeeq$ erl -name baeeq2 -setcookie baeeq

(baeeq2@baeeq.Datalink)1>

(以上执行通过)

 

 

chenpeng@chenpeng$ erl -name baeeq2 -setcookie baeeq

(baeeq2@baeeq.Datalink)1>erl -name baeeq1 -setcookie baeeq

{error_logger,{{2010,4,4},{0,7,19}},"Can't set long node name!/nPlease check your configuration/n",[]}

{error_logger,{{2010,4,4},{0,7,19}},crash_report,[[{initial_call,{net_kernel,init,['Argument__1']}},{pid,<0.21.0>},{registered_name,[]},{error_info,{exit,{error,badarg},[{gen_server,init_it,6},{proc_lib,init_p_do_apply,3}]}},{ancestors,[net_sup,kernel_sup,<0.8.0>]},{messages,[]},{links,[<0.18.0>]},{dictionary,[{longnames,true}]},{trap_exit,true},{status,running},{heap_size,1597},{stack_size,24},{reductions,899}],[]]}

{error_logger,{{2010,4,4},{0,7,19}},supervisor_report,[{supervisor,{local,net_sup}},{errorContext,start_error},{reason,{'EXIT',nodistribution}},{offender,[{pid,undefined},{name,net_kernel},{mfa,{net_kernel,start_link,[[baeeq1,longnames]]}},{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}

{error_logger,{{2010,4,4},{0,7,19}},supervisor_report,[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,shutdown},{offender,[{pid,undefined},{name,net_sup},{mfa,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}

{error_logger,{{2010,4,4},{0,7,19}},std_info,[{application,kernel},{exited,{shutdown,{kernel,start,[normal,[]]}}},{type,permanent}]}

{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}}"}

Crash dump was written to: erl_crash.dump

Kernel pid terminated (application_controller) ({application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}})

(以上执行失败)

 

 


 

 

----------方案2

chinpeng@baeeq$ erl -name baeeq2@localhost -setcookie baeeq

(baeeq2@localhost)1>

(baeeq2@localhost)1> c(kvs).

{ok,kvs}

(baeeq2@localhost)2> kvs:start().

true

(以上执行通过)

 

chenpeng@chenpeng$ erl -name baeeq1@localhost -setcookie baeeq

(baeeq1@localhost)1>

(baeeq1@localhost)1> c(kvs).

{ok,kvs}

 

--方案2.1

(baeeq1@localhost)2> rpc:call(baeeq2@baeeq, kvs, store, [a1,a2]).

=ERROR REPORT==== 4-Apr-2010::00:17:18 ===

** System running to use fully qualified hostnames **

** Hostname baeeq is illegal **

{badrpc,nodedown}

 

--方案2.2

(baeeq1@localhost)3> rpc:call(baeeq2@192.168.1.2, kvs, store, [a1,a2]).

* 1: syntax error before: 168.1

(以上执行RPC调用时未通过,注/etc/hosts中的DNS已经配置)

 

 

 


----------方案3

chinpeng@baeeq:~/erlangWorkspace/concurrent$ erl -sname baeeq2 -setcookie baeeq

(baeeq2@baeeq)1>

(baeeq2@baeeq)1> c(kvs).

{ok,kvs}

(baeeq2@baeeq)2> kvs:start().

true

(baeeq2@baeeq)3> kvs:lookup(a1).   %%store之后才能lookup

{ok,a2}

chenpeng@chenpeng:~/erlangWorkspace/concurrent$ erl -sname baeeq1 -setcookie baeeq

(baeeq1@chenpeng)1>

(baeeq1@chenpeng)1> c(kvs).

{ok,kvs}

(baeeq1@chenpeng)2> rpc:call(baeeq2@baeeq, kvs, store, [a1, a2]).

true

(baeeq1@chenpeng)3> rpc:call(baeeq2@baeeq, kvs, lookup, [a1]).    

{ok,a2}

(以上执行RPC调用时通过)

 

方案2中为什么在不同机器(本文通过虚拟机模拟)中不能通过,原因不明,有待研究。

但是根据官方资料说:

  以-name参数启动Erlang。如果在同一台机器上启动两个节点,使用-sname,但是如果它们运行在不同的网络上,就需要使用-name.

  如果两台机器都在同一个子网内工作,也可以使用-sname.

  换言之,只有在不需要DNS服务的情况下,才能使用-name.

 

 

 

附录:kvs.erl

-module(kvs).

-compile(export_all).

start() -> register(kvs, spawn(fun() -> loop() end)).

store(Key, Value) -> rpc({store, Key, Value}).

lookup(Key) -> rpc({lookup, Key}).

rpc(Q) -> 

kvs ! {self(), Q},

receive

{kvs, Reply} -> Reply

end.

loop() ->

receive

{From, {store, Key, Value}} ->

put(Key, {ok, Value}),

From ! {kvs, true},

loop();

{From, {lookup, Key}} ->

From ! {kvs, get(Key)},

loop()

end.

 

 

环境:

 

chinpeng@baeeq  ubuntu9.10 192.168.1.2

 

chenpeng@chenpeng ubuntu9.10 192.168.1.3 (安装与hostname名为chenpeng系统的虚拟机中)

 

erl环境都为:

 

Erlang R13B01 (erts-5.7.2) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

 

Eshell V5.7.2  (abort with ^G)

 

 

 

 

 

 

 

 

最后

以上就是乐观棒棒糖为你收集整理的在局域网内启动节点时的“Can't set long node name”异常的全部内容,希望文章能够帮你解决在局域网内启动节点时的“Can't set long node name”异常所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部