1. 下载hive安装包

2. 进入 conf 中  :  cp hive-default.xml.template hive-site.xml,  vi hive-site.xml

1) 找到如下对应的配置修改对应的值  (例如:  /javax.jdo.option.ConnectionURL)

<property>
  <name>javax.jdo.option.ConnectionUserName</name>
  <value>root</value>
</property>
<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>Gw_sp1226</value>
</property>
<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://gw-sp.novalocal:3306/hive</value>
</property>
<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <value>com.mysql.jdbc.Driver</value>
</property>

3.  cp hive-env.sh.template hive-env.sh,    vi  hive-env.sh

export HADOOP_HOME=/home/hadoop/hadoop   ##Hadoop安装路径

export HIVE_CONF_DIR=/home/hadoop/hive-2.1.1/conf    ##Hive配置文件路径
export HIVE_AUX_JARS_PATH=/usr/hive/apache-hive-2.2.0-bin/lib ##Hive lib 目录

4. 拷贝mysql-connector-java-5.1.7-bin.jar到hive的lib包中,(格式化json需要多加2个jar包json-serde-1.3.8-jar-with-dependencies.jar 和json-udf-1.3.8-jar-with-dependencies.jar, 具体参考如下flume存储数据到hive)

链接:https://pan.baidu.com/s/1suPzGJmtJlsROC6SVpcztQ 密码:zlgg

目标:  通过接受 1084端口的http请求信息, 存储到 hive数据库中,
osgiweb2.db为hive中创建的数据库名称
periodic_report5 为创建的数据表, flume配置如下:
a1.sources=r1
a1.channels=c1
a1.sinks=k1 a1.sources.r1.type = http
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port =
a1.sources.r1.handler=jkong.Test.HTTPSourceDPIHandler #a1.sources.r1.interceptors=i1 i2
#a1.sources.r1.interceptors.i1.type=regex_filter
#a1.sources.r1.interceptors.i1.regex=\\{.*\\}
#a1.sources.r1.interceptors.i2.type=timestamp
a1.channels.c1.type=memory
a1.channels.c1.capacity=
a1.channels.c1.transactionCapacity=
a1.channels.c1.keep-alive= a1.sinks.k1.type=hdfs
a1.sinks.k1.channel=c1
a1.sinks.k1.hdfs.path=hdfs://gw-sp.novalocal:1086/user/hive/warehouse/osgiweb2.db/periodic_report5
a1.sinks.k1.hdfs.fileType=DataStream
a1.sinks.k1.hdfs.writeFormat=Text
a1.sinks.k1.hdfs.rollInterval=
a1.sinks.k1.hdfs.rollSize=
a1.sinks.k1.hdfs.rollCount=
a1.sinks.k1.hdfs.idleTimeout= a1.sources.r1.channels=c1
a1.sinks.k1.channel=c1
复制代码
. 数据表创建: create table periodic_report5(id BIGINT, deviceId STRING,report_time STRING,information STRING) row format serde "org.openx.data.jsonserde.JsonSerDe" WITH SERDEPROPERTIES("id"="$.id","deviceId"="$.deviceId","report_time"="$.report_time","information"="$.information");
  2.1 将数据表中的字段也同样拆分成数据字段的创表语句(还没有试验, 暂时不用) 复制代码
