首页 > 代码库 > Apache Spark 1.6 Hadoop 2.6 Mac下单机安装配置
Apache Spark 1.6 Hadoop 2.6 Mac下单机安装配置
转载:http://www.cnblogs.com/ysisl/p/5979268.html
一、 下载资料
1. JDK 1.6 +
2. Scala 2.10.4
3. Hadoop 2.6.4
4. Spark 1.6
二、预先安装
1. 安装JDK
2. 安装Scala 2.10.4
解压安装包即可
3. 配置sshd
ssh-keygen -t dsa -P ‘‘ -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
mac 启动sshd
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
查看启动
sudo launchctl list | grep ssh
输出- 0 com.openssh.sshd 表示启动成功
停止sshd服务
sudo launchctl unload -w /System/Library/LaunchDaemons/ssh.plist
三、安装Hadoop
1. 创建Hadoop文件系统目录
mkdir -pv hadoop/workspace
cd hadoop/workspace
mkdir tmp
mkdir -pv hdfs/data
mkdir -pv hdfs/name
添加hadoop目录环境变量
vi ~/.bashrc
HADOOP_HOME=/Users/ysisl/app/hadoop/hadoop-2.6.4
配置hadoop,都在$HADOOP_HOME/etc/hadoop 下
1. core-site.xml
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
<description>HDFS URI</description>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/Users/ysisl/app/hadoop/workspace/tmp</value>
<description>namenode temp dir</description>
</property>
</configuration>
2. hdfs-site.xml
<configuration>
<property>
<name>dfs.name.dir</name>
<value>/Users/ysisl/app/hadoop/workspace/hdfs/name</value>
<description>namenode上存储hdfs名字空间元数据 </description>
</property>
<property>
<name>dfs.data.dir</name>
<value>/Users/ysisl/app/hadoop/workspace/hdfs/data</value>
<description>datanode上数据块的物理存储位置</description>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
<description>副本个数,配置默认是3,应小于datanode机器数量</description>
</property>
</configuration>
3. copy mapred-site.xml.template to mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
4. yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>localhost:8099</value>
</property>
</configuration>
5. 格式化HDFS文件系统
$HADOOP_HOME/bin/hdfs namenode -format
6. 进入sbin/ 执行 start-all.sh
7. 执行jps 查看是否正常启动
21472
30256 Jps
29793 DataNode
29970 SecondaryNameNode
29638 NameNode
30070 ResourceManager
30231 NodeManager
8. 打开 http://localhost:50070/explorer.html 网页查看hadoop目录结构,说明安装成功
四、安装Spark
1. 解压spark压缩包
tar xvzf spark.1.6.tar.gz
2. 加入环境变量
vi ~/.bashrc
SCALA_HOME=/Users/ysisl/app/spark/scala-2.10.4
SPARK_HOME=/Users/ysisl/app/spark/spark-1.6.1-bin-hadoop2.6
2. 设置配置文件
cd spar-1.6.1-bin-hadoop2.6/conf
cp spark-env.sh.template spark-env.sh
vi spar-env.sh
添加如下内容
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
export SCALA_HOME=/Users/ysisl/app/spark/scala-2.10.4
export HADOOP_CONF_DIR=/Users/ysisl/app/hadoop/hadoop-2.6.4/etc/hadoop
export SPARK_MASTER_IP=localhost
export SPARK_WORKER_CORES=2
export SPARK_WORKER_MEMORY=2g
cp slaves.template slaves
默认slaves现在就主机一台
3. 启动 sbin/start-all.sh
jps 查看到多出一个Master,worker进程
21472
29793 DataNode
29970 SecondaryNameNode
30275 Master
30468 SparkSubmit
29638 NameNode
30070 ResourceManager
30231 NodeManager
30407 Worker
30586 Jps
4. 配置scala 、spark 、 hadoop 环境变量加入PATH ,方便执行
vi ~/.bashrc
export HADOOP_HOME=/Users/ysisl/app/hadoop/hadoop-2.6.4
export SCALA_HOME=/Users/ysisl/app/spark/scala-2.10.4
export SPARK_HOME=/Users/ysisl/app/spark/spark-1.6.1-bin-hadoop2.6
export PATH="${HADOOP_HOME}/bin:${SCALA_HOME}/bin:${SPARK_HOME}/bin:$PATH"
五. 测试运行
1. 准备一个csv文件,路径 /Users/ysisl/app/hadoop/test.csv
2. 查看DFS文件系统结构, 执行 hadoop fs -lsr /
3. 新建目录 , hadoop fs -mkdir /test
4. 上传文件到目录, hadoop fs -put /Users/ysisl/app/hadoop/test.csv /test/
5. hadoop fs -lsr / 查看已创建的目录文件
6. 执行 spark-shell
scala > val file=sc.textFile("hdfs:/test/test.csv")
scala > val count=file.flatMap(line=>line.split(" ")).map(word=>(word,1)).reduceByKey(_+_)
scala > count.collect
7. 查看执行状态
a. localhost:8080 ,查看spark 集群运行情况。 此端口一般与其他端口冲突
在spark-env.sh 中加入 export SPARK_MASTER_WEBUI_PORT=98080 来指定
b. http://localhost:4040/jobs/ ,查看 spark task job运行情况
c. http://localhost:50070/ hadoop集群运行情况
Apache Spark 1.6 Hadoop 2.6 Mac下单机安装配置