spark版本:spark-1.6.0-bin-hadoop2.6
hive版本:hive 1.2.1
1.hive-site.xml
<property>
<name>hive.metastore.uris</name>
<value>thrift://master:9083</value>
</property>
2.配置
將hadoop中core-site.xml,hdfs-site.xml, 放在spark中conf下面
將hive中hive-site.xml,放在spark中conf下面
然后將上面三個文件分發到其它spark節點上面。
3.啟動 hive metastore
nohup hive --service metastore > metastore.log 2>&1 &
4.yarn提交
spark-submit --master yarn-cluster \
--class com.jp.spark.sparksql.HiveContextSelect \
--files /usr/local/spark-1.6.0-bin-hadoop2.6/conf/hive-site.xml \
--jars datanucleus-api-jdo-3.2.6.jar,datanucleus-core-3.2.10.jar,datanucleus-rdbms-3.2.9.jar,mysql-connector-java-5.1.39.jar,guava-15.0.jar \
/home/jumper/jp_spark-1.0-SNAPSHOT.jar
guava-15.0.jar 有比較好,否則會報警告。
4.spark-shell啟動
spark-shell guava-15.0.jar
5.HiveContextSelect內容
object HiveContextSelect{ def main(args: Array[String]) { val conf = new SparkConf() // conf.setMaster("local"); conf.setAppName("FirstSelect") val sc = new SparkContext(conf) val hiveContext = new HiveContext(sc) import hiveContext.implicits._ import hiveContext.sql sql("show databases").collect().foreach(println) sc.stop() } }