环境准备
搭建hive之前先完成jdk1.8,hadoop2.5.2和mysql5.7的安装与配置
下载hive1.2.2(https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-1.2.2/apache-hive-1.2.2-bin.tar.gz)
系统安装
选择一台hadoop NN节点设备,把hive压缩包上传到该服务器上。
1.解压hive文件
tar zxvf apache-hive-1.2.2-bin.tar.gz -C /usr
2.修改目录位置
mv apache-hive-1.2.2-bin hive
3.授权hive目录操作权限给hadoop用户
chown -r hadoop:hadoop hive
4.复制默认配置文件的模板文件为hive-site.xml
cp /usr/hive/conf/hive-default.xml.template /usr/hive/conf/hive-site.xml
系统配置
1.修改元数据存储的数据库信息,如果此处不修改数据库信息,默认的元数据存储在本地的文件数据库中,这样不利于hive的迁移和数据恢复。参照一下代码,修改hive-site.xml配置信息
<!--修改元数据存储的关系型数据库连接地址 -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>n/
<!-- 修改数据库连接驱动-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<!-- 修改数据库用户名-->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>
<!-- 修改数据库密码-->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
<description>password to use against metastore database</description>
</property>
2.修改/etc/profile文件,设置环境变量后,会让hive自动找到hadoop信息。
export HIVE_HOME=/usr/hive
export PATH=$PATH:/usr/hadoop/sbin:/usr/hadoop/bin:$HIVE_HOME/bin
启动hive
cd /usr/hive/bin
./hive
hive server配置
cd /usr/hive/bin
1.后台启动hive server
nohup ./hive --service hiveserver2 > /usr/hive/logs/hive.log 2>&1 &
验证hive server启动是否成功
ss -lpnt | grep 10000
启动连接hive server的客户端
./beeline
连接hive服务端
!connect jdbc:hive2://master-2:10000/test
默认情况下用户为root,密码为空
修改hdfs文件系统中/tmp目录的权限,如果不修改权限,无法再beeline中执行hive sql语句进行hive操作
./hdfs dfs -chmod -R 777 /tmp
常见问题解决
常见问题1:
[ERROR] Terminal initialization failed; falling back to unsupported
java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
at jline.TerminalFactory.create(TerminalFactory.java:101)
at jline.TerminalFactory.get(TerminalFactory.java:158)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:229)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:221)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:209)
at org.apache.hadoop.hive.cli.CliDriver.getConsoleReader(CliDriver.java:773)
at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:715)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:675)
at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:615)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
原因:
hadoop目录下存在老版本jline:
/hadoop-2.6.0/share/hadoop/yarn/lib:
-rw-r--r-- 1 root root 87325 Mar 10 18:10 jline-0.9.94.jar
解决:
rm -rvf /hadoop-2.5.2/share/hadoop/yarn/lib/jline-0.9.94.jar
cp -r /hive/lib/jline-2.12.jar /hadoop-2.5.2/share/hadoop/yarn/lib
常见问题2:
[ERROR] Terminal initialization failed; falling back to unsupported
java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
at jline.TerminalFactory.create(TerminalFactory.java:101)
at jline.TerminalFactory.get(TerminalFactory.java:158)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:229)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:221)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:209)
at org.apache.hadoop.hive.cli.CliDriver.getConsoleReader(CliDriver.java:773)
at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:715)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:675)
at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:615)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
原因:
hadoop目录下存在老版本jline:
/hadoop-2.6.0/share/hadoop/yarn/lib:
-rw-r--r-- 1 root root 87325 Mar 10 18:10 jline-0.9.94.jar
解决:
rm -rvf/hadoop-2.5.2/share/hadoop/yarn/lib/jline-0.9.94.jar
cp -r /hive/lib/jline-2.12.jar /hadoop-2.5.2/share/hadoop/yarn/lib
网友评论