create table periodic_report4(id BIGINT, deviceId STRING,report_time STRING,information STRUCT<actualTime:BIGINT,dpiVersionInfo:STRING,subDeviceInfo:STRING,wanTrafficData:STRING,ponInfo:STRING,eventType:STRING,potsInfo:STRING,deviceInfo:STRING,deviceStatus:STRING>) row format serde "org.openx.data.jsonserde.JsonSerDe" WITH SERDEPROPERTIES("input.invalid.ignore"="true","id"="$.id","deviceId"="$.deviceId","report_time"="$.report_time","requestParams.actualTime"="$.requestParams.actualTime","requestParams.dpiVersionInfo"="$.requestParams.dpiVersionInfo","requestParams.subDeviceInfo"="$.requestParams.subDeviceInfo","requestParams.wanTrafficData"="$.requestParams.wanTrafficData","requestParams.ponInfo"="$.requestParams.ponInfo","requestParams.eventType"="$.requestParams.eventType","requestParams.potsInfo"="$.requestParams.potsInfo","requestParams.deviceInfo"="$.requestParams.deviceInfo","requestParams.deviceStatus"="$.requestParams.deviceStatus");
复制代码
. 启动flume语句:flume 根目录 bin/flume-ng agent --conf ./conf/ -f ./conf/flume.conf --name a1 -Dflume.root.logger=DEBUG,console
. 启动hive语句: hive bin目录 hive 或者:
./hive -hiveconf hive.root.logger=DEBUG,console #带log信息启动

5.  进入  bin 目录

./schematool  -dbType mysql -initSchema  #初始化命令
如果初始化失败,可能原因是 mysql 权限问题,
  (1)通过 mysql -uroot -p 命令进入mysql中,
  (2)use mysql
  (3)select user,host,authentication_string from user;
  (4)查看 root 用户 权限是否对应的是 %,如果不是,输入如下命令进行修改,再进行查看
  (5)update user set host='%' where user='root';
./schematool -dbType mysql -info #查看

6.  在mysql中查看 hive的元数据库是否有表生成

7. bin 下  hive 启动hive,  输入  show tables;  (可以通过:   ./hive -hiveconf hive.root.logger=DEBUG,console    打印详细log启动  hive)

8. jdbc链接hive

package com.hive.testHiveJdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; public class HiveJDBCConnection {
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
// private static String url = "jdbc:hive2://223.105.1.203:1083/default";
private static String url = "jdbc:hive2://192.168.88.142:10000/osgiweb";
private static String userName = "hive";
private static String passWord = "hive"; public static void main(String[] args) {
try {
Class.forName(driverName);
Connection con = DriverManager.getConnection(url, userName,
passWord);
Statement stmt = con.createStatement();
String tableName = "periodic_report2";
String sql = null;
/* String sql = "drop table if exists " + tableName;
stmt.execute(sql);
// 创建表
sql = "create table"
+ tableName
+ " (key string,value string) row format delimited fields terminated by ',' stored as textfile ";
stmt.execute(sql);
//加载数据
String Path="/home/hive_1.txt";
sql ="load data local inpath '"+Path+"' into table "+tableName;
stmt.execute(sql); */
// 查询数据
sql ="select * from "+tableName;
ResultSet res = stmt.executeQuery(sql);
while(res.next()){
System.out.println(res.getString(1)+"\t"+res.getString(1));
} } catch (ClassNotFoundException e) {
System.out.println("没有找到驱动类");
e.printStackTrace();
} catch (SQLException e) {
System.out.println("连接Hive的信息有问题");
e.printStackTrace();
} }
}

9. maven pom.xml 配置

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.hive</groupId>
<artifactId>testHiveJdbc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>testHiveJdbc</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency> <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-jdbc -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>2.3.3</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
</exclusion>
<exclusion>
<groupId>org.htrace</groupId>
<artifactId>htrace-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-xc</artifactId>
</exclusion>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-kerberos-codec</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-i18n</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-asn1-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-util</artifactId>
</exclusion>
<exclusion>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.fusesource.leveldbjni</groupId>
<artifactId>leveldbjni-all</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency> </dependencies>
</project>

参考资料:  https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-JDBC

