==Hive条件==

  Hive的条件必需求搭载在hadoop集群上,作为hadoop集群的数据仓库运用,所以你先需求有个hadoop集群,关于hadoop集群的建立,你能够参阅博客Hadoop集群大数据解决方案之建立Hadoop3.X+HA形式(二)。   这篇建立hadoop集群用的是hadoop3.x,其实纯属装逼,咱们这儿需求用到的最好是hadoop-2.8.5+hive-2.3.5,关于hadoop2.x和hadoop3.x的装置差异,这位装逼的博主现已标注清楚了,请放心运用。

==Hive下载==

  这儿运用Hive 2.3.5版别为例子:   官网下载地址:archive.apache.org/dist/hive/h…   一般是下载编译好的bin.tar.gz包:apache-hive-2.3.5-bin.tar.gz,如图1

Hive从入门到放弃——Hive安装和基本使用(二)

图1 下载tar包挑选

==装置metadata库==

==选用MySQL且新建hive数据库==

  为了合作Hadoop宗族开源的精力,这么metadata就选用MySQL,先在集群的某一台机器装置好MySQL,不会装置MySQL就找DBA吧,DBA不理你的话你就能够看看这篇博客Linux(CentOS-7)下装置MySQL-5.7.30 ,然后把在这MySQL上新建好hive库,选用坑少的字符集utf8mb4_unicode_ci,后需求用到,实践运用中 ,一般不会用MySQL的root用户办理MySQL,所以需求后在MySQL服务器上新增hive用户,并把hive库的一切权限赋予hive,能够参阅博客MySQL新建数据库,用户办理及授权办理简介;

create DATABASE hive   DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

==给Hive准备衔接MySQL的驱动==

  之条件到过,Hive的metadata库纷歧定是MySQL,所以针对不同类型库的必然需求不同的衔接驱动Jar包,然后现在的版别Hive并没有给你ready这个Jar包,所以需求自己保证Hive目录下的lib下有mysql的衔接驱动mysql-connector-java-xxx.jar,xxx是要兼容装置的metadata的mysql版别,我的是MySQL-5.7.30,所以我下载mysql-connector-java-8.0.13.jar,直接去官网下载即可,下载时需求登录/注册Oracle账号,然后放到你的Hive的/lib目录下,如我的/data/tools/apache-hive-2.3.5-bin/lib,再经过以下指令修改下这个驱动Jar包的权限;

chmod 755 mysql-connector-java-8.0.13.jar

   mysql-connector-java-xxx.jar下载传送门;

==装置装备==

  下载好Hive后得到是一个tar包apache-hive-2.3.5-bin.tar.gz,一般默认下载后tar权限比较低,运用chmod 755 apache-hive-2.3.5-bin.tar.gz 修改下权限,然后解压tar包tar -zxvf apache-hive-2.3.5-bin.tar.gz,然后 进入解压的folderapache-hive-2.3.5-bin,预览下得到以下文件夹,其间conf是装备相关文件夹,bin 是发动相关的文件夹。

[hadoop@node1 apache-hive-2.3.5-bin]$ ll
总用量 56
drwxrwxr-x. 3 hadoop hadoop   133 5月   5 10:59 bin
drwxrwxr-x. 2 hadoop hadoop  4096 5月   5 10:59 binary-package-licenses
drwxrwxr-x. 2 hadoop hadoop  4096 5月   5 10:59 conf
drwxrwxr-x. 4 hadoop hadoop    34 5月   5 10:59 examples
drwxrwxr-x. 7 hadoop hadoop    68 5月   5 10:59 hcatalog
drwxrwxr-x. 2 hadoop hadoop    44 5月   5 10:59 jdbc
drwxrwxr-x. 4 hadoop hadoop 12288 5月   5 10:59 lib
-rw-r--r--. 1 hadoop hadoop 20798 5月   7 2019 LICENSE
-rw-r--r--. 1 hadoop hadoop   230 5月   8 2019 NOTICE
-rw-r--r--. 1 hadoop hadoop   277 5月   8 2019 RELEASE_NOTES.txt
drwxrwxr-x. 4 hadoop hadoop    35 5月   5 10:59 scripts

==装备环境变量==

  运用vim /etc/profile新增Hive的环境变量,如下,其间/data/tools/apache-hive-2.3.5-bin为我的Hive的根目录,大家依据自己想把Hive装置的方位来写,不可照搬,增加该目录下的$PATH:$HIVE_HOME/bin目录是为了发动Hive便利,然后保存退出 /etc/profile文件,别忘了source /etc/profile来改写环境变量文件;

