1、到下载地址http://apache.fayea.com/hive/,下载apache-hive-1.2.1-bin.tar.gz,解压
tar -xzvf apache-hive-1.2.1-bin.tar.gz
2、配置环境变量
vi /etc/profile
export HIVE_HOME=/opt/modules/app/hive
export PATH=$PATH:$HIVE_HOME/bin
source /etc/profile
3、配置hive参数
[root@hadoop01 hive]# cd conf/
[root@hadoop01 conf]# cp hive-env.sh.template hive-env.sh
[root@hadoop01 conf]# touch hive-site.xml
配置hive-env.sh
export JAVA_HOME=/opt/jdk1.8
export HIVE_HOME=/opt/modules/app/hive
export HADOOP_HOME=/opt/modules/app/hadoop
配置hive-site.xml
创建临时文件:在hive文件夹下创建tmp文件夹
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore </description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
</property>
<property>
<name>hive.querylog.location</name>
<value>/opt/modules/app/hive/tmp</value>
</property>
<property>
<name>hive.exec.local.scratchdir</name>
<value>/opt/modules/app/hive/tmp</value>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/opt/modules/app/hive/tmp</value>
</property>
<property>
<name>datanucleus.schema.autoCreateAll</name>
<value>true</value>
</property>
### beeline连接hive的thrift服务,用户名密码设置
<property>
<name>hive.server2.thrift.client.user</name>
<value>root</value>
<description>Username to use against thrift client</description>
</property>
<property>
<name>hive.server2.thrift.client.password</name>
<value>root</value>
<description>Password to use against thrift client</description>
</property>
</configuration>
4、上传mysql驱动jar
下载mysql驱动文件mysql-connector-java-5.1.7-bin.jar,并上传到到hive/lib目录下。
5、初始化hive
命令:schematool -initSchema -dbType mysql
最后显示schemaTool completed,没有报错就成功了。
6、启动hadoop集群后,启动hive
输入命令:hive
[root@hadoop01 hive]# hive
18/09/24 23:21:45 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
18/09/24 23:21:45 WARN conf.HiveConf: HiveConf of name hive.server2.thrift.client.user does not exist
18/09/24 23:21:45 WARN conf.HiveConf: HiveConf of name hive.server2.thrift.client.password does not exist
Logging initialized using configuration in jar:file:/opt/modules/app/hive/lib/hive-common-1.2.1.jar!/hive-log4j.properties
hive>
常见问题
1.Permission denied: user=dr.who, access=READ_EXECUTE, inode="/tmp":root:supergroup:drwx------
修改一下权限
[root@hadoop01 bin]# ./hdfs dfs -chmod -R 777 /tmp
2.hive启动beeline连接报错: User: xxx is not allowed to impersonate anonymous (state=08S01,code=0)
解决方式:在hadoop的配置文件core-site.xml增加如下配置,重启hdfs,其中“xxx”是连接beeline的用户,将“xxx”替换成自己的用户名即可
<property>
<name>hadoop.proxyuser.xxx.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.xxx.groups</name>
<value>*</value>
</property>
“*”表示可通过超级代理“xxx”操作hadoop的用户、用户组和主机
如果在hive之前安装了spark,可能出现以下错误:
初次启动hive,解决 ls: cannot access /home/hadoop/spark-2.2.0-bin-hadoop2.6/lib/spark-assembly-.jar: No such file or directory问题
spark升级到spark2以后,原有lib目录下的大JAR包被分散成多个小JAR包,原来的spark-assembly-.jar已经不存在,所以hive没有办法找到这个JAR包。
解决方法
打开hive的安装目录下的bin目录,找到hive文件
cd $HIVE_HOME/bin
vi hive
找到下图中的位置
将鼠标定位的位置,更改成下图
这样问题就解决了。