Hive记录-Hive on Spark环境部署

1.hive执行引擎

Hive默认使用MapReduce作为执行引擎,即Hive on mr。实际上,Hive还可以使用Tez和Spark作为其执行引擎,分别为Hive on Tez和Hive on Spark。由于MapReduce中间计算均需要写入磁盘,而Spark是放在内存中,所以总体来讲Spark比MapReduce快很多。

默认情况下,Hive on Spark 在YARN模式下支持Spark。

2.前提条件:安装JDK-1.8/hadoop-2.7.2等,参考之前的博文

3.下载hive-2.1.1.src.tar.gz源码解压后,打开pom.xml发现spark版本为1.6.0---官网介绍版本必须对应才能兼容如hive2.1.1-spark1.6.0 

4.下载spark-1.6.0.tgz源码(网上都是带有集成hive的,需要重新编译)

5.上传到Linux服务器,解压

6.源码编译

#cd  spark-1.6.0

#修改make-distribution.sh的MVN路径为/usr/app/maven/bin/mvn    ###查看并安装pom.xml的mvn版本

#./make-distribution.sh --name "hadoop2-without-hive" --tgz "-Pyarn,hadoop-provided,hadoop-2.4,parquet-provided"  

#等待一个多小时左右吧,保证联网环境,有可能外网访问不到下载不了依赖项,配置访问外网或配置阿里云仓库,重新编译


7.配置

#vim /etc/hosts     192.168.66.66 xinfang

#解压spark-1.6.0-bin-hadoop2-without-hive.tgz,并命名为spark

#官网下载hive-2.1.1解压  并命令为hive(关于hive详细配置,参考http://blog.csdn.net/xinfang520/article/details/77774522)

#官网下载scala2.10.5解压,并命令为scala

#chmod -R 755 /usr/app/spark  /usr/app/hive   /usr/app/scala 

#配置环境变量-vim /etc/profile

#set hive
export HIVE_HOME=/usr/app/hive
export PATH=$PATH:$HIVE_HOME/bin

#set spark
export SPARK_HOME=/usr/app/spark
export PATH=$SPARK_HOME/bin:$PATH

#set scala
export SCALA_HOME=/usr/app/scala
export PATH=$SCALA_HOME/bin:$PATH

#配置/spark/conf/spark-env.sh

export JAVA_HOME=/usr/app/jdk1.8.0
export SCALA_HOME=/usr/app/scala
export HADOOP_HOME=/usr/app/hadoop
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop 
export YARN_CONF_DIR=$HADOOP_HOME/etc/hadoop
export SPARK_DIST_CLASSPATH=$(hadoop classpath)
export SPARK_LAUNCH_WITH_SCALA=0
export SPARK_WORKER_MEMORY=512m
export SPARK_DRIVER_MEMORY=512m
export SPARK_MASTER_IP=192.168.66.66
#export SPARK_EXECUTOR_MEMORY=512M  
export SPARK_HOME=/usr/app/spark
export SPARK_LIBRARY_PATH=/usr/app/spark/lib
export SPARK_MASTER_WEBUI_PORT=18080
export SPARK_WORKER_DIR=/usr/app/spark/work
export SPARK_MASTER_PORT=7077
export SPARK_WORKER_PORT=7078
export SPARK_LOG_DIR=/usr/app/spark/logs
export SPARK_PID_DIR='/usr/app/spark/run' 

#配置/spark/conf/spark-default.conf

spark.master                     spark://xinfang:7077
spark.eventLog.enabled           true
spark.eventLog.dir               hdfs://xinfang:9000/spark-log
spark.serializer                 org.apache.spark.serializer.KryoSerializer
spark.executor.memory            512m
spark.driver.memory              512m
spark.executor.extraJavaOptions  -XX:+PrintGCDetails -Dkey=value -Dnumbers="one two three"

#修改hive-site.xml(hive详细部署参考http://blog.csdn.net/xinfang520/article/details/77774522)

