当前位置:   article > 正文

Hive安装详细步骤

hive安装

一、下载hive

下载hive——地址:http://mirror.bit.edu.cn/apache/hive/

二、安装mysql

执行以下几个命令安装8.0版本mysql

  1. //1、下载MySQLyum源(8.0版本的)
  2. wget http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
  3. (5.7版本的)
  4. wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
  5. //2、添加MySQLyum源
  6. sudo yum localinstall mysql80-community-release-el7-3.noarch.rpm
  7. (5.7版本)
  8. sudo yum localinstall mysql57-community-release-el7-10.noarch.rpm
  9. //3、MySQL的GPG升级了,需要更新,如果是新安装的MySQL,执行以下脚本即可:
  10. rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
  11. //4、安装MySQL客户端
  12. yum -y install mysql-community-server

 开启mysql服务

  1. # 1、开启Mysql服务
  2. sudo service mysqld start
  3. # 2、查看mysql是否开启
  4. sudo servicee mysqld status
  5. # 重启mysql服务
  6. sudo service mysqld restart
  7. # 3、查看初始密码
  8. sudo grep 'temporary password' /var/log/mysqld.log
  9. # 4、进入mysql客户端,输入查询到的初始化密码
  10. mysql -uroot -p

mysql密码设置

  1. # 1、首先要修改密码,高版本的mysql默认必须修改密码才能正常使用,所以如果不修改密码不能做任何事
  2. alter user 'root'@'localhost' identified by '新密码'
  3. 注意:因为我们还没有改密码的复杂度,所以这里的密码必须足够复杂,后面会改简单的
  4. # 2、查看mysql初始化密码的策略
  5. SHOW VARIABLES LIKE 'validate_password%';
  6. mysql> SHOW VARIABLES LIKE 'validate_password%';
  7. +--------------------------------------+-------+
  8. | Variable_name | Value |
  9. +--------------------------------------+-------+
  10. | validate_password.check_user_name | ON |
  11. | validate_password.dictionary_file | |
  12. | validate_password.length | 6 |
  13. | validate_password.mixed_case_count | 1 |
  14. | validate_password.number_count | 1 |
  15. | validate_password.policy | LOW |
  16. | validate_password.special_char_count | 1 |
  17. +--------------------------------------+-------+
  18. 7 rows in set (0.00 sec)
  19. # 3、修改密码验证强度(重启后就失效)
  20. set global validate_password.policy=LOW;
  21. # 4、修改密码允许最短长度,不能小于4
  22. set global validate_password.length=6;
  23. # 5、修改简单密码
  24. alter user 'root'@'localhost' identified by '000000';

 设置mysql远程登陆

8.0版本以前

  1. # 1、修改权限
  2. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
  3. # %表示所有远程机器
  4. # root表示远程登陆后使用root用户
  5. # *.*表示所有表
  6. # 刷新权限
  7. flush privileges;

8.0版本的因为有新的安全要求,不能自己给自己授权,所以要新建一个用户,通过那个用户来授权

  1. # 1、查看mysql用户
  2. use mysql;
  3. select user, host from user;
  4. mysql> select user, host from user;
  5. +------------------+-----------+
  6. | user | host |
  7. +------------------+-----------+
  8. | mysql.infoschema | localhost |
  9. | mysql.session | localhost |
  10. | mysql.sys | localhost |
  11. | root | localhost |
  12. +------------------+-----------+
  13. 4 rows in set (0.00 sec)
  14. # 2、新建用户
  15. create user 'hadoop100'@'%' identified by '000000';
  16. # hadoop100表示用户名
  17. # %表示任意ip
  18. # 000000表示该用户的密码,记得如果重启需要从新修改密码验证策略
  19. # 3、为用户授权
  20. grant all on *.* to 'hadoop100'@'%';
  21. # 4、刷新权限
  22. flush privileges;

mysql开机自启动(在linux中执行)

systemctl enable mysqld

三、解压与配置

①进入到存放hive的目录下,输入以下命令解压到指定目录下

tar -zxvf apache-hive-3.1.2-bin.tar.gz -C /opt/modules/

②配置文件重命名

将hive-defaultxml.template重命名为hive-site.xml

将hive-env.sh.template重命名为hive-env.sh

将hive-log4j.properties.template重命名为hive-log4j.properties

③修改配置

1、修改hive-env.sh配置

添加JAVA_HOME和HADOOP_HOME,exportHIVE_CONF_DIR(即hive的conf目录地址)

