Hive安装详细步骤

一、下载hive

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

二、安装mysql

执行以下几个命令安装mysql

su - root
yum -y install mysql mysql-server mysql-devel
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum -y install mysql-community-server

 开启mysql服务,并为安装hive的节点授权

# 开启Mysql服务
systemctl start mysqld.service
# 设置root用户密码
mysqladmin -uroot password '000000'
# 进入mysql客户端,-p后的为你设置的密码
mysql -uroot -p000000
# 为用户以及其他机器节点授权
mysql> grant all on *.* to root@'hadoop104' identified by '000000';
grant:授权
all:所有权限
*.*:数据库名称.表名称
root:操作mysql的用户
@'':主机名
密码:123456
mysql> flush privileges;

三、解压与配置

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

tar -zxf hive-0.13.1-cdh5.3.6.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配置

<!--判断mysql下是否有这个数据库,没有的话创建-->
<property>
	<name>javax.jdo.option.ConnectionURL</name>
	<value>jdbc:mysql://hadoop100:3306/metastore?createDatabaseIfNotExist=true</value>
	<description>JDBC connect string for a JDBC metastore</description>
</property>
<!--使用mysql driver驱动,默认是hive内置数据库derby驱动-->
<property>
	<name>javax.jdo.option.ConnectionDriverName</name>
	<value>com.mysql.jdbc.Driver</value>
	<description>Driver class name for a JDBC metastore</description>
</property>
<!--mysql账号-->
<property>
	<name>javax.jdo.option.ConnectionUserName</name>
	<value>root</value>
	<description>username to use against metastore database</description>
</property>
<!--mysql密码-->
<property>
	<name>javax.jdo.option.ConnectionPassword</name>
	<value>123456</value>
	<description>password to use against metastore database</description>
</property>
<!--显示查询出的数据的字段名称-->
<property>
  <name>hive.cli.print.header</name>
  <value>true</value>
  <description>Whether to print the names of the columns in query output.</description>
</property>
<!--在hive中显示当前所在数据库名称-->
<property>
  <name>hive.cli.print.current.db</name>
  <value>true</value>
  <description>Whether to include the current database in the Hive prompt.</description>
</property>
<!--使得查询单列数据不会执行mapreduce-->
<property>
  <name>hive.fetch.task.conversion</name>
  <value>more</value>
  <description>
    Some select queries can be converted to single FETCH task minimizing latency.
    Currently the query should be single sourced not having any subquery and should not have
    any aggregations or distincts (which incurs RS), lateral views and joins.
    1. minimal : SELECT STAR, FILTER on partition columns, LIMIT only
    2. more    : SELECT, FILTER, LIMIT only (TABLESAMPLE, virtual columns)
  </description>
</property>

3、修改hive-log4j.properties配置

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

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

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

四、打开hive

1、启动Hive,在hive目录下

bin/hive

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

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

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

<property>
  <name>hive.server2.long.polling.timeout</name>
  <value>5000</value>
  <description>Time in milliseconds that HiveServer2 will wait, before responding to asynchronous calls that use long polling</description>
</property>
<property>
  <name>hive.server2.thrift.bind.host</name>
  <value>hadoop100</value>
  <description>Bind host on which to run the HiveServer2 Thrift interface.
  Can be overridden by setting $HIVE_SERVER2_THRIFT_BIND_HOST</description>
</property>
<property>
  <name>hive.server2.enable.doAs</name>
  <value>false</value>
  <description>
   Setting this property to true will have HiveServer2 execute
    Hive operations as the user making the calls to it.
  </description>
</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配置文件中

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

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

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

猜你喜欢

转载自blog.csdn.net/tyh1579152915/article/details/109405407