在AWS上使用Rserve在Node.js和R之间进行跨平台通信时出错。 错误:连接ETIMEDOUT

我想将我的R脚本从node.js应用程序传递到运行Ubuntu和Rserve的Amazon EC2实例; 然后执行并评估R脚本并将处理后的输出返回到我的node.js应用程序。

我发现了两个可靠的select:
1) RIO – (使用这个)
2) rserve-client

在继续与Rserve连接之前,我确定它已经启动并正在运行。

ubuntu@ip-172-31-37-254:~$ sudo netstat -nltp|grep Rserve tcp 0 0 0.0.0.0:6311 0.0.0.0:* LISTEN 5978/Rserve 

为Rserve启用远程连接参数并成功启动。

 library(Rserve) Rserve(args="--RS-enable-remote") Starting Rserve: /usr/lib/R/bin/R CMD /usr/local/lib/R/site-library/Rserve/libs//Rserve --RS-enable-remote R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" Copyright (C) 2013 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. During startup - Warning message: Setting LC_CTYPE failed, using "C" Rserv started in daemon mode. 

1)从我的Node.js应用程序尝试使用RIO包的testing脚本

 var rio = require("rio"); console.log("Connecting.."); rio.e({ host : "ec2-52-40-113-159.us-west-2.compute.amazonaws.com", port : "6311", command: "pi / 2 * 2", callback: function (err, res) { if (!err) { console.log(res); } else { console.log("Rserve call failed. " + err); } } // path :"/usr/local/lib/R/site-library" }); 

注意:如上所述,我已经相应地更新了主机参数。

运行应用程序时出错:

 node app.js Connecting.. Rserve call failed. Error: connect ETIMEDOUT 52.40.113.159:6311 

我不确定,为什么我无法连接。 有没有我失踪的步骤? 如果有任何替代的软件包或完成此任务的方式,也将不胜感激。 谢谢。

您的使用案例中的问题是您的安全组中没有打开正确的端口。

您将不得不在EC2安全组中打开端口6311和5978,问题将消失。

您可以将以下规则添加到EC2安全组,而不是将端口6311和5878设置为开放。

 Type: Custom TCP Rule, Protocol: TCP, Port Range: 6311, Source: Node.js Server IP Type: Custom TCP Rule, Protocol: TCP, Port Range: 5978, Source: Node.js Server IP