标签:
一直纠结于R的大数据计算问题,希望可以找到一个彻底的方案解决它。而云服务器当然是解决这个问题的最佳方案,所以,至少从这方面入手。
R的云服务器部署有两种解决方案,一种是使用R语言的并行计算,另外一种是使用RHadoop框架。
RHadoop框架其实就是M / R 算法的R语言实现,需要使用者有M / R的计算基础,和R语言平常使用的计算方式有很大的不同,因此,我采用的解决方案是搭建R 的并行计算集群。
在两台IP地址不同的Linux机器上面安装好R,然后每台机器都安装snow包,最后注意一点是,需要配置ssh的免密码登录,不同的linux用户需要配置自己的免密码登录,并且,需要用到R集群的用户都需要使用自己的账户安装snow包。
以下是测试代码:
library(snow);
workerList <- list(
list(host = "192.168.1.100", port = 10187, outfile = "~/log1.log", rshcmd = "ssh -p 22222"),
list(host = "192.168.1.101", port = 10187, outfile = "~/log2.log", rshcmd = "ssh -p 22222"),
list(host = "192.168.1.101", port = 10187, outfile = "~/log3.log", rshcmd = "ssh -p 22222")
);
cl <- makeCluster(workerList, type="SOCK", master="192.168.1.100")
stopCluster(cl);
代码解释:
1、配置每台服务器的属性
list(host = "192.168.1.100", port = 10187, outfile = "~/log1.log", rshcmd = "ssh -p 22222")
服务器的配置选项如下:
名称 |
类型 |
描述 |
默认值 |
port |
integer |
R使用的集群的端口 |
10187 |
timeout |
integer |
服务器之间链接超时时间 |
31536000(一年) |
master |
string |
集群主机IP(或者域名) |
Sys.info()["nodename"] |
type |
string |
服务器之间连接类型 |
NULL |
outfile |
string |
日记输出的文件路径 |
NULL |
user |
string |
服务器用户名 |
Sys.info()["user"] |
rshcmd |
string |
SSH执行命令 |
ssh |
rlibs |
string |
服务器上R的安装路径 |
$R_LIBS |
scriptdir |
string |
snow安装包的安装路径 |
|
rprog |
string |
R程序的执行路径 |
$R_HOME/bin/R |
snowlib |
string |
snow安装包的路径 |
|
rscript |
string |
R脚本所在路径 |
$R_HOME/bin/Rscript |
|
|
|
|
以上为R集群中的各个服务器的常用配置参数列表。
2、根据配置,创建R语言并行计算集群,master指明主节点,这个在我实践的过程中是必须配置的。
cl <- makeCluster(workerList, type="SOCK", master="192.168.180.216")
3、运算结束后,关闭集群机器
stopCluster(cl);
R语言中的并行计算——搭建R的集群
标签:
原文地址:http://www.cnblogs.com/Sky-Yanjun/p/4968308.html