`
litaocheng
  • 浏览: 333539 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Erlang节点short names 和long names

阅读更多

erl node启动方法

short name:

longname:

说明:

Name :: atom() || string()
ShortHost :: atom() || string(), 不可含有"."。比如"myhost"
FullHost :: [ShortHost()] || Ip, 比如"test.mydomain.com"和"8.34.135.3"

short name 和 long name主要为格式上的区别,long name中Host如果为域名,需要进行DNS解析。

我们也可以在hosts中添加类似:

ip ShotHost

的Entry使shortname name节点支持其他主机(请参考后面介绍)

 

Note

注意,shot name的节点和long name的节点不能互相通信。

示例

short name:

假设本机/etc/hosts配置为:8.27.86.135 da6600.fb.joyent.us

erl -sname cheng % 启动了一个名叫:cheng@da6600 的Node

erl -name cheng % 启动了一个名叫:cheng@da6600.fb.joyent.us 的Node

如果我们的本机hosts配置中,没有指定域名,那么需要我们指定Host:

erl -sname cheng@da6600 % 启动了一个名叫:cheng@da6600的Node

 

long name:

erl -name cheng@da6600

erl -name cheng@da6600.fb.joyent.us

erl -name cheng@8.27.86.135

请注意,此3个longname Node是同一个Node

应用

很多资料中,当进行分布式程序开发时,需要经历下面的步骤

  1. 本机单个节点进行测试,
  2. 本机多个节点进行测试,
  3. 多台主机进行接近真实环境的测试

其中第2步,常常是使用 erl -sname Name 类似的方法,产生Node, 因此我们印象中,好像sname只能是在本机的情况下使用?

通常情况下,shortname是限于本机的多个节点,longname可以跨越多台主机(通过IP,DNS解析)。

当然我们也可以像使用long name Node一样,使用short name Node。不同的是long name可以通过DNS进行解析, 而short name必须手动的在hosts中添加对应的映射。这样做的目的就是将本地的请求转发到目标的主机。

好了让我们使用short name来试验一下

server1(ip:8.27.86.135)

启动node:

erl -sname foo@server1

server2(server2也可以在内网当中,此时链接只能由server2发起)

/etc/hosts中添加:

8.27.86.135 server1

随后启动node:

erl -sname bar

> net_kernel:connect_node('foo@server1').
true
> nodes().
> [foo@server1]

这样,两个节点就已经链接了。

同理,我们也可以在server1中添加一个条目,为server2其一个ShortName,随后连接它。

到此,对于short name, long name的使用应该比较清晰了。

分享到:
评论
2 楼 mryufeng 2009-02-11  
-sname Name
    Makes the Erlang runtime system into a distributed node, similar to -name, but the host name portion of the node name Name@Host will be the short name, not fully qualified.
    This is sometimes the only way to run distributed Erlang if the DNS (Domain Name System) is not running. There can be no communication between nodes running with the -sname flag and those running with the -name flag, as node names must be unique in distributed Erlang systems.


-name Name
    Makes the Erlang runtime system into a distributed node. This flag invokes all network servers necessary for a node to become distributed. See net_kernel(3). It is also ensured that epmd runs on the current host before Erlang is started. See epmd(1).
    The name of the node will be Name@Host, where Host is the fully qualified host name of the current host. For short names, use the -sname flag instead.


用途和差别这里说的很明白!

http://blog.yufeng.info
1 楼 djw_posion 2009-02-06  
看了此文章,终于明白shoertname和longname的区别了,十分感谢!  

相关推荐

Global site tag (gtag.js) - Google Analytics