export HIVE_HOME=/data/tools/apache-hive-2.3.5-bin
export PATH=$PATH:$HIVE_HOME/bin

  精确装备好以后,就可运用Hive --version来检查自己Hive装置的版别了,如下:

[hadoop@node1 tools]$ hive --version
Hive 2.3.5
Git git://HW13934/Users/gates/git/hive -r 76595628ae13b95162e77bba365fe4d2c60b3f29
Compiled by gates on Tue May 7 15:45:09 PDT 2019
From source with checksum c7864fc25abcb9cf7a36953ac6be4665

==Hive在集群中的布局装备==

  Hive的装备,选定一个Hive的master,其他的节点为slaves,master和slaves的装备略有不同,不是彻底照搬,当然精确的来说,应该是只要一个节点是Hive的服务器节点担任和元数据库以及集群内部通讯,其他的Hive节点其实是装的client,这些节点在拜访元数据库时,先会内部跳转到Hive服务器的节点,所以Hive服务器节点和客户端节点的装备略有不同;   咱们建立好的hadoop开发集群4个节点,咱们选用装备如下,选用node1为hive的服务器节点,在四个节点上都装一下hive的客户端,其实其他节点不装hive客户端也能够,便是你是用hive cli的时分不能在其他节点运用,道理也很好了解对吧,除了这一点,并不影响啥。

  • NN hadoop集群namenode
  • DN hadoop集群datanode
  • ZK hadoop集群zookeeper
  • ZKFC hadoop集群Zookeeper Failover Controller高可用故障搬运机制
  • JN Journal Node寄存hadoop集群的元数据
metadata(MySQL) hive master hive client NN DN ZK ZKFC JN RM DM
node1 1 1 1 1 1 1 1
node2 1 1 1 1 1 1 1
node3 1 1 1 1 1
node4 1 1 1 1

==Hive的master节点装备==

  之前说了,咱们的hive master节点其实是起到服务器的作用,装备和客户端有不同的,所以在node1节点,进入hive目录下的/conf目录,由于Hive只要一个自带的hive-default.xml.template文件,所以咱们需求以此仿制一个hive-site.xml出来,然后修改里边的装备内容,这些shell指令如下:

# 进入hive的conf目录下
cd /data/tools/apache-hive-2.3.5-bin/conf

# 以hive-default.xml.template为源文件仿制生成一个hive-site.xml
cp hive-default.xml.template hive-site.xml

#修改hive-site.xml文件
vim hive-site.xml

  hive master节点的hive-site.xml的装备内容如下,我只是简单的借去了我的hive装备的部分必要的,可是有幸偷师了百度大佬的5000行的装备文件,许多装备都调整的相对较优,由于5000多行写不下,就只能放在资源包里边了,里边有master节点和slave节点的别离装备,感兴趣的能够去下载:hive-2.3.5装备文件.rar;

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<configuration>
 <!-- WARNING!!! This file is auto generated for documentation purposes ONLY! -->
 <!-- WARNING!!! Any changes you make to this file will be ignored by Hive.   -->
 <!-- WARNING!!! You must make your changes in hive-site.xml instead.         -->
 <!-- Hive Execution Parameters -->
<!--hive的元数据库衔接装备-->
<property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://node1:3306/hive?createDatabaseIfNotExist=true&amp;useUnicode=true&amp;characterEnconding=UTF-8</value>
</property>
<!--hive的元数据库挑选jdbc驱动-->
<property>
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>com.mysql.cj.jdbc.Driver</value>
</property>
<!--hive的元数据库登录的用户名-->
<property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>hive</value>
</property>
<!--hive的元数据库登录的暗码-->
<property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>hive1234</value>
</property>
<property>
        <name>hive.metastore.schema.verification</name>
        <value>false</value>
   <description>
     Enforce metastore schema version consistency.
     True: Verify that version information stored in is compatible with one from Hive jars.  Also disable automatic
           schema migration attempt. Users are required to manually migrate schema after Hive upgrade which ensures
           proper metastore schema migration. (Default)
     False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.
   </description>
</property>
<property>
   <name>hive.server2.thrift.bind.host</name>
   <value>node1</value>
   <description>Bind host on which to run the HiveServer2 Thrift service.</description>
 </property>
<!--hive的监听端口-->
<property> 
   <name>hive.metastore.port</name>  
   <value>9083</value>  
   <description>Hive metastore listener port</description> 
 </property> 
