1. 下载安装
1.1 这里选择安装的是3.1.2,使用下面命令进行下载:
1 # cd ~/software
2 wget http://mirror.bit.edu.cn/apache/hive/hive-3.1.2/apache-hive-3.1.2-bin.tar.gz
1.2 解压重命名
1 tar -xzvf apache-hive-3.1.2-bin.tar.gz
2 mv apache-hive-3.1.2-bin.tar.gz hive
1.3 配置环境变量
使用vim编辑~/.bashrc文件,加入以下配置(目录换成自己的安装目录):
1 # hive home /software/hive
2 export HIVE_HOME=/software/hive
3 export PATH=$PATH:$HIVE_HOME/bin
使用source命令使配置生效: source ~/.bashrc
可以使用echo $PATH 输出查看是否正确
2. 简单配置
2.1 配置hive-env.sh
文件位置:$HIVE_HOME/hive/conf/hive-env.sh.template
命令:
1 cd /software/hive/conf
2 # 复制并重命名
3 cp hive-env.sh.template hive-env.sh
4 vim hive-env.sh
配置如下:
1 # 相应的目录换成自己的
2 # hadoop 目录
3 HADOOP_HOME=/software/hadoop
4
5 # hive 配置目录
6 export HIVE_CONF_DIR=/software/hive/conf
7
8 # hive 的lib目录
9 export HIVE_AUX_JARS_PATH=/software/hive/lib
2.2 创建并配置hive-site.xml
文件位置: $HIVE_HOME/hive/conf/
命令:
1 cd /software/hive/conf
2 # 会自动创建
3 vim hive-site.xml
配置:
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
3 <configuration>
4
5 <property>
6 <name>javax.jdo.option.ConnectionURLname>
7 <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&useSSL=falsevalue>
8 property>
9
10 <property>
11 <name>javax.jdo.option.ConnectionDriverNamename>
12 <value>com.mysql.jdbc.Drivervalue>
13 property>
14
15 <property>
16 <name>javax.jdo.option.ConnectionUserNamename>
17 <value>rootvalue>
18 property>
19
20 <property>
21 <name>javax.jdo.option.ConnectionPasswordname>
22 <value>*******value>
23 property>
24 <property>
25 <name>datanucleus.readOnlyDatastorename>
26 <value>falsevalue>
27 property>
28 <property>
29 <name>datanucleus.fixedDatastorename>
30 <value>falsevalue>
31 property>
32 <property>
33 <name>datanucleus.autoCreateSchemaname>
34 <value>truevalue>
35 property>
36 <property>
37 <name>datanucleus.schema.autoCreateAllname>
38 <value>truevalue>
39 property>
40 <property>
41 <name>datanucleus.autoCreateTablesname>
42 <value>truevalue>
43 property>
44 <property>
45 <name>datanucleus.autoCreateColumnsname>
46 <value>truevalue>
47 property>
48 <property>
49 <name>hive.metastore.localname>
50 <value>truevalue>
51 property>
52
53 <property>
54 <name>hive.cli.print.headername>
55 <value>truevalue>
56 property>
57
58 <property>
59 <name>hive.cli.print.current.dbname>
60 <value>truevalue>
61 property>
62 <property>
63 <name>hive.exec.local.scratchdirname>
64 <value>/usr/local/hivevalue>
65 <description>Local scratch space for Hive jobsdescription>
66 property>
67
68 <property>
69 <name>hive.downloaded.resources.dirname>
70 <value>/usr/local/hive/hive-downloaded-addDir/value>
71 <description>Temporary local directory for added resources in the remote file system.description>
72 property>
73 <property>
74 <name>hive.querylog.locationname>
75 <value>/usr/local/hive/querylog-location-addDir/value>
76 <description>Location of Hive run time structured log filedescription>
77 property>
78 <property>
79 <name>hive.server2.logging.operation.log.locationname>
80 <value>/usr/local/hive/hive-logging-operation-log-addDir/value>
81 <description>Top level directory where operation logs are stored if logging functionality is enableddescription>
82 property>
83
84 configuration>
2.3 格式化数据库及验证
1 # 格式化数据库
2 schematool -dbType mysql -initSchema
3
4 # 启动hive
5 hive
6
7 # 查看数据库
8 hive> show databases;
Tips:
1.如报错显示没有数据库连接驱动则下载mysql驱动包到hive目录下的lib目录下
1 cd /software/hive/lib
2 wget http://central.maven.org/maven2/mysql/mysql-connector-java/6.0.6/mysql-connector-java-6.0.6.jar
2.自定义hive的连接用户名和密码