1,Spark SQL
1.1 spark sql运行在yarn之前注意在/etc/profile配置
export HADOOP_HOME=/data/hadoop/hadoop-2.7.1
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
export YARN_CONF_DIR=$HADOOP_HOME/etc/hadoop
1.2 需要将hive-site.xml拷贝到spark的conf下,如果hive 元数据用mysql存储需要将mysql-connector-java-5.1.15-bin.jar拷贝到spark的jars下
如果spark-sql 和hive 不在一个服务器上也可以通过Thrift Server方式运行
在hive 服务器上启动:nohup hive --service metastore > metastore.log 2>&1 &
在spark客户端上conf中配置hive-site.xml
<configuration> <property> <name>hive.metastore.uris</name> <value>thrift://datanode1:9083</value> </property> </configuration>
可以通过下面命令运行在spark master上
./spark-sql --master spark://192.168.119.128:7077
2,Spark Shell
运行在yarn上之前需要注意配置HADOOP_CONF_DIR和 YARN_CONF_DIR
./spark-shell --master yarn
可以通过下面命令运行在spark master上
./spark-shell --master spark://192.168.119.128:7077
3, Spark Submit
wordcount运行在spark yarn上
./bin/spark-submit --class com.test.hadoop.SparkWordCountTest --master spark://192.168.119.128:7077 --executor-memory 512M --total-executor-cores 2 ../MRTest-1.0-jar-with-dependencies.jar hdfs://namenode:9000/word_test.txt
可以通过下面命令运行在spark master上
./bin/spark-submit --class com.test.hadoop.SparkWordCountTest --master yarn --executor-memory 512M --total-executor-cores 2 ../MRTest-1.0-jar-with-dependencies.jar hdfs://namenode:9000/word_test.txt