Erlang epmd的角色以及使用
浏览:2043次 出处信息
很多同学误会了epmd的作用,认为epmd就是erlang集群的协议,我来澄清下:
Epmd是Erlang Port Mapper Daemon的缩写,在Erlang集群中的作用相当于dns的作用,提供节点名称到端口的查询服务,epmd绑定在总所周知的4369端口上。
epmd文档:这里
epmd协议:这里
Erlang的节点名称是类似这样的foo@ip的格式,当一个节点启动的时候,首先会在本机启动epmd,同时把自己的节点名称和节点监听的tcp端口登记在上面。
看代码:
// erlexec.c ... case 'n': if (strcmp(argv[i], "-name") == 0) { /* -name NAME */ if (i+1 >= argc) usage("-name"); /* * Note: Cannot use add_args() here, due to non-defined * evaluation order. */ add_arg(argv[i]); add_arg(argv[i+1]); isdistributed = 1; i++; ... case 's': /* -sname NAME */ if (strcmp(argv[i], "-sname") == 0) { if (i+1 >= argc) usage("-sname"); add_arg(argv[i]); add_arg(argv[i+1]); isdistributed = 1; i++; } ... if (isdistributed && !no_epmd) start_epmd(epmd_prog); ...
我们可以透过erl -epmd EPMD_PROG来传入不同的参数。
再看下实验:
$erl -sname a $erl -sname b $erl -sname c $ ps -ef|grep epmd membase 4592 1 0 Aug25 ? 00:00:39 /usr/local/bin/epmd -daemon ... $ netstat -an|grep 4369 tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN $ epmd -names epmd: up and running on port 4369 with data: name c at port 4096 name b at port 4097 name a at port 4098 ... $erl -sname x Erlang R14B04 (erts-5.8.5) 1 [64-bit] [smp:16:16] [rq:16] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.5 (abort with ^G) (x@my031091)1> erl_epmd:port_please(x, "127.0.0.1"). {port,34625,5} (x@my031091)2> erl_epmd:names(). {ok,[{"a",4096},{"b",4097},{"c",4098},{"x",34625}]}
kernel的erl_epmd模块提供epmd协议的封装.
那么如果要连接其他节点的时候,就取出节点名称的ip部分,透过erl_epmd建立连接到ip:4369,通过epmd协议来查询想要的foo的端口,然后再用ip:port去连接真正的服务。
新版本的epmd提供了强行移除名称的功能,避免由于erlang虚拟机由于某种原因crash,没有注销名字,导致无法再使用这个名字。
要使用stop功能,epmd必须以 -relaxed_command_check 启动,具体参考epmd -help
演示下:
$ erl -sname x -epmd "epmd -relaxed_command_check -daemon" Erlang R14B04 (erts-5.8.5) 1 [64-bit] [smp:16:16] [rq:16] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.5 (abort with ^G) (x@my031089)1> $ epmd -names epmd: up and running on port 4369 with data: name x at port 58953 $ epmd -stop x STOPPED $ epmd -names epmd: up and running on port 4369 with data:
我们看到名称已经抢先移除成功。
建议继续学习:
- Erlang match_spec引擎介绍和应用 (阅读:4451)
- whatsapp深度使用Erlang有感 (阅读:4427)
- php-erlang (阅读:4257)
- gen_tcp调用进程收到{empty_out_q, Port}消息奇怪行为分析 (阅读:3494)
- hibernate使用注意事项 (阅读:3153)
- Erlang linkin driver用port_control方式时的一些经验分享 (阅读:2916)
- Erlang如何限制节点对集群的访问之net_kernel:allow (阅读:2843)
- ERLANG OTP源码分析 – gen_server (阅读:2828)
- erlang学习手记 (阅读:2661)
- gen_tcp容易误用的一点解释 (阅读:2582)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
扫一扫订阅我的微信号:IT技术博客大学习
<< 前一篇:编程珠玑番外篇-K. Plan 9 的故事(修订版)
后一篇:微博招人的玩法 >>
文章信息
- 作者:Yu Feng 来源: Erlang非业余研究
- 标签: epmd Erlang
- 发布时间:2011-10-23 21:28:02
建议继续学习
近3天十大热文
- [12] 逃出你的肖申克(五):看不见的牢笼(上)
- [10] linux 简单架设防火墙路由器
- [9] [Perl]Moose::Manual::T
- [8] 分布式系统的事务处理
- [8] 关于不得不在python中使用代理访问网络的
- [8] 位置服务类产品的用户状态和地点管理设想
- [8] 怎样获取PHP变量的变量名之PHP实现
- [8] YSLOW法则中,为什么yahoo推荐用GE
- [8] Eclipse开发Android应用程序入门
- [8] 浅述各平台系统交互设计的不同关注点