Centos下伪分布式安装Hive以及安装可能出现的问题

安装要求:Hive 1.2.1   MySQL 5.7    JDK 1.8

1.下载解压
cd /mk/soft  
tar -xvzf apache-hive-1.2.1-bin.tar.gz -C /appl/  
cd /appl  
mv apache-hive-1.2.1-bin hive-1.2.1  

2. 配置环境变量
vi /etc/profile  
export HIVE_HOME=/appl/hive-1.2.1  
export PATH=$PATH:$HIVE_HOME/bin  
export CLASSPATH=.:$HIVE_HOME/lib  
source /etc/profile  

3. 配置Hive

cd /appl/hive-1.2.1/conf  


cp hive-default.xml.template hive-default.xml (不改变)  
cp hive-default.xml.template hive-site.xml (覆盖hive-default.xml配置项)  
cp hive-env.sh.template hive-env.sh  
cp hive-log4j.properties.template hive-log4j.properties  


vi hive-env.sh  
export HADOOP_HOME=${HADOOP_HOME}  
export HIVE_CONF_DIR=${HIVE_HOME}/conf  

vi hive-log4j.properties  
#log4j.appender.EventCounter=org.apache.hadoop.hive.shims.HiveEventCounter  
#log4j.appender.EventCounter=org.apache.hadoop.metrics.jvm.EventCounter  
log4j.appender.EventCounter=org.apache.hadoop.log.metrics.EventCounter  

vi hive-site.xml
-----------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>  
  <!-- Hive Execution Parameters -->  
  <property>  
<name>javax.jdo.option.ConnectionURL</name>  
<value>jdbc:mysql://192.168.1.128:3306/metastore_hive?useUnicode=true&characterEncoding=UTF-8&useSSL=false</value>  
<description>JDBC connect string for a JDBC metastore</description>  
</property>   
  
<property>  
<name>javax.jdo.option.ConnectionDriverName</name>  
<value>com.mysql.jdbc.Driver</value>  
<description>Driver class name for a JDBC metastore</description>  
</property>  
  
<property>  
<name>javax.jdo.option.ConnectionUserName</name>  
<value>hive</value>  
<description>username to use against metastore database</description>  
</property>  
  
<property>  
<name>javax.jdo.option.ConnectionPassword</name>  
<value>hive</value>  
<description>password to use against metastore database</description>  
</property>  
  
<property>  
<name>hive.metastore.warehouse.dir</name>  
<value>hdfs://hong/hive/warehouse</value>  
<description>location of default database for the warehouse (hdfs  path)</description>  
</property>  
  
<property>   
<name>hive.metastore.uris</name>   
<value>thrift://hong:9083</value>  
</property>  
  
<property>  
<name>hive.server2.authentication</name>  
<value>NONE</value>  
</property>  
</configuration>

4HDFS文件系统下创建/hive/warehouse/hive/tmp
hadoop fs -mkdir /hive  
hadoop fs -mkdir /hive/warehouse  
hadoop fs -chmod g+w /hive/warehouse  
hadoop fs -mkdir /hive/tmp  
hadoop fs -chmod g+w /hive/tmp  

5进入MySQL
mysql -u root -p root


以下命令都是在mysql下进行执行:
create database metastore_hive;  
grant all on metastore_hive.* to hive@'%' identified by 'hive';  
grant all on metastore_hive.* to hive@localhost identified by 'hive';  
ALTER DATABASE metastore_hive CHARACTER SET latin1;  
show databases;  
exit  
mysql -u hive -p
密码:hive
use metastore_hive  
exit  

mysql-connector-java-5.1.44-bin.jar到Hive安装目录下的lib里。

6.hadoop 配置
vi /usr/local/hadoop/etc/hadoop/hdfs-site.xml
<property>  
  <name>dfs.permissions</name>  
  <value>false</value>  
</property>  

vi /usr/local/hadoop/etc/hadoop/hadoop-env.sh
export HADOOP_CLASSPATH=$CLASSPATH:$HADOOP_CLASSPATH  

7. 启动服务
1)、启动metastore服务

cd /usr/local/hive/bin
hive --service metastore & (默认端口:9083,可-p 9083控制;测试:hive --service metastore)

2)、启动hiveserver2服务
hive --service hiveserver2 &  (测试:hive --service hiveserver2)
这两项服务都必须要开启运行:
然后在执行hive进入hive shell

3)、访问hiveserver2的两种方式
(1) JDBC
Class.forName("org.apache.hive.jdbc.HiveDriver");
DriverManager.getConnection("jdbc:hive2://IP:10000/default","","");
(2) beeline
beeline -u jdbc:hive2://localhost:10000/ -n hive -p hive

beeline
!connect jdbc:hive2://localhost:10000  
show tables;  
create table test1 (id int, name string) row format delimited fields terminated by ',' stored as textfile;  
load data local inpath '/mk/test/test1.txt' into table test1;  
select * from test1;  
!quit  

查看hive文件
hadoop fs -ls /hive/warehouse/test1
停止:因为不是通过服务启动,只能ps -ef|grep hive,再kill <pid>

8.安装可能遇见的问题:
---------------
[Fatal Error] hive-site.xml:1:1: Content is not allowed in prolog.
18/06/13 16:20:24 FATAL conf.Configuration: error parsing conf file:/home/hadoop/sw/hive-1.2.1/conf/hive-site.xml
org.xml.sax.SAXParseException; systemId: file:/home/hadoop/sw/hive-1.2.1/conf/hive-site.xml; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
出现这种问题的原因是因为hive-site.xml  里没有配置好,再仔细检查下。

----------------
javax.jdo.JDOFatalDataStoreException: Unable to open a test connection to the given database. JDBC url = jdbc:mysql://192.168.1.128:3306/metastore_hive?useUnicode=true&characterEncoding=UTF-8&useSSL=false, username = hive. Terminating connection pool (set lazyInit to true if you expect to start your database after your app). Original Exception: ------
java.sql.SQLException: Access denied for user 'hive'@'hong' (using password: YES)
出现这种问题的原因是对hive用户没有给他访问主机hong的权限,
解决办法:在mysql下 执行

grant all on metastore_hive.* to hive@hong identified by 'hive';

----------------
Exception in thread "main" org.apache.thrift.transport.TTransportException: Could not create ServerSocket on address 0.0.0.0/0.0.0.0:9083.
出现这种问题是因为之前运行的metastore 或者hiveserver2进程(Runjar)失败了,但是没有kill掉,kill掉之前的进程再次启动服务试试。





  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值