一、scala安装
1. 安装jdk
有mac专用的jdk安装包,这里下载安装jdk1.8
2. 安装scala
2.1下载scala
2.2解压到指定目录
tar -zxvf /Users/lodestar/Desktop/临时/scala-2.12.15.tar -C /Users/lodestar/software
2.3环境变量配置
vi ./bash_profile
我本机装过python和maven,这里再加入scala配置
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH
export M2_HOME=/Library/apache-maven-3.6.3
export PATH=$PATH:$M2_HOME/bin
export SCALA_HOME=/Users/lodestar/software/scala-2.12.15
export PATH=$SCALA_HOME/bin:$PATH
保存退出
source .bash_profile让配置生效
echo $SCALA_HOME 验证配置是否生效
2.4.执行./scala进入控制台
2.5 编写,编译执行scala代码
文件后缀.scala;编译:scalac Helloworld.scala
3.Hadoop安装
3.1下载后解压到指定目录
tar -zxvf /Users/lodestar/Desktop/临时/hadoop-2.8.5.tar.gz -C /Users/lodestar/hadoop
hadoop目录结构如下:
bin:客户端工具
sbin:启动hadoop相关进程的脚本
etc/hoadoop:hadoop配置文件
share:常用例子
3.2 hadoop参数配置
vi ./bash_profile
export HADOOP_HOME=/Users/lodestar/hadoop/hadoop-2.8.5
export PATH=$HADOOP_HOME/bin:$PATH
export JAVA_HOME= /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
hadoop-env.sh
export JAVA_HOME= /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home
core-site.xml
hdfs-site.xml
slaves
hadoop000
3.4.ssh免密码登录,否则启动hadoop需要不断输入密码
--hadoop用户操作
ssh localhost --产生.ssh的隐藏目录
ssh-keygen -t rsa --产生密钥对(1路回车)
cat id_rsa.pub >> authorized_keys --讲公钥写入authorized_keys
chmod 600 authorized_keys --authorized_keys 只有创建者有读写权限
ssh localhost 测试,不需要密码配置成功
3.5 初始化文件系统
第一次启动前格式化文件系统
hdfs namenode -format
3.6 启动hadoop
进入sbin目录:
启动Start-dfs.sh
关闭stop-dfs.sh
3.7验证
Jps命令查询看到namenode和datanode进程
测试一下:
hadoop fs -ls /
hadoop fs -put README.txt /
进入浏览器查看hdfs状态
http://localhost:50070/
4 Spark安装和配置
4.1、Spark安装
tar xvf /Users/lodestar/Desktop/临时/spark-3.0.3-bin-hadoop2.7.tar -C /Users/lodestar/spark
4.2、Spark配置
1.配置环境变量
修改~/.bash_profile
export SPARK_HOME=/Users/lodestar/spark/spark-3.0.3-bin-hadoop2.7
export PATH=$SPARK_HOME/bin:$SPARK_HOME/sbin:$PATH
使得配置修改生效:source .bash_profile
2.修改配置文件spark-env.sh
1.修改conf下的spark-env.sh.template为spark-env.sh
cp spark-env.sh.template spark-env.sh
2:修改配置
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home
export SCALA_HOME=/Users/lodestar/software/scala-2.12.15
export SPARK_HOME=/Users/lodestar/spark/spark-3.0.3-bin-hadoop2.7
#SPRAK MASTER地址
export SPARK_MASTER_IP=127.0.0.1
export SPARK_LOCAL_IP=127.0.0.1
export SPARK_EXECUTOR_MEMORY=500M
export SPARK_WORKER_MEMORY=1G
#spark master UI地址
export master=spark://127.0.0.1:7070
3.修改配置文件slaves
1.修改conf下的spark-env.sh.template为spark-env.sh
cp slaves.template slaves
echo “localhost” >> slaves
4.启动spark
./start-all.sh
使用jps查看,master上会有Master和Worker,worker节点上会有Worker
http://1192.168.251.86:8080查看spark的web界面
5.执行spark提供的默认demo
spark-submit --class org.apache.spark.examples.SparkPi --master spark://lodestardembp-2:7077 /Users/lodestar/spark/spark-3.0.3-bin-hadoop2.7/examples/jars/spark-examples_2.12-3.0.3.jar
--这里以前写的是localhos:7077,始终不能正常解析,后面换成spark web ui上的机器名