hive安装 jdbc链接hive的更多相关文章

  1. jdbc链接hive报错:java.lang.ClassNotFoundException: org.apache.thrift.transport.TTransport

    写了个jdbc连接hive2的demo,结果报错:java.lang.ClassNotFoundException: org.apache.thrift.transport.TTransport,实际 ...

  2. Hive安装与配置详解

    既然是详解,那么我们就不能只知道怎么安装hive了,下面从hive的基本说起,如果你了解了,那么请直接移步安装与配置 hive是什么 hive安装和配置 hive的测试 hive 这里简单说明一下,好 ...

  3. macbook hive安装

    1 原材料 1.1 已经安装好的伪分布式hadoop,版本2.8.3(参见链接https://www.cnblogs.com/wooluwalker/p/9128859.html) 1.2 apach ...

  4. 第2章 Hive安装

    第2章 Hive安装 2.1 Hive安装地址 1.Hive官网地址 http://hive.apache.org/ 2.文档查看地址 https://cwiki.apache.org/conflue ...

  5. Hive学习之路 (二)Hive安装

    Hive的下载 下载地址http://mirrors.hust.edu.cn/apache/ 选择合适的Hive版本进行下载,进到stable-2文件夹可以看到稳定的2.x的版本是2.3.3 Hive ...

  6. Apache Hive (二)Hive安装

    转自:https://www.cnblogs.com/qingyunzong/p/8708057.html Hive的下载 下载地址http://mirrors.hust.edu.cn/apache/ ...

  7. 一 Hive安装及初体验

    一 .Hive安装及初体验 1 .hive简介 Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供类SQL查询功能. 1.1直接使用hadoop面临的问题 ...

  8. 吴裕雄--天生自然HADOOP操作实验学习笔记:hive安装

    实验目的 了解hive的原理和安装方式 学习使用MySQL数据库 使用hive进行基本操作 实验原理 1.Hive Hive是一个数据仓库技术,包括解释器.编译器.优化器,一次将一个sql语句装化为m ...

  9. hive安装--设置mysql为远端metastore

    作业任务:安装Hive,有条件的同学可考虑用mysql作为元数据库安装(有一定难度,可以获得老师极度赞赏),安装完成后做简单SQL操作测试.将安装过程和最后测试成功的界面抓图提交 . 已有的当前虚拟机 ...

随机推荐

  1. Mac notes

    1. Mac应用数据存放位置 ~/Library/Application Support/ 比如sublime text的应用数据~/Library/Application Support/Subli ...

  2. 利用HttpWebRequest类Post数据至URI

    在与第三方系统进行数据对接时,需要把数据post到对方提供的一个url,然后进行相关处理. 这里可利用HttpWebRequest类,该类位于System.Net命名空间下.它提供了一些属性和方法可以 ...

  3. python3--列表生成式

    # Auther: Aaron Fan # 原始的写法:a = []for i in range(10): a.append(i*2)print(a) # 用列表生成式完成上面的写法:a = [i*2 ...

  4. combogrid change check multiple

    this.SetDict = function (obj, dicType, multiple, Ischeckbox, callback, change) { obj.combogrid({ pan ...

  5. hdu 4740 The Donkey of Gui Zhou

    1.扯犊子超多if else 判断的代码,华丽丽的TLE. #include<stdio.h> #include<string.h> #define N 1010 int ma ...

  6. numpy.loadtxt() 出现codecError_____ Excel 做矩阵乘法

    1) 用 numpy读入csv文件是报错 UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 2: illegal m ...

  7. Windows7下使用sphinx生成开源文档(原)

    作者这里以osgearth文档为例,感觉这种生成文档的方式比较好,生成的html文档是支持搜索的,感谢开源工作者的奉献.赞一个 1. 下载并安装python for windows:https://w ...

  8. 关于spring”通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明“的错误

    关于spring配置的问题 近日学习spring时遇到了这个问题: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreExcept ...

  9. C++的惨痛教训(未完待续)

    题记:只有痛才能让人铭记!痛促进进步~ 1. strncpy,大家都知道要做安全检查,可是谁都有嫌麻烦的时候,尤其是自己很自信不会产生溢出的时候,可能不会坑了自己,却会坑了使用这段代码的人.所以,1. ...

  10. Jmeter_远程启动

    Jmeter 是Java 应用,对于CPU和内存的消耗比较大,因此,当需要模拟数以千计的并发用户时,使用单台机器模拟所有的并发用户就有些力不从心,甚至会引起JAVA内存溢出错误. 其实,Jmeter的 ...