Loading

在阿里云ECS上安装大数据环境

之前疫情在家,参加了阿里云的在家云实践,白嫖了半年的云服务器,感觉体验还不错。最近阿里云又搞活动,1vCPU,2G内存的主机一年只要94,忍不住又冲了一波,用来装个完整的大数据环境。大致顺序如下:

  1. 安装Java
  2. 安装Hadoop 3.1.3
  3. 安装Anaconda3
  4. 安装Scala 2.11.12
  5. 安装Spark 2.4.0
  6. 安装sbt 0.13.11
  7. 安装Kafka 0.10.2.0

主要参考林子雨老师的博客,剩下的HBase,Hive啥的,以后有时间再慢慢配置。这里记录一下安装过程中出现的问题。

查看Hadoop版本报错

Java环境变量已经配置完成后,安装Hadoop 3.1.3,查看版本时报错。

./bin/hadoop version
ERROR: JAVA_HOME is not set and could not be found.

检查环境变量:

java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

echo $JAVA_HOME
/usr/lib/jvm/jdk1.8.0_162

都是正常的,但是Hadoop还是无法找到Java。查了一下还需要在../hadoop/etc/hadoop/hadoop-env.sh中声明Java的路径。

cd /usr/local/hadoop/etc/
vim hadoop-env.sh

在里面加上export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_162,再次运行查看版本的命令就成功了。

./bin/hadoop version
Hadoop 3.1.3
Source code repository https://gitbox.apache.org/repos/asf/hadoop.git -r ba631c436b806728f8ec2f54ab1e289526c90579
Compiled by ztang on 2019-09-12T02:47Z
Compiled with protoc 2.5.0
From source with checksum ec785077c385118ac91aadde5ec9799
This command was run using /usr/local/hadoop/share/hadoop/common/hadoop-common-3.1.3.jar

启动Scala shell报错

安装完Scala,一启动就报错,淦!!!!!!!!!

./bin/scala
Welcome to Scala 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_162).
Type in expressions for evaluation. Or try :help.
[ERROR] Failed to construct terminal; falling back to unsupported
java.lang.NumberFormatException: For input string: "0x100"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:580)
        at java.lang.Integer.valueOf(Integer.java:766)
        at jline.internal.InfoCmp.parseInfoCmp(InfoCmp.java:59)
        at jline.UnixTerminal.parseInfoCmp(UnixTerminal.java:242)
        at jline.UnixTerminal.<init>(UnixTerminal.java:65)
        at jline.UnixTerminal.<init>(UnixTerminal.java:50)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at jline.TerminalFactory.getFlavor(TerminalFactory.java:211)
        at jline.TerminalFactory.create(TerminalFactory.java:102)
        at jline.TerminalFactory.get(TerminalFactory.java:186)
        at jline.TerminalFactory.get(TerminalFactory.java:192)
        at jline.console.ConsoleReader.<init>(ConsoleReader.java:243)
        at jline.console.ConsoleReader.<init>(ConsoleReader.java:235)
        at jline.console.ConsoleReader.<init>(ConsoleReader.java:223)
        at scala.tools.nsc.interpreter.jline.JLineConsoleReader.<init>(JLineReader.scala:64)
        at scala.tools.nsc.interpreter.jline.InteractiveReader.<init>(JLineReader.scala:33)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$scala$tools$nsc$interpreter$ILoop$$instantiater$1$1.apply(ILoop.scala:858)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$scala$tools$nsc$interpreter$ILoop$$instantiater$1$1.apply(ILoop.scala:855)
        at scala.tools.nsc.interpreter.ILoop.scala$tools$nsc$interpreter$ILoop$$mkReader$1(ILoop.scala:862)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$22$$anonfun$apply$10.apply(ILoop.scala:873)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$22$$anonfun$apply$10.apply(ILoop.scala:873)
        at scala.util.Try$.apply(Try.scala:192)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$22.apply(ILoop.scala:873)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$22.apply(ILoop.scala:873)
        at scala.collection.immutable.Stream.map(Stream.scala:418)
        at scala.tools.nsc.interpreter.ILoop.chooseReader(ILoop.scala:873)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1$$anonfun$newReader$1$1.apply(ILoop.scala:893)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.newReader$1(ILoop.scala:893)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.scala$tools$nsc$interpreter$ILoop$$anonfun$$preLoop$1(ILoop.scala:897)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1$$anonfun$startup$1$1.apply(ILoop.scala:964)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:990)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:891)
        at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:891)
        at scala.reflect.internal.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:97)
        at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:891)
        at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:74)
        at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:87)
        at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:98)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:103)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