<property>
<!--这儿是装备hive能够衔接jdbc,很实用-->
<property>
   <name>hive.server2.thrift.port</name>
   <value>10000</value>
   <description>Port number of HiveServer2 Thrift interface when hive.server2.transport.mode is 'binary'.</description>
</property>
 <property>
   <name>hive.server2.thrift.http.port</name>
   <value>10001</value>
   <description>Port number of HiveServer2 Thrift interface when hive.server2.transport.mode is 'http'.</description>
 </property>
</configuration>

  hive的slave装备,即客户端节点的装备

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
       Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<configuration> 
 <!-- WARNING!!! This file is auto generated for documentation purposes ONLY! -->  
 <!-- WARNING!!! Any changes you make to this file will be ignored by Hive.   -->  
 <!-- WARNING!!! You must make your changes in hive-site.xml instead.         -->  
 <!-- Hive Execution Parameters -->  
 <property> 
   <name>hive.metastore.local</name>  
   <value>false</value> 
 </property>  
 <property> 
   <name>hive.metastore.warehouse.dir</name>  
   <value>/hive/warehouse</value>  
   <description>location of default database for the warehouse</description> 
 </property>  
 <property> 
   <name>hive.metastore.uris</name>  
   <value>thrift://node1:9083</value>  
   <description>Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.</description> 
 </property>  
 <property> 
   <name>hive.metastore.schema.verification</name>  
   <value>false</value>  
   <description>Enforce metastore schema version consistency. True: Verify that version information stored in is compatible with one from Hive jars. Also disable automatic schema migration attempt. Users are required to manually migrate schema after Hive upgrade which ensures proper metastore schema migration. (Default) False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.</description> 
 </property>  
 <property> 
   <name>hive.server2.transport.mode</name>  
   <value>binary</value>  
   <description>Expects one of [binary, http]. Transport mode of HiveServer2.</description> 
 </property>  
 <property> 
   <name>hive.server2.thrift.bind.host</name>  
   <value>node1</value>  
   <description>Bind host on which to run the HiveServer2 Thrift service.</description> 
 </property>  
 <property> 
   <name>hive.driver.parallel.compilation</name>  
   <value>false</value>  
   <description>Whether to enable parallel compilation of the queries between sessions and within the same session on HiveServer2. The default is false.</description> 
 </property>  
 <property> 
   <name>hive.server2.metrics.enabled</name>  
   <value>false</value>  
   <description>Enable metrics on the HiveServer2.</description> 
 </property>  
 <property> 
   <name>hive.server2.thrift.http.port</name>  
   <value>10001</value>  
   <description>Port number of HiveServer2 Thrift interface when hive.server2.transport.mode is 'http'.</description> 
 </property>  
 <property> 
   <name>hive.server2.thrift.http.path</name>  
   <value>cliservice</value>  
   <description>Path component of URL endpoint when in HTTP mode.</description> 
 </property>  
 <property> 
   <name>hive.server2.thrift.max.message.size</name>  
   <value>104857600</value>  
   <description>Maximum message size in bytes a HS2 server will accept.</description> 
 </property>  
 <property> 
   <name>hive.server2.thrift.http.max.idle.time</name>  
   <value>1800s</value>  
   <description>Expects a time value with unit (d/day, h/hour, m/min, s/sec, ms/msec, us/usec, ns/nsec), which is msec if not specified. Maximum idle time for a connection on the server when in HTTP mode.</description> 
 </property>  
 <property> 
   <name>hive.server2.thrift.http.worker.keepalive.time</name>  
   <value>60s</value>  
   <description>Expects a time value with unit (d/day, h/hour, m/min, s/sec, ms/msec, us/usec, ns/nsec), which is sec if not specified. Keepalive time for an idle http worker thread. When the number of workers exceeds min workers, excessive threads are killed after this time interval.</description> 
 </property>  
 <property> 
   <name>hive.metastore.port</name>  
   <value>9083</value>  
   <description>Hive metastore listener port</description> 
 </property> 
<property>
   <name> mapreduce.job.queuename</name>
   <value>etl</value>
   <description>
     Used to specify name of Hadoop queue to which
     jobs will be submitted.  Set to empty string to let Hadoop choose the queue.
   </description>
 </property>
</configuration>

==初始化Hive==

    第一次发动前需求初始化metadata库,其实便是把hive的相关元数据写入到咱们准备的MySQL的hive库里边,初始化的shell指令schematool -dbType mysql -initSchema,详细如下:

[hadoop@node1 conf]$ schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/data/tools/apache-hive-2.3.5-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/data/tools/hadoop-2.8.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]
Metastore connection URL:        jdbc:mysql://node1:3306/hive?createDatabaseIfNotExist=true&useUnicode=true&characterEnconding=UTF-8
Metastore Connection Driver :    com.mysql.cj.jdbc.Driver
Metastore connection User:       hive
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.mysql.sql
Initialization script completed
schemaTool completed

   成功初始化后,能够看到元数据库hive内新增了许多表,这些表便是用来存储hive的元数据的,这儿知道就行,先不做详细介绍。

Hive从入门到放弃——Hive安装和基本使用(二)

图2 初始化后元数据MySQL的hive发生变化

   初始化其实便是把/data/tools/apache-hive-2.3.5-bin/scripts/metastore/upgrade/mysql下的相关sql句子设法在MySQL的hive库里边跑一下,一定要保证metadata的hive库初始化成功,留心字眼: schematool completed,假如遇到初始化报错,如没权限登录hive,则看一下自己的master节点hive-site.xml装备的登录元数据库hive的装备信息是否精确,其他异常能够百度相关的装备调整,这儿就纷歧一列举了 ,一般原始是由于选的mysql版别和驱动不对应,或许mysql对索引长度做了限制或许其他限制,导致Hive初始化建表失利,或许便是登录元数据库hive的IP,端口,用户名,暗码等写的不对,初始化正常后,就能够在master节点先尝试下运用hive了,详细如下;

[hadoop@node1 conf]$ hive
which: no hbase in (/data/tools/jdk1.8.0_211/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/data/tools/apache-hive-2.3.5-bin/bin:/data/tools/zookeeper-3.4.14:/data/tools/hadoop-2.8.5/sbin:/data/tools/hadoop-2.8.5/bin:/data/tools/mysql-5.7.30-linux-glibc2.12-x86_64/bin:/home/hadoop/.local/bin:/home/hadoop/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/data/tools/apache-hive-2.3.5-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/data/tools/hadoop-2.8.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]
Logging initialized using configuration in jar:file:/data/tools/apache-hive-2.3.5-bin/lib/hive-common-2.3.5.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
Time taken: 31.212 seconds, Fetched: 1 row(s)
hive> create database dw;
OK
Time taken: 0.884 seconds

   这个时分假如发动客户端节点,及slave节点的hive,或许会报错,如下,不要慌,这是由于咱们采用master节点作为服务器的形式,那么咱们要把hive的服务器发动,保证客户端形式能拜访。


[hadoop@node2 conf]$ hive
which: no hbase in (/data/tools/jdk1.8.0_211/bin:/data/tools/jdk1.8.0_211/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/data/tools/zookeeper-3.4.14:/data/tools/hadoop-2.8.5/sbin:/data/tools/hadoop-2.8.5/bin:/home/hadoop/.local/bin:/home/hadoop/bin:/data/tools/apache-hive-2.3.5-bin/bin:/data/tools/zookeeper-3.4.14:/data/tools/hadoop-2.8.5/sbin:/data/tools/hadoop-2.8.5/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/data/tools/apache-hive-2.3.5-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/data/tools/hadoop-2.8.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]
Logging initialized using configuration in jar:file:/data/tools/apache-hive-2.3.5-bin/lib/hive-common-2.3.5.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;
FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

==发动Hive服务==

  能够在你的hive目录下,新建一个shell文件start_hive.sh, shell指令vim /data/tools/apache-hive-2.3.5-bin/start_hive.sh,里边内容如下,然后保存退出;

#!/usr/bin/env bash

#后台发动hive service
nohup hive --service metastore >> /data/logs/hive/meta.log 2>&1 &

#后台发动hive 的jdbc service
nohup  hive --service hiveserver2 >> /data/logs/hive/hiveserver2.log 2>&1 &

  精确发动后,jps指令能查到两个RunJar进程对应hive的本身service和hive的jdbc service,要 重启hive的话,就先kill这两个RunJar,然后在运行这个脚本即可,留意:jdbc衔接hive的装备为冷加载,什么意思呢,假设你改了一个hdfs或许hive的装备,你要是用jdbc衔接的hive,纷歧定能改写到新的装备,乃至或许会报错,如你修改了hdfs块的大小,另一边你用jdbc在查询hive表,或许会引发异常,这个时分你需求重启一下hive的jdbc service,jps检查如下:

