我用分布式的erlang应用程序付款.
配置和想法来自:
http:/www.erlang.org/doc/pdf/otp-system-documentation.pdf 9.9.分布式应用
配置文件:
[{kernel,
[{distributed,[{wd,5000,['n1@a2-X201',{'n2@a2-X201','n3@a2-X201'}]}]},
{sync_nodes_mandatory,['n2@a2-X201','n3@a2-X201']},
{sync_nodes_timeout,5000}
]}
,{sasl, [
%% All reports go to this file
{sasl_error_logger,{file,"/tmp/wd_n1.log"}}
]
}].
[{kernel,
[{distributed,[{wd,5000,['n1@a2-X201',{'n2@a2-X201','n3@a2-X201'}]}]},
{sync_nodes_mandatory,['n1@a2-X201','n3@a2-X201']},
{sync_nodes_timeout,5000}
]
}
,{sasl, [
%% All reports go to this file
{sasl_error_logger,{file,"/tmp/wd_n2.log"}}
]
}].
现在在3个独立的终端启动erlang:
在每个erlang节点上启动应用程序:*application:start(wd).
(n1@a2-X201)1> application:start(wd). =INFO REPORT==== 19-Jun-2011::15:42:51 === wd_plug_server starting... PluginId: 4 Path: "/home/a2/src/erl/data/SIG" FileMask: "(?i)(.*)\\.SIG$" ok
(n2@a2-X201)1> application:start(wd). ok (n2@a2-X201)2>
(n3@a2-X201)1> application:start(wd). ok (n3@a2-X201)2>
一切都好的.如Erlang文档中所述:应用程序在节点n1 @ a2-X201上运行
现在kill节点n1:应用程序已迁移到n2
(n2@a2-X201)2> =INFO REPORT==== 19-Jun-2011::15:46:28 === wd_plug_server starting... PluginId: 4 Path: "/home/a2/src/erl/data/SIG" FileMask: "(?i)(.*)\\.SIG$"
继续我们的游戏:kill node n2 再一次系统工作正常.我们在节点n3处有我们的应用程序
(n3@a2-X201)2> =INFO REPORT==== 19-Jun-2011::15:48:18 === wd_plug_server starting... PluginId: 4 Path: "/home/a2/src/erl/data/SIG" FileMask: "(?i)(.*)\\.SIG$"
现在恢复节点n1和n2.所以:
Erlang R14B (erts-5.8.1) [source] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.1 (abort with ^G) (n1@a2-X201)1> Eshell V5.8.1 (abort with ^G) (n2@a2-X201)1>
节点n1 和n2又回来了.
看起来现在我必须手动重启应用程序:*让我们先在节点n2处执行:
(n2@a2-X201)1> application:start(wd).
(n1@a2-X201)1> application:start(wd). =INFO REPORT==== 19-Jun-2011::15:55:43 === wd_plug_server starting... PluginId: 4 Path: "/home/a2/src/erl/data/SIG" FileMask: "(?i)(.*)\\.SIG$" ok (n1@a2-X201)2>
有用.节点n2也返回OK:
Eshell V5.8.1 (abort with ^G) (n2@a2-X201)1> application:start(wd). ok (n2@a2-X201)2>
在节点n3,我们看到:
=INFO REPORT==== 19-Jun-2011::15:55:43 ===
application: wd
exited: stopped
type: temporary
通常,除了在节点n2处启动应用程序的延迟之外,一切看起来都不错,如文档中所述.
现在再次杀死节点n1:
(n1@a2-X201)2> User switch command --> q [a2@a2-X201 releases]$
行动......一切都挂了.应用程序未在另一个节点重新启动.
实际上,当我写这篇文章时,我意识到有时候一切都好了,有时候我有问题.
任何想法,虽然恢复"主要"节点时可能会出现问题并再次杀死它?
您所看到的奇怪现象很可能与您在节点 n1/n2 上完全重新启动应用程序有关,而 n3 仍在初始应用程序初始化下运行。
如果您的应用程序启动任何系统范围的进程并使用它们的 pid,而不是使用全局设置的注册名称,例如 pg 或 pg2,那么您可能正在使用两组全局状态。
如果是这种情况,建议采取的方法是专注于从现有应用程序中添加/删除节点,而不是重新启动整个应用程序。通过这种方式,节点可以离开并加入到一组现有的初始化值中。
| 归档时间: |
|
| 查看次数: |
964 次 |
| 最近记录: |