目录
环境
一、安装Hive3.3.3
2. 配置环境变量
3. 修改/usr/local/hive/conf下的hive-site.xml
4.初始化hive数据库
5.启动hive,成功!!!
6.为hive建立hdfs使用目录
环境环境:workstation11 + centos 7 + hadoop-2.7.7 + mysql 5.7.19 + hive 2.3.3
首先安装mysql,步骤看这里centos 下安装mysql - ETl数据挖掘 - 大数据学习网
其次安装hadoop-2.7.7,详情参考:hadoop-2.7.7 完全安装配置这里
接着安装HIVE-2.3.3
备注:在安装Hive2.3.3之前,请首先安装Hadoop2.7.7。
一、安装Hive3.3.3首先需要下载Hive安装包文件, Hive官网下载地址
也可以直接链接:网盘下载 提取码:2c0h。进入百度网盘后,进入“软件”目录,找到apache-hive-2.3.3-bin.tar文件,下载到本地。
tar -zxvf ./apache-hive-3.1.2-bin.tar.gz -C /usr/local # 解压到/usr/local中
cd /usr/local/
mv apache-hive-3.3.3-bin hive # 将文件夹名改为hive
chown -R root:root hive # 修改文件权限
2. 配置环境变量
为了方便使用,我们把hive命令加入到环境变量中去,
请使用vim编辑器打开.profile文件,命令如下:
vi /etc/profile
在该文件最下面添加如下内容:
#HIVE
export HIVE_HOME=/usr/local/hive
export PATH=$PATH:$HIVE_HOME/bin
保存退出后,运行如下命令使配置立即生效:
source /etc/profile
检测 Hive 环境变量是否设置成功,使用如下命令查看 Hive 版本:
hive --version
执行此命令后,若是出现 Hive 版本信息说明配置成功:3. 修改
/usr/local/hive/conf
下的hive-site.xml
执行如下命令:
cd /usr/local/hive/conf
cp hive-default.xml.template hive-default.xml
上面命令是将hive-default.xml.template重命名为hive-default.xml;然后,使用vim编辑器新建一个配置文件hive-site.xml,命令如下:
cd /usr/local/hive/conf
vi hive-site.xml
在hive-site.xml中添加如下配置信息:
javax.jdo.option.ConnectionURL
jdbc:mysql://192.168.106.132:3306/hive?useSSL=false
JDBC connect string for a JDBC metastore
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
Driver class name for a JDBC metastore
javax.jdo.option.ConnectionUserName
root
username to use against metastore database
javax.jdo.option.ConnectionPassword
123456
password to use against metastore database
然后,按键盘上的“ESC”键退出vim编辑状态,再输入:wq,保存并退出vim编辑器。
4.初始化hive数据库先复制mysql的驱动程序到hive/lib下面(我这里是上传mysql-connector-java-5.1.46-bin.jar到/usr/local/hive/lib)然后
[root@hadoop conf]# mysql -uroot -proot #登录
mysqlmysql> create user 'hive' identified by 'hive'; #这句话是Oracle用法,其实不必执行mysql> grant all privileges on *.* to hive@"%" identified by "hive" with grant option;
#创建hive用户同时设置远程连接(因为hive-site.xml中配置的是hive用户)
Query OK, 0 rows affected (0.04 sec)
mysql> flush privileges; #刷新权限
Query OK, 0 rows affected (0.09 sec)
mysql> exit #退出
Bye
[root@hadoop conf]# cd ..
[root@hadoop hive]# bin/schematool -initSchema -dbType mysql #初始化mysql
Metastore connection URL: jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true&characterEncoding=UTF-8&useSSL=false
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
5.启动hive,成功!!!
6.为hive建立hdfs使用目录
[root@node02 hive]# hdfs dfs -mkdir /usr
[root@node02 hive]# hdfs dfs -mkdir /usr/hive/
[root@node02 hive]# hdfs dfs -mkdir -p /usr/hive/datacase
[root@node02 hive]# hdfs dfs -chmod g+w /usr/hive/datacase
[root@node02 hive]# hdfs dfs -mkdir /tmp
[root@node02 hive]# hdfs dfs -chmod g+w /tmp
[root@node02 hive]# hdfs dfs -ls -R / #查看
drwxrwxr-x - root supergroup 0 2018-07-27 14:49 /tmp
drwxr-xr-x - root supergroup 0 2018-07-27 14:44 /usr
drwxr-xr-x - root supergroup 0 2018-07-27 14:45 /usr/hive
drwxrwxr-x - root supergroup 0 2018-07-27 14:45 /usr/hive/datacase
7. 遇到错误
1.hive数据库初始化报错
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.mysql.sql
Error: Syntax error: Encountered "" at line 1, column 64. (state=42X01,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
Use --verbose for detailed stacktrace.
*** schemaTool failed ***
原因:先确定hive-site.xml文件名是否正确,如果不对则必须改为hive-site.xml否则不生效。然后查看其中的mysql数据连接信息是否正确修改。我这里犯了个错误就是直接从网上拷贝后粘贴到文件的上方了,后来检查文件时发现文件中其实是有这四个标签的并且都有默认值,估计执行时后面标签的内容把我添加到前面的标签内容给覆盖掉了所以才没有生效。
解决方法:到文件中分别找到这4个标签并一一修改其中的内容,不要直接复制粘贴。这个文件比较大,可以下载到本地用NotPad++打开修改后再重新上传覆盖。
2.启动hive报错[root@hadoop local]# hive
Logging initialized using configuration in file:/usr/local/hive/conf/hive-log4j2.properties Async: true
Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
at org.apache.hadoop.fs.Path.initialize(Path.java:205)
at org.apache.hadoop.fs.Path.(Path.java:171)
at org.apache.hadoop.hive.ql.session.SessionState.createSessionDirs(SessionState.java:659)
at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:582)
at org.apache.hadoop.hive.ql.session.SessionState.beginStart(SessionState.java:549)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:750)
at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:686)
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:483)
at org.apache.hadoop.util.RunJar.run(RunJar.java:226)
at org.apache.hadoop.util.RunJar.main(RunJar.java:141)
Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
at java.net.URI.checkPath(URI.java:1823)
at java.net.URI.(URI.java:745)
at org.apache.hadoop.fs.Path.initialize(Path.java:202)
... 12 more
解决方法:建立相应目录并在hive-site.xml文件中修改
[root@hadoop conf]# mkdir -p /tmp/hive/local /tmp/hive/resources /tmp/hive/querylog /tmp/hive/operation_logs #创建目录
[root@hadoop conf]# vi hive-site.xml #修改配置文件,注意是修改不是添加!!!
hive.exec.scratchdir
/tmp/hive
HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scratchdir}/ is created, with ${hive.scratch.dir.permission}.
hive.exec.local.scratchdir
/tmp/hive/local
Local scratch space for Hive jobs
hive.downloaded.resources.dir
/tmp/hive/resources
Temporary local directory for added resources in the remote file system.
hive.querylog.location
/tmp/hive/querylog
Location of Hive run time structured log file
hive.server2.logging.operation.log.location
/tmp/hive/operation_logs
Top level directory where operation logs are stored if logging functionality is enabled
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)