[hadoop@node1 apache-hive-2.3.5-bin]$ jps
8195 DFSZKFailoverController
15686 Jps
7607 NameNode
15303 RunJar
6408 QuorumPeerMain
15304 RunJar

==cli衔接hive==

  博客Hive从入门到抛弃——Hive布景和根底架构介绍(一)讲了衔接hive的几种形式,其间比较常用的有cli形式,由于咱们装备好了hive环境变量,只需求直接在shell下hive 即可进入,详细如下;


[hadoop@node2 conf]$ hive
which: no hbase in (/data/tools/jdk1.8.0_211/bin:/data/tools/jdk1.8.0_211/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/data/tools/zookeeper-3.4.14:/data/tools/hadoop-2.8.5/sbin:/data/tools/hadoop-2.8.5/bin:/home/hadoop/.local/bin:/home/hadoop/bin:/data/tools/apache-hive-2.3.5-bin/bin:/data/tools/zookeeper-3.4.14:/data/tools/hadoop-2.8.5/sbin:/data/tools/hadoop-2.8.5/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/data/tools/apache-hive-2.3.5-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/data/tools/hadoop-2.8.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]
Logging initialized using configuration in jar:file:/data/tools/apache-hive-2.3.5-bin/lib/hive-common-2.3.5.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;
FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

==运用JDBC衔接hive==

  条件保证自己的hive装备了jdbc衔接,并且 发动了jdbc service,然后经过shell指令的jdbc衔接如下:

办法1 beeline !connect jdbc:hive2://dw-test-cluster-007:10000 输入用户名,输入暗码; 办法2: 或许 beeline -u “jdbc:hive2://dw-test-cluster-007:10000” -n hadoop hadoop -u : 指定元数据库的链接信息 -n : 指定用户名和暗码

  shell环境下jdbc衔接效果如下:

[hadoop@node1 apache-hive-2.3.5-bin]$  beeline -u "jdbc:hive2://node1:10000" -n hadoop hadoop
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/data/tools/apache-hive-2.3.5-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/data/tools/hadoop-2.8.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]
Connecting to jdbc:hive2://node1:10000
Connected to: Apache Hive (version 2.3.5)
Driver: Hive JDBC (version 2.3.5)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 2.3.5 by Apache Hive
0: jdbc:hive2://node1:10000> show databases;
+----------------+
| database_name  |
+----------------+
| default        |
| dw             |
+----------------+
2 rows selected (5.817 seconds)
0: jdbc:hive2://node1:10000>

  也能够用支撑jdbc的ide东西衔接,详细运用可参阅Hive从入门到抛弃——Hive常用衔接东西引荐(三);   留意:jdbc的稳定性没有cli的好,第一,hive里边的jdbc是冷加载,你新改动的hdfs或许hive装备,jdbc纷歧定能实时获取到,需求重启加载,第二,jdbc的service或许受到已知的,不知道的原因导致断开,假如你在shell环境下运用以上jdbc的指令都无法正确 衔接上的话,就要想想是不是jdbc的service断了。

==根本运用==

  装置中难免会遇到坑,百度,必应解决一切装置问题后,正常发动,直接在集群内部按的shell环境下输入hive,会调转如图2,留意正常发动的时分也是干净利落的,假如发动中会报错,就算最终跳出了’hive>’的CLI环境,也是有装备不完美的地方,再百度,必应修正,能够运用cli或许jdbc形式登录hive后,进行简单的句子测验下Hive是否可用。

--Hive SQL跟MySQL很类似,可是不是彻底相同,数据类型也是纷歧样的,有MySQL根底相对学起来友好些
show databases; --检查DBs
use default; --切换到default库
--建表
--留意,Hive内主键,索引,都不盛行运用,高版别尽管支撑可是很少人用,
--允许在文件后追加数据,不能行级别删除,修改数据,后续操作中会细讲
create table if not exists user(
id string comment 'openId', 
phone string comment '电话', 
user_name string comment '用户名', 
sex string comment '性别,直接存男女', 
certificate_no string comment '身份证',  
create_time string 
)
row format delimited fields terminated by '\t' NULL DEFINED AS '' stored as textfile;
select * from user limit 10;--查询

  留意:hive本身并没有像mysql相同不带用户名,暗码的登录验证,需求结合其他技能或许二次开发,可是许多自己建立的hive也不太关心这一点,而是经过防火墙端口等技能来限制hive的安全拜访,这个感兴趣的能够先自己研讨下。