一、spark介绍
是一种通用的大数据计算框架, 正如传统大数据技术Hadoop的MapReduce、 Hive引擎, 以及Storm流式实时计算引擎等. Spark主要用于大数据的计算。
二、服务器及环境准备
1、准备三台服务器
192.168.42.139 node1
192.168.42.140 node2
192.168.42.141 node3
2、环境准备
jdk1.8
scala-2.13.12
spark-3.5.0-bin-hadoop3
3、环境变量的配置
export JAVA_HOME=/usr/local/jdk1.8.0_391
export JRE_HOME=/usr/local/jdk1.8.0_391/jre
export HBASE_HOME=/usr/local/bigdata/hbase-2.5.6
export HADOOP_HOME=/usr/local/bigdata/hadoop-3.3.6
export FLINK_HOME=/usr/local/bigdata/flink-1.18.0
export SCALA_HOME=/usr/local/bigdata/scala-2.13.12
export SPARK_HOME=/usr/local/bigdata/spark-3.5.0-bin-hadoop3
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAR_HOME/lib
export PATH=.:$JAVA_HOME/bin:$JRE_HOME/bin:$FLINK_HOME/bin:$SPARK_HOME/bin:$SCALA_HOME/bin:$HADOOP_HOME/bin:$HBASE_HOME/bin:$PYTHON_HOME/bin:$PATH
三、spark配置文件的修改
1、拷贝spark-env.sh
export SPARK_DIST_CLASSPATH=/usr/local/bigdata/spark-3.5.0-bin-hadoop3
export SPAEK_MASTER_HOST=node1
export SPARK_MASTER_PORT=7077
export SPARK_MASTER_WEBUI_PORT=8080
export SPARK_WORKER_MEMORY=1g
export SPARK_WORKER_CORES=1
export SPARK_WORKER_INSTANCES=1
export JAVA_HOME=/usr/local/jdk1.8.0_391
2、拷贝workers
node1
node2
node3
3、拷贝spark-defaults.conf
# Example:
spark.master spark://node1:7077
spark.eventLog.enabled true
# spark.eventLog.dir hdfs://namenode:8021/directory
spark.serializer org.apache.spark.serializer.KryoSerializer
# spark.driver.memory 5g
spark.executor.extraJavaOptions -XX:+PrintGCDetails -Dkey=value -Dnumbers="one two three"
四、把配置好的spark拷贝到其他
...
五、启动spark
进入/usr/local/bigdata/spark-3.5.0-bin-hadoop3/sbin中执行 ./start-all.sh
./start-all.sh
六、查看启动成功后的界面
http://192.168.42.139:8080/
七、在集群下执行spark任务
spark-submit --class org.apache.spark.examples.SparkPi --driver-memory 1g --num-executors 1 --executor-memory 512m --executor-cores 1 ${SPARK_HOME}/examples/jars/spark-examples*.jar 100