开始前:
什么是Beeline?HiveServer2支持一个新的命令行Shell,称为Beeline,它是基于SQLLine CLI的JDBC客户端;在Hive0.14版本开始官方推荐Beeline来使用HiveServer2来替代HiveCLI,后续版本HiveCLI渐渐消失;Beeline支持嵌入模式(embedded mode)和远程模式(remote mode),嵌入模式运行嵌入式的HIVE(类似HiveCLI),远程模式通过Thrift连接到独立的HiveServer2进程上
1、Java 1.7
Note:注意:Hive 1.2以后的版本需要Java 1.7或更新版本。Hive版本0.14到1.1也可以使用Java 1.6。强烈建议用户开始迁移到Java 1.8
2、Hadoop 2.x(首选),1.x(在Hive2.0.0之前不支持)
#笔者在Hadoop上选择Hadoop-2.8.5
tar -zxvf hive-3.1.0.tar.gz #解压,我的是将hive-3.1.0解压到名为hive的文件夹内
vim /etc/profile #编辑环境变量文件
export HIVE_HOME=/hadoopeco/hive/apache-hive-3.1.0-bin
export PATH=${HIVE_HOME}/bin:$PATH
export CLASSPATH=$CLASSPATH:${HIVE_HOME}/lib/*
cp hive-env.sh.template hive-env.sh #$HIVE_HOME/conf目录下,在hive-env.sh中添加
export HADOOP_HOME=
cp hive-default.xml.template hive-site.xml
vim hive-site.xml (或vi hive-site.xml)
通过"to 1100"命令,跳转到1100多行这样,或者通过Sublime Text来find会更快
修改hive-site.xml:
javax.jdo.option.ConnectionPassword
123456
password to use against metastore database
javax.jdo.option.ConnectionURL
jdbc:mysql://master:3306/hive?createDatabaseIfNotExist=true
JDBC connect string for a JDBC metastore.
To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
Driver class name for a JDBC metastore
javax.jdo.option.ConnectionUserName
root
Username to use against metastore database
javax.jdo.option.Multithreaded
true
Set this to true if multiple threads access metastore through JDO concurrently.
hive.metastore.schema.verification
false
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.
必须使用HDFS命令创建 /tmp 和 /user/hive/warehouse (hive.metastore.warehouse.dir)和
在HIve创建表前将这两个文件夹设置为chmod g+w,如下
$HADOOP_HOME/bin/hadoop fs -mkdir /tmp
$HADOOP_HOME/bin/hadoop fs -mkdir /user/hive/warehouse
$HADOOP_HOME/bin/hadoop fs -chmod g+w /tmp
$HADOOP_HOME/bin/hadoop fs -chmod g+w /user/hive/warehouse
在$HIVE_HOME/conf/hive-site.xml中进行配置
hive.metastore.warehouse.dir
hdfs://master:8020/user/hive/warehouse
location of default database for the warehouse
将mysql-connector-java-5.1.39-bin.jar(可以用其它版本的驱动)驱动复制到$HIVE_HOME/lib中
初始化hive:
$HIVE_HOME/bin/schematool -dbType mysql -initSchema
截图:
在MySQL Workbench中发现名为“hive”的数据库已经被创建:
mkdir $HIVE_HOME/tmp
将hive-site.xml中的system:java.io.tmpdir修改为自定义的tmp所在绝对路径,将system:user.name修改为user.name