这篇文章主要介绍Hive如何安装、配置及基础使用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
10. Hive
此主题介绍Hive的安装、配置及基础使用。
Hive基本信息
官网:http://hive.apache.org/
10.1. 环境准备
# 切换到工作空间
cd /opt/workspaces
# 创建Hive数据目录
mkdir data/hive
# 创建Hive日志目录
mkdir logs/hive
10.2. 安装
wget http://mirrors.cnnic.cn/apache/hive/hive-1.2.1/apache-hive-1.2.1-bin.tar.gz
tar -zxf apache-hive-1.2.1-bin.tar.gz
rm -rf apache-hive-1.2.1-bin.tar.gz
mv apache-hive-1.2.1-bin ./frameworks/hive
10.3. 配置(单机)
vi ~/.profile
export HIVE_HOME=/opt/workspaces/frameworks/hive
export PATH=$PATH:$HIVE_HOME/bin
source ~/.profile
配置Mysql
mysql -u root -p
create database hive;
grant all on *.* to'hive'@'%' identified by 'hive'; #账号hive,密码hive,所有IP都可以访问(%)
flush privileges;
exit;
创建HDFS目录
./frameworks/hadoop/bin/hadoop fs -mkdir /tmp
./frameworks/hadoop/bin/hadoop fs -mkdir -p /user/hive/warehouse
./frameworks/hadoop/bin/hadoop fs -chmod 777 /tmp
./frameworks/hadoop/bin/hadoop fs -chmod 777 /user/hive/warehouse
修改Hive配置
cat>./frameworks/hive/conf/hive-env.sh<<EOF
export HADOOP_HEAPSIZE=1024
HADOOP_HOME=/opt/workspaces/frameworks/hadoop
export HIVE_CONF_DIR=/opt/workspaces/frameworks/hive/conf
export HIVE_AUX_JARS_PATH=/opt/workspaces/frameworks/hive/lib
EOF
cat>./frameworks/hive/conf/hive-site.xml<<EOF
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://`<Docker Host IP>`:3306/hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://bd:9083</value>
</property>
<property>
<name>hive.exec.local.scratchdir</name>
<value>/opt/workspaces/data/hive</value>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/opt/workspaces/data/hive</value>
</property>
<property>
<name>hive.querylog.location</name>
<value>/opt/workspaces/data/hive</value>
</property>
<property>
<name>hive.server2.logging.operation.log.location</name>
<value>/opt/workspaces/data/hive</value>
</property>
<property>
<name>hive.querylog.location</name>
<value>/opt/workspaces/frameworks/logs/hive</value>
</property>
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
</configuration>
EOF
cp ./frameworks/hive/conf/hive-log4j.properties.template ./frameworks/hive/conf/hive-log4j.properties
vi ./frameworks/hive/conf/hive-log4j.properties
hive.log.dir=/opt/workspaces/frameworks/logs/hive
下载mysql驱动
wget -P ./frameworks/hive/lib http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.36/mysql-connector-java-5.1.36.jar
| 测试发现5.1.38 需要使用SSL连接,可设置jdbc://…&userSSL=false 禁用 |
10.4. 启动
nohup ./frameworks/hive/bin/hive --service metastore >/dev/null 2>&1 &
10.5. 测试
cat>test_person.txt<<EOF
tom 20
jack 24
nestor 29
EOF
./frameworks/hadoop/bin/hdfs dfs -mkdir /tmp/hivetest/
./frameworks/hadoop/bin/hdfs dfs -put ./test_person.txt /tmp/hivetest/
./frameworks/hive/bin/hive
CREATE EXTERNAL TABLE test_person(name STRING,age INT)ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LOCATION '/tmp/hivetest';
select * from test_person;
以上是“Hive如何安装、配置及基础使用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注天达云行业资讯频道!