2、修改hive-site.xml配置

  1. <!--判断mysql下是否有这个数据库,没有的话创建-->
  2. <property>
  3. <name>javax.jdo.option.ConnectionURL</name>
  4. <value>jdbc:mysql://hadoop100:3306/metastore?createDatabaseIfNotExist=true</value>
  5. <description>JDBC connect string for a JDBC metastore</description>
  6. </property>
  7. <!--使用mysql driver驱动,默认是hive内置数据库derby驱动-->
  8. <property>
  9. <name>javax.jdo.option.ConnectionDriverName</name>
  10. <value>com.mysql.jdbc.Driver</value>
  11. <description>Driver class name for a JDBC metastore</description>
  12. </property>
  13. <!--mysql账号-->
  14. <property>
  15. <name>javax.jdo.option.ConnectionUserName</name>
  16. <value>root</value>
  17. <description>username to use against metastore database</description>
  18. </property>
  19. <!--mysql密码-->
  20. <property>
  21. <name>javax.jdo.option.ConnectionPassword</name>
  22. <value>000000</value>
  23. <description>password to use against metastore database</description>
  24. </property>
  25. <!--显示查询出的数据的字段名称-->
  26. <property>
  27. <name>hive.cli.print.header</name>
  28. <value>true</value>
  29. <description>Whether to print the names of the columns in query output.</description>
  30. </property>
  31. <!--在hive中显示当前所在数据库名称-->
  32. <property>
  33. <name>hive.cli.print.current.db</name>
  34. <value>true</value>
  35. <description>Whether to include the current database in the Hive prompt.</description>
  36. </property>
  37. <!--使得查询单列数据不会执行mapreduce-->
  38. <property>
  39. <name>hive.fetch.task.conversion</name>
  40. <value>more</value>
  41. <description>
  42. Some select queries can be converted to single FETCH task minimizing latency.
  43. Currently the query should be single sourced not having any subquery and should not have
  44. any aggregations or distincts (which incurs RS), lateral views and joins.
  45. 1. minimal : SELECT STAR, FILTER on partition columns, LIMIT only
  46. 2. more : SELECT, FILTER, LIMIT only (TABLESAMPLE, virtual columns)
  47. </description>
  48. </property>

3、修改hive-log4j.properties配置

设置log路径用以存放hive的log日志文件
 hive.log.dir=/opt/modules/hive-3.1.2/logs

4、拷贝数据库驱动包到hive的lib目录中

cp mysql-connector-java-5.1.27/mysql-connector-java-5.1.27-bin.jar /opt/modules/hive-3.1.2/lib/

四、打开hive

1、启动Hive,在hive目录下

bin/hive

2、修改HDFS系统中关于Hive的一些目录权限

  1. /opt/modules/cdh/hadoop-2.5.0-cdh5.3.6/bin/hadoop fs -chmod 777 /tmp/
  2. /opt/modules/cdh/hadoop-2.5.0-cdh5.3.6/bin/hadoop fs -chmod 777 /user/hive/warehouse

五、配置HiveServer2(注:1.几版本的hive不用配)

  1. <property>
  2. <name>hive.server2.long.polling.timeout</name>
  3. <value>5000</value>
  4. <description>Time in milliseconds that HiveServer2 will wait, before responding to asynchronous calls that use long polling</description>
  5. </property>
  6. <property>
  7. <name>hive.server2.thrift.bind.host</name>
  8. <value>hadoop100</value>
  9. <description>Bind host on which to run the HiveServer2 Thrift interface.
  10. Can be overridden by setting $HIVE_SERVER2_THRIFT_BIND_HOST</description>
  11. </property>
  12. <property>
  13. <name>hive.server2.enable.doAs</name>
  14. <value>false</value>
  15. <description>
  16. Setting this property to true will have HiveServer2 execute
  17. Hive operations as the user making the calls to it.
  18. </description>
  19. </property>

1、检查端口:
 $ sudo netstat -antp | grep 10000

2、启动服务:
$ bin/hive --service hiveserver2

3、连接服务:
$ bin/beeline
 beeline> !connect jdbc:hive2://hadoop100:10000 

六、安装hive出现的一些错误

1、Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D

解决方案:在hive 配置文件hive-site.xml 中找到${system:java.io.tmpdir},

并把所有的${system:java.io.tmpdir}都替换成具体目录,如/opt/modules/hive-0.13.1-cdh5.3.6/tmp即可

2、使用hive语句时出现:

Failed with exception java.io.IOException:java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:user.name%7D

解决方案:

①进入hive-site.xml配置文件中

  1. <property>
  2. <name>hive.exec.local.scratchdir</name>
  3. <value>/opt/modules/hive-0.13.1-cdh5.3.6/tmp/${System:user.name}</value>
  4. <description>Local scratch space for Hive jobs</description>
  5. </property>

配置改为如下配置即可,其它地方可以不用改

  1. <property>
  2. <name>hive.exec.local.scratchdir</name>
  3. <value>/opt/modules/hive-0.13.1-cdh5.3.6/tmp/${user.name}</value>
  4. <description>Local scratch space for Hive jobs</description>
  5. </property>

3、在Hive中无法执行任何命令java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.Session

hive的数据库MySQL在安装的时候没有初始化

  1. # 在MySQL中
  2. # 删除mysql中的元数据库
  3. drop databases metastore;
  4. # 新建一个元数据库
  5. create database metastore;
  6. # 在命令行中,重新初始化
  7. schematool -dbType mysql -initSchema

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/396917
推荐阅读
相关标签
  

闽ICP备14008679号