安装HIVE

## 下载并解压缩 去主页选择镜像地址:https://www.apache.org/dyn/closer.cgi/hive/ 在镜像地址中选择下载的版本,出于跟其他软件的兼容性考虑,我们这里选用的不是最新版(3.1.3),而是2017-04-07发布的2.3.9,下载地址如下: https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.9/ 下载后上传到主节点root用户的主目录/root,再使用tar命令解压缩 ```shell [root@hadoop-1 software]# tar -xvf apache-hive-2.3.9-bin.tar.gz ``` 使用mv命令将解压后的目录重命名为hive,以去掉版本号等信息 ```shell [root@hadoop-1 software]# mv apache-hive-2.3.9-bin hive ``` 使用mv命令将hive目录移动到安装的目标目录/opt ```shell [root@hadoop-1 software]# mv hive /opt ``` ## 修改环境变量 使用vi命令打开并编辑/etc/profile文件 ```shell [root@hadoop-1 software]# vi /etc/profile ``` 增加如下配置信息 ```shell # HIVE export HIVE_HOME=/opt/hive export PATH=$PATH:$HIVE_HOME/bin ``` 使用source命令使配置文件生效 ```shell [root@hadoop-1 software]# source /etc/profile ``` ## 创建并修改配置文件 进入conf目录 ```shell [root@hadoop-1 software]# cd $HIVE_HOME/conf ``` 拷贝hive-env.sh.template文件为hive-env.sh ```shell [root@hadoop-1 conf]# cp hive-env.sh.template hive-env.sh ``` 打开hive-env.sh文件 ```shell [root@hadoop-1 conf]# vi hive-env.sh ``` 在文件末尾增加如下参数: ```shell HADOOP_HOME=/opt/hadoop export HIVE_CONF_DIR=/opt/hive/conf ``` 使用vi命令新建一个hive-site.xml ```shell [root@hadoop-1 conf]# vi hive-site.xml ``` 在打开的hive-site.xml文件中配置如下信息: ```xml <?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</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> </configuration> ``` ## 安装mysql或mariadb数据库 若未安装mysql或mariadb数据库,请根据“**安装mysql或mariadb数据库**”教程先安装好数据库,然后再执行如下操作。 ## 配置元数据库 从mysql官网中下载mysql驱动,地址如下: > https://downloads.mysql.com/archives/c-j/ 注意,下载5.1.49版本的即可,不要下载更高版本的。具体下载地址如下: > https://cdn.mysql.com/archives/mysql-connector-java-5.1/mysql-connector-java-5.1.49.tar.gz 将下载好的mysql驱动mysql-connector-java-5.1.49.tar.gz上传至主节点 ```shell [root@hadoop-1 software]# ls apache-hive-2.3.9-bin.tar.gz mysql-connector-java-5.1.49.tar.gz ``` 解压mysql-connector-java-5.1.49.tar.gz ```shell [root@hadoop-1 software]# ``` 查看解压得到的文件 ```shell [root@hadoop-1 software]# ls apache-hive-2.3.9-bin.tar.gz mysql-connector-java-5.1.49 mysql-connector-java-5.1.49.tar.gz [root@hadoop-1 software]# ``` 进入解压得到的mysql-connector-java-5.1.49目录,并查看有哪些文件 ```shell [root@hadoop-1 software]# cd mysql-connector-java-5.1.49 [root@hadoop-1 mysql-connector-java-5.1.49]# ls build.xml COPYING mysql-connector-java-5.1.49.jar README.txt CHANGES mysql-connector-java-5.1.49-bin.jar README src [root@hadoop-1 mysql-connector-java-5.1.49]# ``` 从上述解压结果可知,其含有一个mysql驱动文件mysql-connector-java-5.1.49.jar。 重命名mysql驱动文件的名称(去掉版本号,可以不去掉) ```shell [root@hadoop-1 software]# mv mysql-connector-java-5.1.49-bin.jar mysql-connector-java.jar ``` 将MySQL驱动移动到Hive安装目录的lib目录下 ```shell [root@hadoop-1 ~]# mv mysql-connector-java.jar /opt/hive/lib ``` 登录Mariadb shell ```shell [root@hadoop-1 conf]# mysql -u root -p ``` 新建hive数据库,这个hive数据库与hive-site.xml中localhost:3306/hive的hive对应,用来保存hive元数据 ```sql MariaDB [(none)]> create database hive; ``` 配置mysql允许hive接入,将所有数据库的所有表的所有权限赋给hive用户,后面的hive是配置hive-site.xml中配置的连接密码: ```sql MariaDB [(none)]> grant all on *.* to hive@localhost identified by 'hive'; ``` 刷新mysql系统权限关系表 ```sql MariaDB [(none)]> flush privileges; ``` 重要:修改hive元数据库的编码为latin1,若不修改则会导致在hive cli中使用create database(创建数据库)、create table(创建表)、drop talbe(删除表)等命令时出现卡住或报错而无法正确执行的问题。 ```sql MariaDB [(none)]> alter database hive character set latin1; ``` 初始化schema 由于Hive中所有的元信息都需要存储到关系型数据库里面,因此需要初始化数据库表。 ```shell # 进入指定的目录 [root@hadoop-1 conf]# cd $HIVE_HOME/bin # 初始化,如果要使用默认的derby数据库则将命令中的mysql替换成derby即可 [root@hadoop-1 bin]# ./schematool -initSchema -dbType mysql SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/hadoop/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:mysql://localhost:3306/hive?createDatabaseIfNotExist=true Metastore Connection Driver : com.mysql.jdbc.Driver Metastore connection User: hive Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. Starting metastore schema initialization to 2.3.0 Initialization script hive-schema-2.3.0.mysql.sql Initialization script completed schemaTool completed [root@hadoop-1 bin]# ``` 启动hive cli测试 > 注意:由于hive是使用HDFS来存储数据的,而且其语句默认是自动转换成MapReduce程序来执行的,所以在启动hive之前,需要<font color=red>先启动Hadoop集群</font>,否则将启动失败。 启动hadoop集群 ```shell [root@hadoop-1 bin]# start-all.sh This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh Starting namenodes on [hadoop-1] hadoop-1: starting namenode, logging to /opt/hadoop/logs/hadoop-root-namenode-hadoop-1.out hadoop-3: starting datanode, logging to /opt/hadoop/logs/hadoop-root-datanode-hadoop-3.out hadoop-2: starting datanode, logging to /opt/hadoop/logs/hadoop-root-datanode-hadoop-2.out hadoop-1: starting datanode, logging to /opt/hadoop/logs/hadoop-root-datanode-hadoop-1.out Starting secondary namenodes [hadoop-1] hadoop-1: starting secondarynamenode, logging to /opt/hadoop/logs/hadoop-root-secondarynamenode-hadoop-1.out starting yarn daemons starting resourcemanager, logging to /opt/hadoop/logs/yarn-root-resourcemanager-hadoop-1.out hadoop-3: starting nodemanager, logging to /opt/hadoop/logs/yarn-root-nodemanager-hadoop-3.out hadoop-2: starting nodemanager, logging to /opt/hadoop/logs/yarn-root-nodemanager-hadoop-2.out hadoop-1: starting nodemanager, logging to /opt/hadoop/logs/yarn-root-nodemanager-hadoop-1.out [root@hadoop-1 bin]# ``` 创建Hadoop相关目录并赋权(**可选操作**) ```shell # 创建/tmp目录 [root@hadoop-1 conf]# hadoop fs -mkdir /tmp # 创建/user/hive/warehouse目录,其中-p参数用于一次性创建多层目录 [root@hadoop-1 conf]# hadoop fs -mkdir -p /user/hive/warehouse # 为目录赋权 [root@hadoop-1 conf]# hadoop fs -chmod g+w /tmp [root@hadoop-1 conf]# hadoop fs -chmod g+w /user/hive/warehouse ``` 启动Hive cli ```shell [root@hadoop-1 bin]# hive which: no hbase in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/java/bin:/opt/java/jre/bin:/opt/hadoop/bin:/opt/hadoop/sbin:/opt/hive/bin:/root/bin) SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/hadoop/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] Logging initialized using configuration in jar:file:/opt/hive/lib/hive-common-2.3.9.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> ``` 在Hive cli中,执行`show databases;`命令查看Hive中现在有哪些数据库。 ```sql hive> show databases; OK default Time taken: 4.035 seconds, Fetched: 1 row(s) hive> ``` 至此,Hive就算安装完啦! ## 使用beeline 首先启动hiveserver2服务: ```bash nohup ./bin/hiveserver2>> hiveserver2.log 2>&1 & ``` hiveserver2服务启动后,使用beeline客户端访问hiveserver2服务: ```bash cd /opt/module/hive # 进入beeline客户端 bin/beeline # 执行连接hiveserver2操作 beeline> !connect jdbc:hive2://hadoop01:10000/default # 或者 bin/beeline -u jdbc:hive2://hadoop01:10000/default -n root ``` > 注意:hive的默认引擎为MR!!! ## hive 安装 客户端 hive本身提供了thrift协议对外提供服务的功能。 如果某台机器已经配置好了hive,然后运行以下命令打开thrift,提供对外服务(打开后这台机器就为hive服务器) ```bash # 启动hive服务器 nohup $HIVE_HOME/bin/hiveserver2 & nohup $HIVE_HOME/bin/hive --service metastore & # 关闭hive服务器 process="hive" PID=$(ps x | grep $process | grep '/bin/java' | grep -v grep | awk '{print $1}') ps -ef | grep $process | grep '/bin/java' | grep -v grep | awk '{print $2}' | xargs kill -9 ``` 远程机器想要使用hive,可以不做任何元数据和数据存储位置配置(都不需要知道这些配置细节),只需用hive的客户端功能连接hive服务器就行了。 这样配置连接hive服务器: ```xml <?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>hive.metastore.local</name> <value>false</value> </property> <property> <name>hive.metastore.uris</name> <value>thrift://192.168.0.101:9083</value> </property> </configuration> ``` 然后在客户端机器运行hive命令,就能使用hive客户端功能了,和正常使用hive一样。 > 注意: hive命令启动需要本地起了hdfs服务,不需要yarn服务 hive客户端从hive服务端拿到元数据,然后会根据元数据中记录的数据文件地址拿数据,但是元数据中记录的地址可能为如下形式: hdfs://slave5:9000/user/hive/warehouse/... 也就是说hive客户端需要知道slave5对应ip才能访问数据文件,要求hive客户端的/etc/hosts文件里有ip映射。 如果不想配hosts,在服务端hive-site.xml配置文件里指定hive.metastore.warehouse.dir选项时,直接用ip地址(未测试过)。但是不建议这样,因为如果用了ip地址,一旦hdfs集群的NameNode换了ip,hdfs上的数据文件就不能用原来的ip访问到了,想用hive继续访问,需要修改hive的元数据内容。 ## Hive创建数据库表可能遇到的问题 若hive中执行创建数据库或表操作的时候若遇到下面的问题 ```sql hive> create database if not exists hive; FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. com/mysql/jdbc/PreparedStatement$BatchParams hive> ``` 这是由于Hive的元数据库的字符集导致的问题,需要配置元数据库的字符集,进入Mariadb数据库并执行如下语句(注意将元数据库hive修改为自己的数据库名): ```sql mysql> alter database hive character set latin1; ``` 执行完成上述操作之后,再次进入hive即可正常创建数据库或表 # 进行./schematool -initSchema -dbType mysql可能出现的问题 ```shell [root@hadoop01 bin]# ./schematool -initSchema -dbType mysql SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.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] Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V at org.apache.hadoop.conf.Configuration.set(Configuration.java:1357) at org.apache.hadoop.conf.Configuration.set(Configuration.java:1338) at org.apache.hadoop.mapred.JobConf.setJar(JobConf.java:536) at org.apache.hadoop.mapred.JobConf.setJarByClass(JobConf.java:554) at org.apache.hadoop.mapred.JobConf.<init>(JobConf.java:448) at org.apache.hadoop.hive.conf.HiveConf.initialize(HiveConf.java:4051) at org.apache.hadoop.hive.conf.HiveConf.<init>(HiveConf.java:4014) at org.apache.hive.beeline.HiveSchemaTool.<init>(HiveSchemaTool.java:82) at org.apache.hive.beeline.HiveSchemaTool.main(HiveSchemaTool.java:1117) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.util.RunJar.run(RunJar.java:323) at org.apache.hadoop.util.RunJar.main(RunJar.java:236) ``` 原因:系统找不到相关jar包,或者同一类型的 jar 包有不同版本存在,系统无法决定使用哪一个。 而在我们Hadoop的文件里就有一个(/……/hadoop/share/hadoop/common/lib/guava-27.0-jre.jar),hive的lib下又有一个(guava-14.0.1.jar),因此这是因为有不同版本的包存在造成的。 解决办法: 将hadoop的包复制过来即可: ```shell cp /opt/hadoop/share/hadoop/common/lib/guava-27.0-jre.jar /opt/hive/lib # 安装目录记得换成自己的 ``` 此时再执行./schematool -initSchema -dbType mysql就没有问题啦: ```shell [root@hadoop01 bin]# ./schematool -initSchema -dbType mysql SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.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:mysql://localhost:3306/hive?createDatabaseIfNotExist=true Metastore Connection Driver : com.mysql.jdbc.Driver Metastore connection User: hive Starting metastore schema initialization to 2.3.0 Initialization script hive-schema-2.3.0.mysql.sql Initialization script completed schemaTool completed ``` ### 直接关机您可能遇到hive不能使用,例如类似于如下错误: ```shell Exception in thread "main" java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.server.namenode.SafeModeException): Cannot create directory /tmp/hive/atguigu/ac2b1292-d550-4be4-9178-7694ed34350c. Name node is in safe mode. The reported blocks 71 needs additional 2 blocks to reach the threshold 0.9990 of total blocks 73. The number of live datanodes 3 has reached the minimum number 0. Safe mode will be turned off automatically once the thresholds have been reached. at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkNameNodeSafeMode(FSNamesystem.java:1327) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.mkdirs(FSNamesystem.java:3893) at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.mkdirs(NameNodeRpcServer.java:983) at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.mkdirs(ClientNamenodeProtocolServerSideTranslatorPB.java:622) at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java) at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:616) at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:969) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2049) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2045) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:422) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657) at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2043) at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:522) at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:677) at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:621) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.util.RunJar.run(RunJar.java:221) at org.apache.hadoop.util.RunJar.main(RunJar.java:136) Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.server.namenode.SafeModeException): Cannot create directory /tmp/hive/atguigu/ac2b1292-d550-4be4-9178-7694ed34350c. Name node is in safe mode. The reported blocks 71 needs additional 2 blocks to reach the threshold 0.9990 of total blocks 73. The number of live datanodes 3 has reached the minimum number 0. Safe mode will be turned off automatically once the thresholds have been reached. at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkNameNodeSafeMode(FSNamesystem.java:1327) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.mkdirs(FSNamesystem.java:3893) at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.mkdirs(NameNodeRpcServer.java:983) at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.mkdirs(ClientNamenodeProtocolServerSideTranslatorPB.java:622) at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java) at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:616) at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:969) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2049) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2045) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:422) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657) at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2043) at org.apache.hadoop.ipc.Client.call(Client.java:1475) at org.apache.hadoop.ipc.Client.call(Client.java:1412) at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:229) at com.sun.proxy.$Proxy15.mkdirs(Unknown Source) at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.mkdirs(ClientNamenodeProtocolTranslatorPB.java:558) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:191) at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102) at com.sun.proxy.$Proxy16.mkdirs(Unknown Source) at org.apache.hadoop.hdfs.DFSClient.primitiveMkdir(DFSClient.java:3000) at org.apache.hadoop.hdfs.DFSClient.mkdirs(DFSClient.java:2970) at org.apache.hadoop.hdfs.DistributedFileSystem$21.doCall(DistributedFileSystem.java:1047) at org.apache.hadoop.hdfs.DistributedFileSystem$21.doCall(DistributedFileSystem.java:1043) at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81) at org.apache.hadoop.hdfs.DistributedFileSystem.mkdirsInternal(DistributedFileSystem.java:1043) at org.apache.hadoop.hdfs.DistributedFileSystem.mkdirs(DistributedFileSystem.java:1036) at org.apache.hadoop.hive.ql.session.SessionState.createPath(SessionState.java:639) at org.apache.hadoop.hive.ql.session.SessionState.createSessionDirs(SessionState.java:574) at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:508) ... 8 more ``` 原因可能是直接关机导致了hadoop进入了安全模式,所以这个hive进不去 解决方式: ```shell [root@hadoop-01 root]$ hadoop dfsadmin -safemode leave ``` 然后再次执行 ```shell [root@hadoop-01 root]# hive Logging initialized using configuration in jar:file:/opt/hive/lib/hive-common-2.3.9.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> ``` 另外,这种情况的"并发症"是当你用hive启动hiveserver2连JDBC时也会报错 错误提示:Could not open client transport with JDBC Uri Error: Could not open client transport with JDBC Uri: jdbc:hive2://hadoop-01:10000: java.net.ConnectException: 拒绝连接 (Connection refused) (state=08S01,code=0) 其实这也是因为上面的原因啦,当上面的情况排除掉后,这个问题也解决啦。 以下是hiveserver2连接jdbc的过程: ```shell [root@hadoop-01 hive]$ bin/hiveserver2 [root@hadoop-01 hive]$ bin/beeline Beeline version 1.2.1 by Apache Hive beeline> !connect jdbc:hive2://hadoop-01:10000 Connecting to jdbc:hive2://hadoop-01:10000 Enter username for jdbc:hive2://hadoop-01:10000: hive Enter password for jdbc:hive2://hadoop-01:10000: ********* Connected to: Apache Hive (version 1.2.1) Driver: Hive JDBC (version 1.2.1) Transaction isolation: TRANSACTION_REPEATABLE_READ 0: jdbc:hive2://hadoop-01:10000> ```