如果想要在spark上使用sparkR必须首先在集群的所有机器上安装R包,前面有安装过R.3.2.1,但是因为很多R包不支持,所以更新为3.3.1。
1、安装依赖
yum
install
gcc
yum
install
gcc-c++
yum
install
gcc-gfortran
yum
install
pcre-devel
yum
install
tcl-devel
yum
install
zlib-devel
yum
install
bzip2
-devel
yum
install
libX11-devel
yum
install
readline-devel
#否则报”–with-readline=yes (default) and headers/libs are not available”错误
yum
install
libXt-devel
#否则报”configure: error: –with-x=yes (default) and X11 headers/libs are not available”错误
yum
install
tk-devel
yum
install
tetex-latex
yum -y install libcurl libcurl-devel
2、 编译
下载R包解压缩
进入/usr/local/program/R-3.3.1/ 目录下,执行
./configure
1、报错 checking if zlib version >= 1.2.5... no
checking whether zlib support suffices... configure: error: zlib library and headers are required
解决:
tar xvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure --prefix=/opt/zlib-1.2.8
make && make install
2、报错checking if zlib version >= 1.2.5... no
checking whether zlib support suffices... configure: error: zlib library and headers are required
解决:
首先:rm -vf /usr/bin/bz*
1、tar zxf bzip2-1.0.6.tar.gz
2、make -f Makefile-libbz2_so #-f 标志是使bzip2 根据另一个Makefile来编译,就是Makefile-libbz2_so文件,创建一个动态的libbz.so库文件,然后把bzip2工具连接到这个库上
3、make clean
4、 make
5、make install PREFIX=/opt/bzip2-1.0.6
6、./configure --prefix=/opt/R-3.3.1 --enable-R-shlib LDFLAGS="-L/opt/zlib-1.2.8/lib -L/opt/bzip2-1.0.6/lib -L/opt/xz-5.2.2/lib " CPPFLAGS="-I/opt/zlib-1.2.8/include -I/opt/bzip2-1.0.6/include -I/opt/xz-5.2.2/include "
3、报错
checking whether bzip2 support suffices... no
checking for lzma_version_number in -llzma... no
configure: error: "liblzma library and headers are required"
解决:wget http://tukaani.org/xz/xz-5.2.2.tar.gz --no-check-certificat
rm -vf /usr/bin/xz*
tar xzvf xz-5.2.2.tar.gz
cd xz-5.2.2
./configure --prefix=/opt/xz-5.2.2
make -j3 && make install
./configure --prefix=/opt/R-3.3.1 --enable-R-shlib LDFLAGS="-L/opt/zlib-1.2.8/lib -L/opt/bzip2-1.0.6/lib -L/opt/xz-5.2.2/lib " CPPFLAGS="-I/opt/zlib-1.2.8/include -I/opt/bzip2-1.0.6/include -I/opt/xz-5.2.2/include "
4、报错 if PCRE version >= 8.10, < 10.0 and has UTF-8 support... no
解决:
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
tar xzvf pcre-8.39.tar.gz
./configure --prefix=/opt/pcre-8.39
make -j3 && make install
./configure --prefix=/opt/R-3.3.1 --enable-R-shlib LDFLAGS="-L/opt/zlib-1.2.8/lib -L/opt/bzip2-1.0.6/lib -L/opt/xz-5.2.2/lib -L/opt/pcre-8.39/lib " CPPFLAGS="-I/opt/zlib-1.2.8/include -I/opt/bzip2-1.0.6/include -I/opt/xz-5.2.2/include -I/opt/pcre-8.39/include "
仍然报错
checking if PCRE version >= 8.10, < 10.0 and has UTF-8 support... no
checking whether PCRE support suffices... configure: error: pcre >= 8.10 library and headers are required
CRE需要安装--enable-utf8
重新安装pcre
cd /pcre-8.39
./configure --prefix=/opt/pcre-8.39 --enable-utf8
make -j3 && make install
./configure --prefix=/opt/R-3.3.1 --enable-R-shlib LDFLAGS="-L/opt/zlib-1.2.8/lib -L/opt/bzip2-1.0.6/lib -L/opt/xz-5.2.2/lib -L/opt/pcre-8.39/lib " CPPFLAGS="-I/opt/zlib-1.2.8/include -I/opt/bzip2-1.0.6/include -I/opt/xz-5.2.2/include -I/opt/pcre-8.39/include "
5、报错 checking if libcurl is version 7 and >= 7.28.0... no
configure: error: libcurl >= 7.28.0 library and headers are required with support for https
wget --no-check-certificate https://curl.haxx.se/download/curl-7.47.1.tar.gz
tar xzvf curl-7.47.1.tar.gz
cd curl-7.47.1
./configure --prefix=/opt/curl-7.47.1
make -j3 && make install
./configure --prefix=/opt/R-3.3.1 --enable-R-shlib LDFLAGS="-L/opt/zlib-1.2.8/lib -L/opt/bzip2-1.0.6/lib -L/opt/xz-5.2.2/lib -L/opt/pcre-8.39/lib -L/opt/curl-7.47.1/lib " CPPFLAGS="-I/opt/zlib-1.2.8/include -I/opt/bzip2-1.0.6/include -I/opt/xz-5.2.2/include -I/opt/pcre-8.39/include -I/opt/curl-7.47.1/include "
成功然后进入R的安装目录下执行:
make && make install
6、报错
/usr/bin/ld: warning: libpcre.so.1, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: liblzma.so.5, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
此处报错是由于没有找到动态库,看第一二行
解决方法:添加动态库
vi /etc/ld.so.conf 添加pcre和xz
include ld.so.conf.d/*.conf
/opt/pcre-8.39/lib
/opt/xz-5.2.2/lib
然后执行
#ldconfig
进入R的安装目录下执行:
make && make install
7、报错
version.o g_alab_her.o g_cntrlify.o g_fontdb.o g_her_glyph.o xxxpr.o `ls ../unix/*.o ../appl/*.o ../nmath/*.o` ../extra/tre/libtre.a -L../../lib -lRblas -lgfortran -lm -lreadline -lpcre -llzma -lbz2 -lz -lrt -ldl -lm
/usr/bin/ld: /opt/bzip2-1.0.6/lib/libbz2.a(bzlib.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/opt/bzip2-1.0.6/lib/libbz2.a: could not read symbols: Bad value
collect2: ld 返回 1
make[3]: *** [libR.so] 错误 1
make[3]: Leaving directory `/usr/local/program/R-3.3.1/src/main'
make[2]: *** [R] 错误 2
make[2]: Leaving directory `/usr/local/program/R-3.3.1/src/main'
make[1]: *** [R] 错误 1
make[1]: Leaving directory `/usr/local/program/R-3.3.1/src'
make: *** [R] 错误 1
解决方法:
vi /usr/local/program/bzip2-1.0.6/Makefile 的CFLAGS 行修改为
CFLAGS=-Wall -fPIC -Winline -O2 -g $(BIGFILES)
3、make clean
4、 make
5、make install PREFIX=/opt/bzip2-1.0.6
进入R的安装目录下执行:
make && make install
成功
进入spark所在的目录下执行 ./bin/sparkR即可
vim /etc/profile ##添加R源环境变量
export PATH=$PATH:$JAVA_HOME/bin:/usr/local/program/R-3.3.1/bin
source /etc/profile ##让环境变量立马生效
参考:
http://pj.freefaculty.org/blog/?p=315
http://www.bubuko.com/infodetail-1742059.html
8、报错 env: R: 没有那个文件或目录
是因为执行sparkR的时候会到/usr/bin下面找执行文件,找到执行文件创建个软链接即可
ln -s /usr/local/program/R-3.3.1/bin/R /usr/bin/R