0.前置
安装mysql-server
sudo apt-get install mysql-server
输入Y,中途会要求输入数据库账户密码等,如果没有要求设置数据库密码,请执行以下命令
service mysql start
mysql -u root -p
登录mysql后,修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
刷新权限
FLUSH PRIVILEGES;
重新登陆
exit;
下载wget命令sudo apt-get install wget
sudo apt-get install wget
cd到你想要安装hive的文件夹,例如我这里是cd /usr/local
cd /usr/local
下载安装hive3.1.3
sudo wget https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-3.1.3/apache-hive-3.1.3-bin.tar.gz
##### 下载完成后看到如下界面解压hivesudo tar -zxvf apache-hive-3.1.3-bin.tar.gz
##### 将文件夹名改为hivesudo mv apache-hive-3.1.3-bin hive
##### 修改文件权限(注意这里的hadoop是当前用户名,格式应为用户名:用户名)sudo chown -R hadoop:hadoop hive
配置环境变量
vim ~/.bashrc
##### 在该文件最前面一行添加如下内容:export HIVE_HOME=/usr/local/hive #hive文件夹的路径export PATH=$PATH:$HIVE_HOME/bin export HADOOP_HOME=/usr/local/hadoop #hadoop文件夹的路径
##### 运行命令使其生效:source ~/.bashrc
修改/usr/local/hive/conf下的hive-site.xml,将hive-default.xml.template重命名为hive-default.xml
cd /usr/local/hive/conf #进入/hive/conf文件夹mv hive-default.xml.template hive-default.xml
##### 使用vim编辑器新建一个配置文件hive-site.xmlvim hive-site.xml
在hive-site.xml中添加如下配置信息:##### hive三种配置方式区别Hive中metastore(元数据存储)的三种方式:a)内嵌Derby方式b)Local方式c)Remote方式###### *1.本地模式(*derby)这种方式是最简单的存储方式,只需要在hive-site.xml做如下配置便可<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:derby:;databaseName=metastore_db;create=true</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>org.apache.derby.jdbc.EmbeddedDriver</value> </property> <property> <name>hive.metastore.local</name> <value>true</value> </property> <property> <name>hive.metastore.warehouse.dir</name> <value>/usr/local/hive/warehouse</value> </property> </configuration>
注:使用derby存储方式时,运行hive会在当前目录生成一个derby文件和一个metastore_db目录。这种存储方式的弊端是在同一个目录下同时只能有一个hive客户端能使用数据库,否则会提示如下错误[html] view plaincopyprint?hive> show tables; FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Failed to start database 'metastore_db', see the next exception for details. NestedThrowables: java.sql.SQLException: Failed to start database 'metastore_db', see the next exception for details. FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask hive> show tables;FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Failed to start database 'metastore_db', see the next exception for details.NestedThrowables:java.sql.SQLException: Failed to start database 'metastore_db', see the next exception for details.FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask###### 2.单用户模式(mysql)*这种存储方式需要在本地运行一个mysql服务器,并作如下配置(下面两种使用mysql的方式,需要将mysql的jar包拷贝到$HIVE_HOME/lib目录下(前面已安装mysql)*)。<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>hive.metastore.warehouse.dir</name> <value>/usr/local/hive_remote/warehouse</value> </property> <property> <name>hive.metastore.local</name> <value>true</value> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost/hive_remote?createDatabaseIfNotExist=true</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>password</value> </property> </configuration>
[ERROR] Terminal initialization failed; falling back to unsupportedjava.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expectedat jline.TerminalFactory.create(TerminalFactory.java:101)错误的原因: Hadoop jline版本和hive的jline不一致**###### 3.多用户模式###### 1.Remote一体**这种存储方式需要在远端服务器运行一个mysql服务器,并且需要在Hive服务器启动meta服务。这里用mysql的测试服务器,ip位192.168.1.214,新建hive_remote数据库,字符集位latine1<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>hive.metastore.warehouse.dir</name> <value>/usr/local/hive/warehouse</value> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://192.168.57.6:3306/hive?createDatabaseIfNotExist=true</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>password</value> </property> <property> <name>hive.metastore.local</name> <value>false</value> </property> <property> <name>hive.metastore.uris</name> <value>thrift://192.168.1.188:9083</value> </property> </configuration>
注:这里把hive的服务端和客户端都放在同一台服务器上了。服务端和客户端可以拆开,###### 2.Remote分开将hive-site.xml配置文件拆为如下两部分** 1)、服务端配置文件**<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>hive.metastore.warehouse.dir</name> <value>/usr/local/hive/warehouse</value> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://192.168.57.6:3306/hive?createDatabaseIfNotExist=true</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>root</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>123456</value> </property> </configuration>
** 2)、客户端配置文件**<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>hive.metastore.warehouse.dir</name> <value>/usr/local/hive/warehouse</value> </property> <property> <name>hive.metastore.local</name> <value>false</value> </property> <property> <name>hive.metastore.uris</name> <value>thrift://192.168.57.5:9083</value> </property> </configuration>
客户端启动的时候要注意:[ERROR] Terminal initialization failed; falling back to unsupportedjava.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expectedat jline.TerminalFactory.create(TerminalFactory.java:101)错误的原因: Hadoop jline版本和hive的jline不一致下载mysql-connector-java-5.1.40到/usr/local
cd /usr/localsudo wget https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-5.1.40.tar.gz
##### 解压sudo tar -zxvf mysql-connector-java-5.1.40.tar.gz
##### 将mysql-connector-java-5.1.40-bin.jar拷贝到/usr/local/hive/lib目录下cp /usr/local/mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar /usr/local/hive/lib
启动并登陆MySQL Shell
service mysql startmysql -u root -p
新建Hive数据库
create database hive;
配置MySQL允许Hive接入(mysql用户hive,密码hive)
grant all on *.* to hive@localhost identified by 'hive';flush privileges;exit;
升级元数据
cd /usr/local/hive./bin/schematool -initSchema -dbType mysql
可能会出现错误 Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V原因是hive/lib中的guava包版本与/hadoop/share/hadoop/common/lib中的guava包版本不匹配,将hadoop中的guava包替换到hive中,执行以下命令cp /usr/local/hadoop/share/hadoop/common/lib/guava-27.0-jre.jar /usr/local/hive/librm -rf /usr/local/hive/lib/guava-19.0.jar
重新执行命令升级元数据cd /usr/local/hive./bin/schematool -initSchema -dbType mysql
输出一段文字的最后出现如下字样即升级完成启动Hive,注意启动Hive之前需要先启动集群
hive
如果有过多警告信息,如图可在hive/conf下新建log4j.properties日志的配置文件cd /usr/local/hive/confvim /usr/local/hive/conf/log4j.properties
添加以下内容log4j.rootLogger=ERROR, CA log4j.appender.CA=org.apache.log4j.ConsoleAppenderlog4j.appender.CA.layout=org.apache.log4j.PatternLayoutlog4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
重启hive即可
本文转载自: https://blog.csdn.net/Jeramy_/article/details/138326758
版权归原作者 Jeramy_ 所有, 如有侵权,请联系我们删除。
版权归原作者 Jeramy_ 所有, 如有侵权,请联系我们删除。