scala> 

但是好像不影响使用。修改.profile可以解决这个问题。

cd 
vim .profile
# 添加export TERM=xterm-color
source .profile

这样就解决了。但是不知道是为什么解决的,看了几个博客,都是这样那样再这样,就OK了。前几天刚安装了一遍Scala 2.11.12,那时候还好好的,这会儿就出问题了。

配置PYSPARK

pyspark的交互式环境本身不需要配置,执行以下命令就可以打开pyspark:

cd /usr/local/spark
./bin/pyspark

使用的Python版本是系统的默认Python版本,也就是你在终端中输入python打开的那一个(之前已经安装好了Anaconda3,此时用的就是Anaconda3自带的Python版本)。但是你在这个Python中却无法导入pyspark相关的包。

>>> from pyspark.sql import Row
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyspark'

需要配置环境变量,在~/.bashrc中添加以下的几行:

export HADOOP_HOME=/usr/local/hadoop
export SPARK_HOME=/usr/local/spark
export PYTHONPATH=$SPARK_HOME/python:$SPARK_HOME/python/lib/py4j-0.10.7-src.zip:$PYTHONPATH
export PYSPARK_PYTHON=python
export PATH=$HADOOP_HOME/bin:$SPARK_HOME/bin:$PATH

记得source一下让环境变量生效。这时候再去导入相关的包就不会报错了。上面那些其实也顺便配置了HadoopSpark的环境变量,理论上来说,如果你就只想用默认的Python版本跑pyspark,那只要加上PYTHONPATH的那一行就行了。

SBT换源

一开始用的是华为的源,而且似乎源也没给全,会报包下载失败的错误。想了一下我是在阿里云的服务器上,用阿里云的源大概快点?并没有

vim ~/.sbt/repositories
[repositories]
aliyun-maven-repo: https://maven.aliyun.com/repository/public
aliyun-nexus: https://maven.aliyun.com/nexus/content/groups/public/
typesafe: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
maven-central
sonatype-oss-releases
sonatype-oss-snapshots
ivy-sbt-plugin: https://dl.bintray.com/sbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

换了sbt的版本,改用sbt1.3.8,参考sbt无痛入门指南换源,速度快了很多。

Maven换源

参考将Maven源改为国内阿里云仓库

阿里云服务器安装HBase

这个有点坑,一开始完全想不到问题出在这里。打开HBase Shell,运行所有命令都会报错。

ERROR: KeeperErrorCode = NoNode for /hbase/master

说是找不到master,启动HBase之后执行jps是有HMaster的。最后检查了很久,发现HDFS中没有hbase文件夹,这时候才想起来配置hbase-site.xml的时候有个地方疏忽了。

<configuration>
    <property>
        <name>hbase.rootdir</name>
        <value>hdfs://xxx.xxx.xxx.xxx:9000/hbase</value>  
        此处要填写你的阿里云内网IP
    </property>
    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>
    <property>
        <name>hbase.unsafe.stream.capability.enforce</name>
        <value>false</value>
    </property>
</configuration>
posted @ 2020-07-03 10:13  达芬骑驴  阅读(296)  评论(1编辑  收藏  举报