Hive学习之路 (四)Hive的链接3种链接方式

 

正文web

1、CLI链接

进入到 bin 目录下,直接输入命令: 数据库

复制代码

[hadoop@hadoop3 ~]$ hive
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/apps/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/apps/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]apache

Logging initialized using configuration in jar:file:/home/hadoop/apps/apache-hive-2.3.3-bin/lib/hive-common-2.3.3.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive> show databases;
OK
default
myhive
Time taken: 6.569 seconds, Fetched: 2 row(s)
hive>浏览器

复制代码

启动成功的话如上图所示,接下来即可以作 hive 相关操做app

补充:ide

  一、上面的 hive 命令至关于在启动的时候执行:hive --service clioop

  二、使用 hive --help,能够查看 hive 命令能够启动那些服务spa

  三、经过 hive --service serviceName --help 能够查看某个具体命令的使用方式3d


2、HiveServer2/beeline

在如今使用的最新的 hive-2.3.3 版本中:都须要对 hadoop 集群作以下改变,不然没法使用

一、修改 hadoop 集群的 hdfs-site.xml 配置文件

加入一条配置信息,表示启用 webhdfs

<property>
 <name>dfs.webhdfs.enabled</name>
 <value>true</value>
</property>

二、修改 hadoop 集群的 core-site.xml 配置文件

加入两条配置信息:表示设置 hadoop 的代理用户

复制代码
<property>
 <name>hadoop.proxyuser.hadoop.hosts</name>
 <value>*</value>
</property>
<property>
 <name>hadoop.proxyuser.hadoop.groups</name>
 <value>*</value>
</property>
复制代码

配置解析:

hadoop.proxyuser.hadoop.hosts 配置成*的意义,表示任意节点使用 hadoop 集群的代理用户 hadoop 都能访问 hdfs 集群,hadoop.proxyuser.hadoop.groups 表示代理用户的组所属

以上操做作好了以后(最好重启一下HDFS集群),请继续作以下两步:

第一步:先启动 hiveserver2 服务

启动方式,(假如是在 hadoop3 上):

启动为前台:hiveserver2

复制代码
[hadoop@hadoop3 ~]$ hiveserver2
2018-04-04 10:21:49: Starting HiveServer2
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/apps/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/apps/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
复制代码

启动会多一个进程

启动为后台:

nohup hiveserver2 1>/home/hadoop/hiveserver.log 2>/home/hadoop/hiveserver.err &
或者:nohup hiveserver2 1>/dev/null 2>/dev/null &
或者:nohup hiveserver2 >/dev/null 2>&1 &

以上 3 个命令是等价的,第一个表示记录日志,第二个和第三个表示不记录日志

命令中的 1 和 2 的意义分别是:

1:表示标准日志输出

2:表示错误日志输出 若是我没有配置日志的输出路径,日志会生成在当前工做目录,默认的日志名称叫作: nohup.xxx

[hadoop@hadoop3 ~]$ nohup hiveserver2 1>/home/hadoop/log/hivelog/hiveserver.log 2>/home/hadoop/log/hivelog/hiveserver.err &
[1] 4352
[hadoop@hadoop3 ~]$ 

PS:nohup 命令:若是你正在运行一个进程,并且你以为在退出账户时该进程还不会结束, 那么可使用 nohup 命令。该命令能够在你退出账户/关闭终端以后继续运行相应的进程。 nohup 就是不挂起的意思(no hang up)。 该命令的通常形式为:nohup command &

第二步:而后启动 beeline 客户端去链接:

执行命令:

复制代码
[hadoop@hadoop3 ~]$ beeline -u jdbc:hive2//hadoop3:10000 -n hadoop
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/apps/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/apps/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
scan complete in 1ms
scan complete in 2374ms
No known driver to handle "jdbc:hive2//hadoop3:10000"
Beeline version 2.3.3 by Apache Hive
beeline> 
复制代码

-u : 指定元数据库的连接信息

-n : 指定用户名和密码

另外还有一种方式也能够去链接:

先执行 beeline

而后按图所示输入:!connect jdbc:hive2://hadoop02:10000

按回车,而后输入用户名,这个 用户名就是安装 hadoop 集群的用户名

复制代码
[hadoop@hadoop3 ~]$ beeline
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/apps/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/apps/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Beeline version 2.3.3 by Apache Hive
beeline> !connect jdbc:hive2://hadoop3:10000
Connecting to jdbc:hive2://hadoop3:10000
Enter username for jdbc:hive2://hadoop3:10000: hadoop
Enter password for jdbc:hive2://hadoop3:10000: ******
Connected to: Apache Hive (version 2.3.3)
Driver: Hive JDBC (version 2.3.3)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://hadoop3:10000> 
复制代码

接下来即可以作 hive 操做


3、Web UI

 一、 下载对应版本的 src 包:apache-hive-2.3.2-src.tar.gz

二、 上传,解压

tar -zxvf apache-hive-2.3.2-src.tar.gz

三、 而后进入目录${HIVE_SRC_HOME}/hwi/web,执行打包命令:

jar -cvf hive-hwi-2.3.2.war *

在当前目录会生成一个 hive-hwi-2.3.2.war

四、 获得 hive-hwi-2.3.2.war 文件,复制到 hive 下的 lib 目录中

cp hive-hwi-2.3.2.war ${HIVE_HOME}/lib/

五、 修改配置文件 hive-site.xml

复制代码
<property>
 <name>hive.hwi.listen.host</name>
 <value>0.0.0.0</value>
 <description>监听的地址</description>
</property>
<property>
 <name>hive.hwi.listen.port</name>
 <value>9999</value>
 <description>监听的端口号</description>
</property>
<property>
 <name>hive.hwi.war.file</name>
 <value>lib/hive-hwi-2.3.2.war</value>
 <description>war 包所在的地址</description>
</property>
复制代码

六、 复制所需 jar 包

  一、cp ${JAVA_HOME}/lib/tools.jar ${HIVE_HOME}/lib

  二、再寻找三个 jar 包,都放入${HIVE_HOME}/lib 目录:

    commons-el-1.0.jar

    jasper-compiler-5.5.23.jar

    jasper-runtime-5.5.23.jar

    否则启动 hwi 服务的时候会报错。

七、 安装 ant

一、 上传 ant 包:apache-ant-1.9.4-bin.tar.gz

二、 解压 tar -zxvf apache-ant-1.9.4-bin.tar.gz -C ~/apps/

三、 配置环境变量 vi /etc/profile 在最后增长两行: export ANT_HOME=/home/hadoop/apps/apache-ant-1.9.4 export PATH=$PATH:$ANT_HOME/bin 配置完环境变量别忘记执行:source /etc/profile

四、 验证是否安装成功

 

八、上面的步骤都配置完,基本就大功告成了。进入${HIVE_HOME}/bin 目录:

   ${HIVE_HOME}/bin/hive --service hwi

  或者让在后台运行: nohup bin/hive --service hwi > /dev/null 2> /dev/null &

九、 前面配置了端口号为 9999,因此这里直接在浏览器中输入: hadoop02:9999/hwi

十、至此大功告成

 

相关文章
相关标签/搜索