HIVE的安装
参考:Hive安装 - Hive教程? (yiibai.com)
安装包下载:Index of /infosystems/apache/hive/hive-1.2.2 (kddi-research.jp)
# 解压程序包到指定目录下/usr/local
tar -axvf apache-hive-3.1.2-bin.tar.gz -C /usr/local
# 切换到指定目录下
cd /usr/local
# 更改目录名
mv apache-hive-3.1.2-bin.tar.gz hive
# 配置HIVE中的环境配置:HADOOP_HOME=/usr/local/hadoop-2.7.3
[root@master conf]# cp hive-env.sh.template hive-env.sh
[root@master conf]#
[root@master conf]# pwd
/usr/local/hive/conf
[root@master conf]# vim hive-env.sh # 配置HADOOP_HOME变量
[root@master conf]#
# 设置环境变量
echo 'export HIVE_HOME=/usr/local/hive
export PATH=$PATH:$HIVE_HOME/bin
export CLASSPATH=$CLASSPATH:/usr/local/hadoop-2.7.3/lib/*:.
export CLASSPATH=$CLASSPATH:/usr/local/hive/lib/*:.' >> /etc/profile
# 使环境配置立即生效
source /etc/profile
安装 Derby数据库
wget http://archive.apache.org/dist/db/derby/db-derby-10.4.2.0/db-derby-10.4.2.0-bin.tar.gz
mkdir /usr/local/derby
tar -zxvf db-derby-10.4.2.0-bin.tar.gz -C /usr/local/derby
echo 'export DERBY_HOME=/usr/local/derby
export PATH=$PATH:$DERBY_HOME/bin
export CLASSPATH=$CLASSPATH:$DERBY_HOME/lib/derby.jar:$DERBY_HOME/lib/derbytools.jar' >> /etc/profile
source /etc/profile
# 创建一个名为data目录在$DERBY_HOME目录中,用于存储Metastore数据。
mkdir $DERBY_HOME/data
配置Hive的Metastore
通过编辑hive-site.xml 文件来指定Hive的数据库存储。
cp hive-default.xml.template hive-default.xml
# 编辑hive-site.xml并在<configuration>和</configuration>标记之间追加以下行:
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:derby://localhost:1527/metastore_db;create=true </value>
<description>JDBC connect string for a JDBC metastore </description>
</property>
# 创建一个文件名为 jpox.properties 并添加以下行:
javax.jdo.PersistenceManagerFactoryClass = org.jpox.PersistenceManagerFactoryImpl
org.jpox.autoCreateSchema = false
org.jpox.validateTables = false
org.jpox.validateColumns = false
org.jpox.validateConstraints = false
org.jpox.storeManagerType = rdbms
org.jpox.autoCreateSchema = true
org.jpox.autoStartMechanismMode = checked
org.jpox.transactionIsolation = read_committed
javax.jdo.option.DetachAllOnCommit = true
javax.jdo.option.NontransactionalRead = true
javax.jdo.option.ConnectionDriverName = org.apache.derby.jdbc.ClientDriver
javax.jdo.option.ConnectionURL = jdbc:derby://hadoop1:1527/metastore_db;create = true
javax.jdo.option.ConnectionUserName = APP
javax.jdo.option.ConnectionPassword = mine
# 运行Hive之前,需要创建在HDFS独立的Hive文件夹/tmp。在这里使用/user/hive/warehouse文件夹。
# 需要给这些新创建的文件夹写权限
hdfs dfs -mkdir /tmp
hdfs dfs -mkdir -p /user/hive/warehouse
hdfs dfs -chmod g+w /tmp
hdfs dfs -chmod g+w /user/hive/warehouse
# 进入hive命令行
[root@master conf]#
[root@master conf]# hive
Logging initialized using configuration in jar:file:/usr/local/hive/lib/hive-common-1.2.2.jar!/hive-log4j.properties
hive> show tables;
OK
Time taken: 0.979 seconds
hive>
使用beeline连接HIVE
# 先启动 metastore 服务
nohup hive --service metastore > /dev/null 2>&1 &
# 再启动 hiveserver2 服务
nohup hiveserver2 > /dev/null 2>&1 &
# 第一种连接方式
beeline -u jdbc:hive2://master:10000 -n root
# 配置alias
alias beeline='beeline -u jdbc:hive2://master:10000 -n root'
# 第二种连接方式
[root@master derby]# beeline # 进入beeline
Beeline version 1.2.2 by Apache Hive
beeline> !connect jdbc:hive2://master:10000 # 连接hive
Connecting to jdbc:hive2://master:10000
Enter username for jdbc:hive2://master:10000: root # 设置用户
Enter password for jdbc:hive2://master:10000: **** # 设置密码
Connected to: Apache Hive (version 1.2.2)
Driver: Hive JDBC (version 1.2.2)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://master:10000> show tables; # 查看所有
+-----------+--+
| tab_name |
+-----------+--+
| cx_stu01 |
| cx_stu02 |
+-----------+--+
2 rows selected (0.277 seconds)
0: jdbc:hive2://master:10000>
|