作者:手机用户2502900723 | 来源:互联网 | 2023-08-13 09:30
注:我的Hadoop版本是2.7.3Hadoop安装参考我的博客https:blog.csdn.nettszxlzcarticledetails61635411下载hive,解压h
注:我的Hadoop版本是2.7.3 Hadoop安装参考我的博客 https://blog.csdn.net/tszxlzc/article/details/61635411
- 下载hive,解压hive文件
[[email protected] local]# wget http://mirror.bit.edu.cn/apache/hive/hive-2.3.4/apache-hive-2.3.4-bin.tar.gz
[[email protected] local]# tar -xzvf apache-hive-2.3.4-bin.tar.gz
- 将hive加到环境变量
[[email protected] apache-hive-2.3.4-bin]# export HIVE_HOME=/usr/local/apache-hive-2.3.4-bin
[[email protected] apache-hive-2.3.4-bin]# export PATH=$HIVE_HOME/bin:$PATH
- hadoop分布式或伪分布式,hive数据会存在hdfs上,默认放在目录下 /user/hive/warehouse,所以先创建目录
$ $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
- 在/usr/local/apache-hive-2.3.4-bin/conf 目录下创建hive-site.xml文件
<configuration>
<property>
<name>datanucleus.schema.autoCreateAllname>
<value>truevalue>
property>
<property>
<name>javax.jdo.option.ConnectionURLname>
<value>jdbc:mysql://192.168.152.128:3306/hive_db?createDatabaseIfNotExist=truevalue>
<description>JDBC connect string for a JDBC metastoredescription>
property>
<property>
<name>javax.jdo.option.ConnectionDriverNamename>
<value>com.mysql.jdbc.Drivervalue>
<description>Driver class name for a JDBC metastoredescription>
property>
<property>
<name>javax.jdo.option.ConnectionUserNamename>
<value>rootvalue>
<description>username to use against metastore databasedescription>
property>
<property>
<name>javax.jdo.option.ConnectionPasswordname>
<value>123456value>
<description>password to use against metastore databasedescription>
property>
configuration>
- 在/usr/local/apache-hive-2.3.4-bin/lib目录下下载mysql驱动
[[email protected] lib]# wget http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.37/mysql-connector-java-5.1.37.jar
- 初始化hive元数据到mysql
[[email protected] conf]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/apache-hive-2.3.4-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL: jdbc:mysql://192.168.152.128:3306/hive_db?createDatabaseIfNotExist=true
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: root
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.mysql.sql
Initialization script completed
schemaTool completed
- 启动hive,并创建一个表验证
[[email protected] conf]
which: no hbase in (/usr/local/apache-hive-2.3.4-bin/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.8.0_111/bin:/usr/local/hadoop-2.7.3/bin:/usr/local/hadoop-2.7.3/sbin:/root/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/apache-hive-2.3.4-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Logging initialized using configuration in jar:file:/usr/local/apache-hive-2.3.4-bin/lib/hive-common-2.3.4.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive> create table x (a int);
OK
Time taken: 7.151 seconds
hive>
至此hive创建表成功,还可以到hdfs查看到表已放到仓库目录下
问题记录:
- 由于我的hive和mysql在两个不同的虚拟机上,hive机器ping不同mysql机器,而mysql机器可以ping通hive机器,发现是hive机器网络选择了桥接模式,而mysql机器网络选择了NAT模式。将hive机器的网络改为NAT模式,就可以初始化hive元数据了
- 另外要查看hive的日志到 /tmp/root目录下查看,因为我是用root用户操作的