Erlang epmd的角色以及使用
2013-06-07 13:44
288 查看
转载自yufeng.info
很多同学误会了epmd的作用,认为epmd就是erlang集群的协议,我来澄清下:
Epmd是Erlang Port Mapper Daemon的缩写,在Erlang集群中的作用相当于dns的作用,提供节点名称到端口的查询服务,epmd绑定在总所周知的4369端口上。
epmd文档:http://www.erlang.org/doc/man/epmd.html
epmd协议:http://www.erlang.org/doc/apps/erts/erl_dist_protocol.html
Erlang的节点名称是类似这样的foo@ip的格式,当一个节点启动的时候,首先会在本机启动epmd,同时把自己的节点名称和节点监听的tcp端口登记在上面。
看代码:
我们可以透过erl -epmd EPMD_PROG来传入不同的参数。
再看下实验:
epmd是个标准的tcp服务器,它的协议如下:
kernel的erl_epmd模块提供epmd协议的封装,向net_kernel模块提供服务。如果net_kernel要连接其他节点的时候,就取出节点名称的ip部分,透过erl_epmd建立连接到ip:4369,通过epmd协议来查询想要的foo的端口,然后再用ip:port去连接真正的服务。
新版本的epmd提供了强行移除名称的功能,避免由于erlang虚拟机由于某种原因crash,没有注销名字,导致无法再使用这个名字。
要使用stop功能,epmd必须以 -relaxed_command_check 启动,具体参考epmd –help
演示下:
我们看到名称已经抢先移除成功。
祝玩得开心!
很多同学误会了epmd的作用,认为epmd就是erlang集群的协议,我来澄清下:
Epmd是Erlang Port Mapper Daemon的缩写,在Erlang集群中的作用相当于dns的作用,提供节点名称到端口的查询服务,epmd绑定在总所周知的4369端口上。
epmd文档:http://www.erlang.org/doc/man/epmd.html
epmd协议:http://www.erlang.org/doc/apps/erts/erl_dist_protocol.html
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}]}
epmd是个标准的tcp服务器,它的协议如下:
kernel的erl_epmd模块提供epmd协议的封装,向net_kernel模块提供服务。如果net_kernel要连接其他节点的时候,就取出节点名称的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 epmd的角色以及使用
- Erlang epmd的角色以及使用(转载自系统技术非业余研究)
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(23)-设置角色遗留问题和为权限设置角色以及EasyUI Tabs的使用
- erlang的dialyzer使用中遇到的问题,以及解决方法
- 使用unity3d搭建简单的场景以及第一人称角色的控制
- 数据库安全性之使用命令来实现用户管理以及角色.十五
- 简单两步快速实现shiro的配置和使用,包含登录验证、角色验证、权限验证以及shiro登录注销流程
- 使用C语言和DX库编写东方风格的STG射击游戏--------第一章--------创建基本界面以及可以移动的角色
- Mongodb 权限控制以及角色使用
- actors角色模型系列之一 actors介绍以及akka 框架的使用入门
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(23)-设置角色遗留问题和为权限设置角色以及EasyUI Tabs的使用
- 简单两步快速实现shiro的配置和使用,包含登录验证、角色验证、权限验证以及shiro登录注销流程(基于spring的方式,使用maven构建)
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(23)-设置角色遗留问题和为权限设置角色以及EasyUI Tabs的使用
- Erlang虚拟机内存使用问题以及监控
- 设置角色遗留问题和为权限设置角色以及EasyUI Tabs的使用
- QuickCSharp框架开发(20)------授权部分的代码以及如何使用授权 添加用户、角色与分配资源部分的代码暂且省略
- oracle 10g 管理权限和角色,以及有关方面的数据字典的使用方法总结
- [Unity&特效]使用Projector投影仪来制作角色脚下的特效圆环以及技能指示器skill indicator
- (zz)actors角色模型系列之一 actors介绍以及akka 框架的使用入门
- Ueditor使用以及遇到的问题