Hadoop在整个大数据技术体系中占有至关重要的地位,是大数据技术的基础和敲门砖,对Hadoop基础知识的掌握程度会在一定程度决定在大数据技术的道路上能走多远。
最近想要学习Spark,首先需要搭建Spark的环境,Spark的依赖环境比较多,需要Java JDK、Hadoop的支持。我们就分步骤依次介绍各个依赖的安装和配置。新安装了一个Linux Ubuntu 18.04系统,想在此系统上进行环境搭建,详细记录一下过程。
下载之后的包放到某个目录下,此处放在/opt/java目录
linuxidc@linuxidc:~/www.linuxidc.com$ sudo cp /home/linuxidc/www.linuxidc.com/jdk-8u231-linux-x64.tar.gz /opt/java/
[sudo] linuxidc 的密码:
linuxidc@linuxidc:~/www.linuxidc.com$ cd /opt/java/
linuxidc@linuxidc:/opt/java$ ls
jdk-8u231-linux-x64.tar.gz 使用命令:tar -zxvf jdk-8u231-linux-x64.tar.gz 解压缩 linuxidc@linuxidc:/opt/java$ sudo tar -zxf jdk-8u231-linux-x64.tar.gz
linuxidc@linuxidc:/opt/java$ ls
jdk1.8.0_231 jdk-8u231-linux-x64.tar.gz
修改配置文件/etc/profile,使用命令:sudo nano /etc/profile
linuxidc@linuxidc:/opt/java$ sudo nano /etc/profile
在文件末尾增加以下内容(具体路径依据环境而定):
export JAVA_HOME=/opt/java/jdk1.8.0_231
export JRE_HOME=/opt/java/jdk1.8.0_231/jre
export PATH=${JAVA_HOME}/bin:$PATH
保存退出,在终端界面使用命令:source /etc/profile 使配置文件生效。
linuxidc@linuxidc:/opt/java$ source /etc/profile
使用java -version验证安装是否成功,以下回显表明安装成功了。
linuxidc@linuxidc:/opt/java$ java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
linuxidc@linuxidc:/opt/java$
linuxidc@linuxidc:~/www.linuxidc.com$ sudo apt-get install rsync
将下载的包放到某个目录下,此处放在/opt/hadoop
linuxidc@linuxidc:~/www.linuxidc.com$ sudo cp /home/linuxidc/www.linuxidc.com/hadoop-2.7.7.tar.gz /opt/hadoop/
使用命令:tar -zxvf hadoop-2.7.7.tar.gz 进行解压缩
此处选择伪分布式的安装方式(Pseudo-Distributed)
修改解压后的目录下的子目录文件 etc/hadoop/hadoop-env.sh,将JAVA_HOME路径修改为本机JAVA_HOME的路径,如下图:
配置Hadoop的环境变量
使用命令:
linuxidc@linuxidc:/opt/hadoop/hadoop-2.7.7/etc/hadoop$ sudo nano /etc/profile
添加以下内容:
export HADOOP_HOME=/opt/hadoop/hadoop-2.7.7
修改PATH变量,添加hadoop的bin目录进去
export PATH=${JAVA_HOME}/bin:${HADOOP_HOME}/bin:$PATH
修改解压后的目录下的子目录文件 etc/hadoop/core-site.xml
linuxidc@linuxidc:/opt/hadoop/hadoop-2.7.7/etc/hadoop$ sudo nano core-site.xml
fs.defaultFShdfs://localhost:9000
如下图:
修改解压后的目录下的子目录文件 etc/hadoop/hdfs-site.xml
linuxidc@linuxidc:/opt/hadoop/hadoop-2.7.7/etc/hadoop$ sudo nano hdfs-site.xml
dfs.replication1
如下图:
设置免密登陆
linuxidc@linuxidc:~/www.linuxidc.com$ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
Generating public/private rsa key pair.
Your identification has been saved in /home/linuxidc/.ssh/id_rsa.
Your public key has been saved in /home/linuxidc/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:zY+ELQc3sPXwTBRfKlTwntek6TWVsuQziHtu3N/6L5w linuxidc@linuxidc
The key's randomart image is:
+---[RSA 2048]----+
| . o.*+. .|
| + B o o.|
| o o =o+.o|
| B..+oo=o|
| S.*. ==.+|
| +.o .oo.|
| .o.o... |
| oo .E .|
| .. o==|
+----[SHA256]-----+
linuxidc@linuxidc:~/www.linuxidc.com$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
linuxidc@linuxidc:~/www.linuxidc.com$ chmod 0600 ~/.ssh/authorized_keys
使用命令:ssh localhost 验证是否成功,如果不需要输入密码即可登陆说明成功了。
linuxidc@linuxidc:~/www.linuxidc.com$ ssh localhost
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 5.4.0-999-generic x86_64) * Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage * Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch 188 个可升级软件包。
0 个安全更新。 Your Hardware Enablement Stack (HWE) is supported until April 2023.
Last login: Sat Nov 30 23:25:35 2019 from 127.0.0.1
接下来需要验证Hadoop的安装
a、格式化文件系统
linuxidc@linuxidc:/opt/hadoop/hadoop-2.7.7$ bin/hdfs namenode -format
19/11/30 23:29:06 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = linuxidc/127.0.1.1
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 2.7.7
......
b、启动Namenode和Datanode
linuxidc@linuxidc:/opt/hadoop/hadoop-2.7.7$ sbin/start-dfs.sh
Starting namenodes on [localhost]
localhost: starting namenode, logging to /opt/hadoop/hadoop-2.7.7/logs/hadoop-linuxidc-namenode-linuxidc.out
localhost: starting datanode, logging to /opt/hadoop/hadoop-2.7.7/logs/hadoop-linuxidc-datanode-linuxidc.out
Starting secondary namenodes [0.0.0.0]
The authenticity of host '0.0.0.0 (0.0.0.0)' can't be established.
ECDSA key fingerprint is SHA256:OSXsQK3E9ReBQ8c5to2wvpcS6UGrP8tQki0IInUXcG0.
Are you sure you want to continue connecting (yes/no)? yes
0.0.0.0: Warning: Permanently added '0.0.0.0' (ECDSA) to the list of known hosts.
0.0.0.0: starting secondarynamenode, logging to /opt/hadoop/hadoop-2.7.7/logs/hadoop-linuxidc-secondarynamenode-linuxidc.out c、浏览器访问 http://localhost:50070
下载好后解压到:/opt/scala
linuxidc@linuxidc:~/下载$ sudo tar zxf scala-2.11.8.tgz -C /opt/scala
[sudo] linuxidc 的密码:
linuxidc@linuxidc:~/下载$ cd /opt/scala
linuxidc@linuxidc:/opt/scala$ ls
scala-2.11.8 配置环境变量: linuxidc@linuxidc:/opt/scala$ sudo nano /etc/profile 添加: export SCALA_HOME=/opt/scala/scala-2.11.8
source /etc/profile
[sudo] linuxidc 的密码:
linuxidc@linuxidc:~/www.linuxidc.com$ cd /opt/spark/
linuxidc@linuxidc:/opt/spark$ ls
spark-2.4.4-bin-hadoop2.7.tgz
linuxidc@linuxidc:/opt/spark$ sudo tar -zxf spark-2.4.4-bin-hadoop2.7.tgz
[sudo] linuxidc 的密码:
linuxidc@linuxidc:/opt/spark$ ls
spark-2.4.4-bin-hadoop2.7 spark-2.4.4-bin-hadoop2.7.tgz
使用命令:./bin/run-example SparkPi 10 测试spark的安装
配置环境变量SPARK_HOME
linuxidc@linuxidc:/opt/spark/spark-2.4.4-bin-hadoop2.7$ sudo nano /etc/profile
export SPARK_HOME=/opt/spark/spark-2.4.4-bin-hadoop2.7
export PATH=${JAVA_HOME}/bin:${HADOOP_HOME}/bin:${SPARK_HOME}/bin:$PATH
source /etc/profile
配置配置spark-env.sh
进入到spark/conf/
sudo cp /opt/spark/spark-2.4.4-bin-hadoop2.7/conf/spark-env.sh.template /opt/spark/spark-2.4.4-bin-hadoop2.7/conf/spark-env.sh
linuxidc@linuxidc:/opt/spark/spark-2.4.4-bin-hadoop2.7/conf$ sudo nano spark-env.sh
export JAVA_HOME=/opt/java/jdk1.8.0_231
export HADOOP_HOME=/opt/hadoop/hadoop-2.7.7
export HADOOP_CONF_DIR=/opt/hadoop/hadoop-2.7.7/etc/hadoop
export SPARK_HOME=/opt/spark/spark-2.4.4-bin-hadoop2.7
export SCALA_HOME=/opt/scala/scala-2.11.8
export SPARK_MASTER_IP=127.0.0.1
export SPARK_MASTER_PORT=7077
export SPARK_MASTER_WEBUI_PORT=8099
export SPARK_WORKER_CORES=3
export SPARK_WORKER_INSTANCES=1
export SPARK_WORKER_MEMORY=5G
export SPARK_WORKER_WEBUI_PORT=8081
export SPARK_EXECUTOR_CORES=1
export SPARK_EXECUTOR_MEMORY=1G
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$HADOOP_HOME/lib/native
Java,Hadoop等具体路径根据自己实际环境设置。
启动bin目录下的spark-shell
可以看到已经进入到scala环境,此时就可以编写代码啦。
spark-shell的web界面http://127.0.0.1:4040
暂时先这样,如有什么疑问,请在Linux公社下面的评论栏里提出。
Linux公社微信号ID:
linuxidc_com长按或扫描左图识别二维码关注Linux公社公众微信号
更多Hadoop相关信息见Hadoop 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=13
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx
支持就点下在看并
转发朋友圈吧
![3dc3a9886456879e118c5e1e4b83422d.png](https://i-blog.csdnimg.cn/blog_migrate/bf9f641c2eda78f37bf5586ed5580e2c.jpeg)
1、Java JDK8的安装
前往Oracle官网下载JDK8,选择适合自己操作系统的版本,此处选择Linux 64 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html![61c5abaa27eb0f9bf95a890d27371d15.png](https://i-blog.csdnimg.cn/blog_migrate/66ec6e65095e9056485331317fa6a17f.jpeg)
[sudo] linuxidc 的密码:
linuxidc@linuxidc:~/www.linuxidc.com$ cd /opt/java/
linuxidc@linuxidc:/opt/java$ ls
jdk-8u231-linux-x64.tar.gz 使用命令:tar -zxvf jdk-8u231-linux-x64.tar.gz 解压缩 linuxidc@linuxidc:/opt/java$ sudo tar -zxf jdk-8u231-linux-x64.tar.gz
linuxidc@linuxidc:/opt/java$ ls
jdk1.8.0_231 jdk-8u231-linux-x64.tar.gz
![437bf8fbdf54ef21d0ffbb6d312c6401.png](https://i-blog.csdnimg.cn/blog_migrate/9d8462e5d5533022bd556c3b5a0fb3cb.png)
![52df65b4deb1c1760b4e3b1d56c3acff.png](https://i-blog.csdnimg.cn/blog_migrate/67f22b29ab3d9990c5c8e6b374a5a3bc.png)
![56c2d0b1c1bf5fa7e06ef5294aae1f50.png](https://i-blog.csdnimg.cn/blog_migrate/a7c1b4c8864064ff1ead430dd06439f7.png)
export JRE_HOME=/opt/java/jdk1.8.0_231/jre
export PATH=${JAVA_HOME}/bin:$PATH
![23670c44c4e237587480afcea44274b8.png](https://i-blog.csdnimg.cn/blog_migrate/109a338f91094fd291e965ef82e80263.png)
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
linuxidc@linuxidc:/opt/java$
![c103fcfafb0c8b360abc6c364c12ba3f.png](https://i-blog.csdnimg.cn/blog_migrate/759f3c0260fb3d8d7a538de386d7b18e.png)
2、安装Hadoop
前往官网https://hadoop.apache.org/releases.html下载hadoop,此处选择版本2.7.7 http://www.apache.org/dist/hadoop/core/hadoop-2.7.7/hadoop-2.7.7.tar.gz hadoop需要ssh免密登陆等功能,因此先安装ssh。 使用命令: linuxidc@linuxidc:~/www.linuxidc.com$ sudo apt-get install ssh![5befb8c5a3993b6bdecd26ecc4bab631.png](https://i-blog.csdnimg.cn/blog_migrate/8aa816f02d57f7f8ee6187f3c4bb4986.jpeg)
![d4698abcd39edc846f4b2f6d3c26b1ee.png](https://i-blog.csdnimg.cn/blog_migrate/75a29ee1ceb7dc7ad131734dbe82f829.png)
![56c2d0b1c1bf5fa7e06ef5294aae1f50.png](https://i-blog.csdnimg.cn/blog_migrate/a7c1b4c8864064ff1ead430dd06439f7.png)
![52df65b4deb1c1760b4e3b1d56c3acff.png](https://i-blog.csdnimg.cn/blog_migrate/67f22b29ab3d9990c5c8e6b374a5a3bc.png)
![f81ed3b3d7d1dd94626cada34e545db2.png](https://i-blog.csdnimg.cn/blog_migrate/30d84601d606f60a19e57b330acaea43.jpeg)
![e1a62e57dce8605d71ef48f03c20ba19.png](https://i-blog.csdnimg.cn/blog_migrate/8dd7b7df8946e32f0e6855d97624c139.png)
![134e0467c13f05a6e29d67d07bb00dee.png](https://i-blog.csdnimg.cn/blog_migrate/e72c9fb38e79a24c363f101e5ecdcd7b.jpeg)
![b0fcc696c6ad6c7e6cd379f29b7520f4.png](https://i-blog.csdnimg.cn/blog_migrate/cf2e4baa093311bbf82b1fab09ac06ce.jpeg)
Generating public/private rsa key pair.
Your identification has been saved in /home/linuxidc/.ssh/id_rsa.
Your public key has been saved in /home/linuxidc/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:zY+ELQc3sPXwTBRfKlTwntek6TWVsuQziHtu3N/6L5w linuxidc@linuxidc
The key's randomart image is:
+---[RSA 2048]----+
| . o.*+. .|
| + B o o.|
| o o =o+.o|
| B..+oo=o|
| S.*. ==.+|
| +.o .oo.|
| .o.o... |
| oo .E .|
| .. o==|
+----[SHA256]-----+
linuxidc@linuxidc:~/www.linuxidc.com$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
linuxidc@linuxidc:~/www.linuxidc.com$ chmod 0600 ~/.ssh/authorized_keys
![2fb4d0756bdf5f3b36bff45fcf67b452.png](https://i-blog.csdnimg.cn/blog_migrate/335003ab5bf95e09549cb9f6ac985b4d.png)
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 5.4.0-999-generic x86_64) * Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage * Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch 188 个可升级软件包。
0 个安全更新。 Your Hardware Enablement Stack (HWE) is supported until April 2023.
Last login: Sat Nov 30 23:25:35 2019 from 127.0.0.1
![d0fc3c186c1dbaa191676a14f5791bd2.png](https://i-blog.csdnimg.cn/blog_migrate/96234896a4783acab6ff3b32bae28e13.png)
19/11/30 23:29:06 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = linuxidc/127.0.1.1
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 2.7.7
......
![b185dd98697520fae15c04a749a78800.png](https://i-blog.csdnimg.cn/blog_migrate/92691d177fa067db231488c7f95912ed.jpeg)
Starting namenodes on [localhost]
localhost: starting namenode, logging to /opt/hadoop/hadoop-2.7.7/logs/hadoop-linuxidc-namenode-linuxidc.out
localhost: starting datanode, logging to /opt/hadoop/hadoop-2.7.7/logs/hadoop-linuxidc-datanode-linuxidc.out
Starting secondary namenodes [0.0.0.0]
The authenticity of host '0.0.0.0 (0.0.0.0)' can't be established.
ECDSA key fingerprint is SHA256:OSXsQK3E9ReBQ8c5to2wvpcS6UGrP8tQki0IInUXcG0.
Are you sure you want to continue connecting (yes/no)? yes
0.0.0.0: Warning: Permanently added '0.0.0.0' (ECDSA) to the list of known hosts.
0.0.0.0: starting secondarynamenode, logging to /opt/hadoop/hadoop-2.7.7/logs/hadoop-linuxidc-secondarynamenode-linuxidc.out c、浏览器访问 http://localhost:50070
![2059623d1878fd2764afc8afa9df30ec.png](https://i-blog.csdnimg.cn/blog_migrate/8a9287eceb9ea2bc8c457c0013a784e8.jpeg)
3、Scala安装:
下载地址:https://www.scala-lang.org/download/2.11.8.html![30defb06ee3624fd3d26cfade949b68d.png](https://i-blog.csdnimg.cn/blog_migrate/ea4cfcb5bc71316fc7343041f7dc0856.png)
[sudo] linuxidc 的密码:
linuxidc@linuxidc:~/下载$ cd /opt/scala
linuxidc@linuxidc:/opt/scala$ ls
scala-2.11.8 配置环境变量: linuxidc@linuxidc:/opt/scala$ sudo nano /etc/profile 添加: export SCALA_HOME=/opt/scala/scala-2.11.8
![8aad3dab9939240fe1a209e3e97f68ab.png](https://i-blog.csdnimg.cn/blog_migrate/f614e1d911dfa44492eff316858c3105.png)
4、安装spark
前往spark官网下载spark https://spark.apache.org/downloads.html 此处选择版本如下: spark-2.4.4-bin-hadoop2.7 将spark放到某个目录下,此处放在/opt/spark 使用命令:tar -zxvf spark-2.4.0-bin-hadoop2.7.tgz 解压缩即可 linuxidc@linuxidc:~/www.linuxidc.com$ sudo cp /home/linuxidc/www.linuxidc.com/spark-2.4.4-bin-hadoop2.7.tgz /opt/spark/[sudo] linuxidc 的密码:
linuxidc@linuxidc:~/www.linuxidc.com$ cd /opt/spark/
linuxidc@linuxidc:/opt/spark$ ls
spark-2.4.4-bin-hadoop2.7.tgz
![dbe6c176967205791642f73a6fc1b98b.png](https://i-blog.csdnimg.cn/blog_migrate/3875f38bb5753c9cdaa8920a9f9153f2.png)
[sudo] linuxidc 的密码:
linuxidc@linuxidc:/opt/spark$ ls
spark-2.4.4-bin-hadoop2.7 spark-2.4.4-bin-hadoop2.7.tgz
![49c8973db0e500ded703541b18f811be.png](https://i-blog.csdnimg.cn/blog_migrate/80566786956d398794156bcf3a5eab24.png)
export PATH=${JAVA_HOME}/bin:${HADOOP_HOME}/bin:${SPARK_HOME}/bin:$PATH
![b71530dcc0f5372c3cfc1bc75342ef09.png](https://i-blog.csdnimg.cn/blog_migrate/c46303167f00c076c44fec70271e8745.png)
export HADOOP_HOME=/opt/hadoop/hadoop-2.7.7
export HADOOP_CONF_DIR=/opt/hadoop/hadoop-2.7.7/etc/hadoop
export SPARK_HOME=/opt/spark/spark-2.4.4-bin-hadoop2.7
export SCALA_HOME=/opt/scala/scala-2.11.8
export SPARK_MASTER_IP=127.0.0.1
export SPARK_MASTER_PORT=7077
export SPARK_MASTER_WEBUI_PORT=8099
export SPARK_WORKER_CORES=3
export SPARK_WORKER_INSTANCES=1
export SPARK_WORKER_MEMORY=5G
export SPARK_WORKER_WEBUI_PORT=8081
export SPARK_EXECUTOR_CORES=1
export SPARK_EXECUTOR_MEMORY=1G
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$HADOOP_HOME/lib/native
![1fc5fa3f2cf563319ef5f70427ae6a36.png](https://i-blog.csdnimg.cn/blog_migrate/9ac305fc5a0b36f9596e0c97ed6a8a99.jpeg)
![cde57d9f14a41735f865f354f9e62940.png](https://i-blog.csdnimg.cn/blog_migrate/e4ed166fb60b90fd74a366c80619dee3.png)
![ef2e8e9701209c0a31fd532a34f83778.png](https://i-blog.csdnimg.cn/blog_migrate/14f76447009785bc5d000f0ad2dc810b.jpeg)
![9dd04097bd2c16e0682e7d09d1affcb6.png](https://i-blog.csdnimg.cn/blog_migrate/a9177a9b51704425cb93d67e8a526844.png)
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx
本文永久更新链接地址:https://www.linuxidc.com/Linux/2019-12/161628.htm
![1e866879239b27807c0561022b325fb4.gif](https://i-blog.csdnimg.cn/blog_migrate/04aed0573026306002c76c06473e96ec.gif)
![9611790b5c7bd2cd8735d5c5872b20f0.png](https://i-blog.csdnimg.cn/blog_migrate/e20ff6240820bbd0fc2a8b9a8da77f2c.png)
![1e866879239b27807c0561022b325fb4.gif](https://i-blog.csdnimg.cn/blog_migrate/04aed0573026306002c76c06473e96ec.gif)