在华为云下部署hive环境
在华为云下部署hive环境
Hive需要使用hadoop,在安装hive环境之前,已经在华为云上部署好了hadoop2.8和mysql8.0。
一、下载解压
到hive.apache.org下载hive到/opt目录下,本次使用的版本是hive2.3.3
解压:
tar xzvf apache-hive-2.3.3-bin.tar.gz
mv apache-hive-2.3.3-bin hive-2.3.3
二、配置环境
/etc/profile
export HIVE_HOME=/opt/ hive-2.3.3
PATH 加入$HIVE_HOME/bin
source /etc/profile
三、配置Hive
cd /opt/ hive-2.3.3/conf
cp hive-env.sh.template hive-env.sh
加入HADOOP_HOME变量
HADOOP_HOME=/opt/hadoop-2.8.0
拷贝hive-site配置文件
cp hive-default.xml.template hive-site.xml
HIVE有三种运行模式,下面分别介绍:
3.1 单用户模式
即元数据使用Derby存储的模式
按照官网介绍,使用单用户模式,直接在命令行敲hive就ok了,但在实际使用中会有很多坑。
坑1:输入hive后出现以下错误信息:
Exception in thread "main"java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative pathin absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
需要在hive-site.xml文件中配置以下两个参数的路径解决此问题:
hive.exec.local.scratchdir
hive.downloaded.resources.dir
这两个参数是Hive的缓存目录,如果不配置,使用Hive时将报错。
mkdir /opt/hive-2.3.3/iotmp
配置两个参数路径为:/opt/hive-2.3.3/iotmp
hive
已经可以成功进入提示符,我们来输个简单的cli命令吧
hive>show tables
出现错误提示:
FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
原因是没有初始化derby database,使用如下命令:
[root@cdm3 bin]# schematool -initSchema -dbType derby
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/opt/hive-2.3.3/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4
j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/opt/hadoop-2.8.0/share/hadoop/common/lib/slf4j-log4j12-
1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL: jdbc:derby:;databaseName=metastore_db;create=true
Metastore Connection Driver : org.apache.derby.jdbc.EmbeddedDriver
Metastore connection User: APP
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.derby.sql
Initialization script completed
schemaTool completed
坑2:如果你是第一次运行hive,运行schematool -initSchema -dbType derby命令就可以了,但是如果你已经运行过hive,再试图使用initSchema,会出现类似错误信息
.....
Initialization script hive-schema-2.3.0.derby.sql
Error: FUNCTION 'NUCLEUS_ASCII' already exists. (state=X0Y68,code=30000)
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
Underlying cause: java.io.IOException : Schema script failed, errorcode 2
......
最后在网上找到解决办法:
1、Before you run hive for the first time, run
schematool -initSchema -dbType derby
2、If you already ran hive and then tried to initSchema and it's failing:
mv metastore_db metastore_db.tmp
3、Re run
schematool -initSchema -dbType derby
按上面更改当前目录下metastore_db的文件名,重新执行,在当前目录下可以看到 新建了一个目录,metastore_db
进入hive再次执行,一切ok
hive> show tables;
OK
Time taken: 7.539 seconds
3.2、多用户模式
即元数据使用非Derby,而使用其他的关系型数据库存储(例如MySQL、Oracle等)Hive的元数据:表信息,表属性,分区,列、Owner等等信息,Hive的实际数据是存储在HDFS上的。
在Hive-site.xml 添加4个配置项即可
1. javax.jdo.option.ConnectionURL(jdbc:mysql://centos:3306/hive?createDatabaseIfNotExist=true),指定的是Hive连接数据库的连接字符串;
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://172.16.248.8:3306/hive?createDatabaseIfNotExist=true</value>
<description>
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.
</description>
</property>
2. javax.jdo.option.ConnectionDriver(com.mysql.jdbc.Driver),指定的是MySQL驱动类的入口;
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
3. javax.jdo.option.ConnectionUserName(hive),指定了数据库的用户名;
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
<description>Username to use against metastore database</description>
</property>
4. javax.jdo.option.ConnectionPassword(Hive@8848),指定了数据库的密码;
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>H******</value>
<description>password to use against metastore database</description>
</property>
可能遇到的坑1:
Caused by:org.datanucleus.exceptions.NucleusException: Attempt to invoke the"BONECP" plugin to create a ConnectionPool gave an error : Thespecified datastore driver ("com.mysql.jdbc.Driver") was not found inthe CLASSPATH. Please check your CLASSPATH specification, and the name of thedriver.
此问题是因为缺少数据库对应的驱动包造成的,需要将MySQL数据库的驱动包拷贝到$HIVE_HOME/lib/下
注意要使用跟数据库版本一致的驱动包,
本例中使用的数据库版本是mysql 8.0, 开始使用的是驱动 mysql-connector-java-5.1.32.jar,结果还是出错:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not crea
te connection to database server.
在网上下载相应的驱动包 mysql-connector-java-8.0.12.jar
cp mysql-connector-java-8.0.12.jar $HIVE_HOME/lib/
可能遇到的坑2:
Caused by:org.apache.hadoop.hive.ql.metadata.HiveException:org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:Hivemetastore database is not initialized. Please use schematool (e.g. ./schematool-initSchema -dbType ...) to create the schema. If needed, don't forget toinclude the option to auto-create the underlying database in your JDBCconnection string (e.g. ?createDatabaseIfNotExist=true for mysql))
此问题是因为没有初始化元数据库
schematool -initSchema –dbType mysql
可能遇到的坑3:
MySQL远程访问受限,需要授权
CREATE USER 'ty'@'%' IDENTIFIED BY 'Hellfire87-1'
GRANT ALL PRIVILEGES ON *.* TO 'ty'@'%';
flush privileges;
执行
schematool -initSchema –dbType mysql
还是出错
…
no dbType supplied
…
使用刚建立的hive帐号登录mysql,
mysql -uhive –p
退出后再执行:
schematool -initSchema -dbType mysql --verbose
神奇的成功了。
我们可以登录进mysql看hive的元数据信息:
mysql> use hive
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_hive |
+---------------------------+
| AUX_TABLE |
| BUCKETING_COLS |
| CDS |
| COLUMNS_V2 |
| COMPACTION_QUEUE |
| COMPLETED_COMPACTIONS |
| COMPLETED_TXN_COMPONENTS |
| DATABASE_PARAMS |
| DBS |
| DB_PRIVS |
| DELEGATION_TOKENS |
| FUNCS |
| FUNC_RU |
| GLOBAL_PRIVS |
| HIVE_LOCKS |
| IDXS |
| INDEX_PARAMS |
| KEY_CONSTRAINTS |
| MASTER_KEYS |
| NEXT_COMPACTION_QUEUE_ID |
| NEXT_LOCK_ID |
| NEXT_TXN_ID |
| NOTIFICATION_LOG |
| NOTIFICATION_SEQUENCE |
| NUCLEUS_TABLES |
| PARTITIONS |
| PARTITION_EVENTS |
| PARTITION_KEYS |
| PARTITION_KEY_VALS |
| PARTITION_PARAMS |
| PART_COL_PRIVS |
| PART_COL_STATS |
| PART_PRIVS |
| ROLES |
| ROLE_MAP |
| SDS |
| SD_PARAMS |
| SEQUENCE_TABLE |
| SERDES |
| SERDE_PARAMS |
| SKEWED_COL_NAMES |
| SKEWED_COL_VALUE_LOC_MAP |
| SKEWED_STRING_LIST |
| SKEWED_STRING_LIST_VALUES |
| SKEWED_VALUES |
| SORT_COLS |
| TABLE_PARAMS |
| TAB_COL_STATS |
| TBLS |
| TBL_COL_PRIVS |
| TBL_PRIVS |
| TXNS |
| TXN_COMPONENTS |
| TYPES |
| TYPE_FIELDS |
| VERSION |
| WRITE_SET |
+---------------------------+
57 rows in set (0.00 sec)
3.3 远程模式
启动metastore server
Hive –service metastore &
- 点赞
- 收藏
- 关注作者
评论(0)