<configuration>
<property>  
<name>hive.metastore.schema.verification</name>  
<value>false</value>  
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.66.66:3306/hive?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>1</value>
</property>
<!--<property>
<name>hive.hwi.listen.host</name>
<value>192.168.66.66</value>
</property>
<property>
<name>hive.hwi.listen.port</name>
<value>9999</value>
</property>
<property>
<name>hive.hwi.war.file</name>
<value>lib/hive-hwi-2.1.1.war</value>
</property>-->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<property>
<name>hive.exec.scratchdir</name>
<value>/user/hive/tmp</value>
</property>
<property>
<name>hive.querylog.location</name>
<value>/user/hive/log</value>
</property>
<property>  
<name>hive.server2.thrift.port</name>  
<value>10000</value>
</property> 
<property>  
<name>hive.server2.thrift.bind.host</name>  
<value>192.168.66.66</value>
</property>
<property>
<name>hive.server2.webui.host</name>
<value>192.168.66.66</value>
</property>
<property>
<name>hive.server2.webui.port</name>
<value>10002</value>
</property> 
<property>  
<name>hive.server2.long.polling.timeout</name>  
<value>5000</value>                                
</property>
<property> 
<name>hive.server2.enable.doAs</name> 
<value>true</value> 
</property> 
<property> 
<name>datanucleus.autoCreateSchema </name> 
<value>false</value> 
</property> 
<property> 
<name>datanucleus.fixedDatastore </name> 
<value>true</value> 
</property>
<!-- hive on mr-->
<!--
<property>  
<name>mapred.job.tracker</name>  
<value>http://192.168.66.66:9001</value>  
</property>
<property>  
<name>mapreduce.framework.name</name>  
<value>yarn</value>  
</property>
-->
<!--hive on spark or spark on yarn -->
<property>
<name>hive.execution.engine</name>
<value>spark</value>
</property>
<property>
<name>spark.home</name>
<value>/usr/app/spark</value>
</property>
<property>
<name>spark.master</name>
<value>spark://xinfang:7077</value>  或者yarn-cluster/yarn-client
</property>
<property>  
<name>spark.submit.deployMode</name>  
<value>client</value>  
</property> 
<property>
<name>spark.eventLog.enabled</name>
<value>true</value>
</property>
<property>
<name>spark.eventLog.dir</name>
<value>hdfs://xinfang:9000/spark-log</value>
</property>
<property>
<name>spark.serializer</name>
<value>org.apache.spark.serializer.KryoSerializer</value>
</property>
<property>
<name>spark.executor.memeory</name>
<value>512m</value>
</property>
<property>
<name>spark.driver.memeory</name>
<value>512m</value>
</property>
<property>
<name>spark.executor.extraJavaOptions</name>
<value>-XX:+PrintGCDetails -Dkey=value -Dnumbers="one two three"</value>
</property>
</configuration>

#新建目录

hadoop fs  -mkdir  -p   /spark-log
hadoop   fs  -chmod  777  /spark-log
mkdir -p  /usr/app/spark/work  /usr/app/spark/logs  /usr/app/spark/run
mkdir -p /usr/app/hive/logs 

#拷贝hive-site.xml到spark/conf下(这点非常关键)

#hive进入客户端 

hive>set hive.execution.engine=spark; (将执行引擎设为Spark,默认是mr,退出hive CLI后,回到默认设置。若想让引擎默认为Spark,需要在hive-site.xml里设置)
hive>create table test(ts BIGINT,line STRING); (创建表)
hive>select count(*) from test;

若整个过程没有报错,并出现正确结果,则Hive on Spark配置成功。

http://192.168.66.66:18080



8.网上转载部分解决方案

第一个坑:要想在Hive中使用Spark执行引擎,最简单的方法是把spark-assembly-1.5.0-hadoop2.4.0.jar包直接拷贝 到$HIVE_HOME/lib目录下。

第二个坑:版本不对,刚开始以为hive 能使用 spark的任何版本,结果发现错了,hive对spark版本有着严格要求,具体对应版本你可以下载hive源码里面,搜索他pom.xml文件里面的spark版本,如果版本不对,启动hive后会报错。具体错误如下:

Failed to execute spark task, with exception 'org.apache.hadoop.hive.ql.metadata.HiveException(Failed to create spark client.)' FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.spark.SparkTask

第三个坑:./make-distribution.sh --name "hadoop2-without-hive" --tgz "-Pyarn,hadoop-provided,hadoop-2.4" ,开启spark报错找不到类

解决办法是在spark-env.sh里面添加 :export SPARK_DIST_CLASSPATH=$(hadoop classpath)

#如果启动包日志包重复需要删除
#根据实际修改hive/bin/hive:(根据spark2后的包分散了)
sparkAssemblyPath='ls ${SPARK_HOME}/lib/spark-assembly-*.jar' 
将其修改为:sparkAssemblyPath='ls ${SPARK_HOME}/jars/*.jar'

#spark1 拷贝spark/lib/spark-* 到/usr/app/hive/lib

 

9.参考文章说明

#参考http://spark.apache.org/docs/latest/building-spark.html

#参考http://www.cnblogs.com/linbingdong/p/5806329.html

#参考http://blog.csdn.net/pucao_cug/article/details/72773564

#参考https://cwiki.apache.org//confluence/display/Hive/Hive+on+Spark:+Getting+Started







 

posted @ 2017-10-17 23:25  信方  阅读(17391)  评论(1编辑  收藏