美文网首页
Hive单节点搭建

Hive单节点搭建

作者: 小左伯爵 | 来源:发表于2020-12-06 16:54 被阅读0次

1.安装mysql

#yum安装
[root@node01 ~]# yum install mysql-server
[root@node01 ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@node01 ~]# service mysqld start
[root@node01 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user,password from user;
+-----------+------+----------+
| host      | user | password |
+-----------+------+----------+
| localhost | root |          |
| node01    | root |          |
| 127.0.0.1 | root |          |
| localhost |      |          |
| node01    |      |          |
+-----------+------+----------+
5 rows in set (0.00 sec)
# grant授权
#all privileges所有权限
#*.*所有库的所有表
#'root'@'%'允许远程访问
#identified by '123456'  密码
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from user;                                               
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root |                                           |
| node01    | root |                                           |
| 127.0.0.1 | root |                                           |
| localhost |      |                                           |
| node01    |      |                                           |
| %         | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------+-------------------------------------------+
6 rows in set (0.00 sec)
mysql> delete from user where host != '%';

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye
[root@node01 ~]# mysql -uroot -p
Enter password:

2.启动相关程序

#1.启动zookeeper,在node02,node03,node04上
[root@node02 ~]# zkServer.sh start
[root@node03 ~]# zkServer.sh start
[root@node04 ~]# zkServer.sh start
#2.启动hadoop集群
[root@node01 sbin]# start-all.sh 
WARNING: HADOOP_SECURE_DN_USER has been replaced by HDFS_DATANODE_SECURE_USER. Using value of HADOOP_SECURE_DN_USER.
Starting namenodes on [node01 node02 node03]
Starting datanodes
Starting journal nodes [node01 node02 node03]
Starting ZK Failover Controllers on NN hosts [node01 node02 node03]
Starting resourcemanagers on [ node01 node02 node03]
Starting nodemanagers

3.解压文件

#在node02上
[root@node02 hive]# tar -xvf apache-hive-3.1.2-bin.tar.gz 
[root@node02 hive]# ls
apache-hive-3.1.2-bin  apache-hive-3.1.2-bin.tar.gz  mysql-connector-java-5.1.32-bin.jar
[root@node02 hive]# mv apache-hive-3.1.2-bin apache-hive-3.1.2

4.配置环境变量

[root@node02 ~]# vim /etc/profile
export JAVA_HOME=/opt/jdk/jdk1.8.0_144
export HADOOP_HOME=/opt/hadoop/hadoop-3.2.1
export ZOOKEEPER_HOME=/opt/zookeeper/apache-zookeeper-3.6.2
export HIVE_HOME=/opt/hive/apache-hive-3.1.2
export PATH=$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZOOKEEPER_HOME/bin:$HIVE_HOME/bin:$PATH
[root@node02 ~]# source  /etc/profile

5.修改hive-site.xml

[root@node02 conf]# cp hive-default.xml.template hive-site.xml
#删除当前光标行到最后一行,删掉默认配置
:.,$-1d
#配置为
<configuration>
  <property>  
    <name>metastore.warehouse.dir</name>  
    <value>/opt/hive/warehouse</value>  
  </property>  
     
     
  <property>  
    <name>javax.jdo.option.ConnectionURL</name>  
    <value>jdbc:mysql://node01/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>root</value>  
  </property>  
     
  <property>  
    <name>javax.jdo.option.ConnectionPassword</name>  
    <value>123456</value>  
  </property>  
</configuration>

6. 拷贝驱动包

[root@node02 hive]# cp mysql-connector-java-5.1.32-bin.jar apache-hive-3.1.2/lib/

7.启动

#启动
[root@node02 apache-hive-3.1.2]# hive
#报错
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V

#jar包版本不一致
#找到hadoop的目录下的guava.jar包,找到hive目录下的guava.jar包,用高版本替换低版本,两个目录分别为
/opt/hadoop/hadoop-3.2.1/share/hadoop/common/lib
/opt/hive/apache-hive-3.1.2/lib
[root@node02 lib]# cp guava-27.0-jre.jar /opt/hive/apache-hive-3.1.2/lib/guava-19.0.jar
#再次启动
hive> show tables;
FAILED: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
#初始化数据库
[root@node02 lib]#  schematool -dbType mysql -initSchema
hive> show tables;
OK
Time taken: 0.457 seconds

8.操作

hive> show tables;
OK
Time taken: 0.457 seconds
hive> create table tbl(id int,age int);
OK
Time taken: 0.4 seconds
hive> show tables;
OK
tbl
Time taken: 0.042 seconds, Fetched: 1 row(s)
#插入数据
hive> insert into tbl values(1,2);
Query ID = root_20201207001446_14c92ef1-6675-4817-8d20-fe4760b1a587
Total jobs = 3
Launching Job 1 out of 3
Number of reduce tasks determined at compile time: 1
In order to change the average load for a reducer (in bytes):
  set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
  set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
  set mapreduce.job.reduces=<number>
Starting Job = job_1607266191449_0001, Tracking URL = http://node01:8088/proxy/application_1607266191449_0001/
Kill Command = /opt/hadoop/hadoop-3.2.1/bin/mapred job  -kill job_1607266191449_0001
Hadoop job information for Stage-1: number of mappers: 0; number of reducers: 0
2020-12-07 00:14:57,609 Stage-1 map = 0%,  reduce = 0%
Ended Job = job_1607266191449_0001 with errors
Error during job, obtaining debugging information...
FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
MapReduce Jobs Launched: 
Stage-Stage-1:  HDFS Read: 0 HDFS Write: 0 FAIL
Total MapReduce CPU Time Spent: 0 msec
#可登录http://node01:8088/cluster,查看任务
失败了,报错
Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster
Please check whether your etc/hadoop/mapred-site.xml contains the below configuration:
<property>
<name>yarn.app.mapreduce.am.env</name>
<value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
</property>
<property>
<name>mapreduce.map.env</name>
<value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
</property>
<property>
<name>mapreduce.reduce.env</name>
<value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
</property>
[root@node01 hadoop]# vim mapred-site.xml 
#添加
<property>
  <name>yarn.app.mapreduce.am.env</name>
  <value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
  <name>mapreduce.map.env</name>
  <value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
  <name>mapreduce.reduce.env</name>
  <value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
#分发文件,重启 stop-all.sh start-all.sh
[root@node01 hadoop]# scp mapred-site.xml root@node02:`pwd`/
mapred-site.xml                                                                                100% 1184     1.2KB/s   00:00    
[root@node01 hadoop]# scp mapred-site.xml root@node03:`pwd`/
mapred-site.xml                                                                                100% 1184     1.2KB/s   00:00    
[root@node01 hadoop]# scp mapred-site.xml root@node04:`pwd`/
mapred-site.xml                                                                                100% 1184     1.2KB/s   00:00 
#再次执行插入操作
hive> insert into tbl values(1,2);
#报错org.apache.hadoop.yarn.exceptions.InvalidAuxServiceException: The auxService:mapreduce_shuffle does not exist
#修改yarn-site.xml
[root@node01 hadoop]# vim yarn-site.xml 
#添加以下内容
<property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
</property>
<property>
    <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
    <value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
#分发配置到其他节点,重启
#再次执行插入,成功
hive> select * from tbl;
OK
1       2
Time taken: 0.182 seconds, Fetched: 1 row(s)

9.在mysql中查看源数据信息

mysql> show databases; 
mysql> use hive_remote;
mysql> show tables;
mysql> select * from TBLS;
+--------+-------------+-------+------------------+-------+------------+-----------+-------+----------+---------------+--------------------+--------------------+--------------------+
| TBL_ID | CREATE_TIME | DB_ID | LAST_ACCESS_TIME | OWNER | OWNER_TYPE | RETENTION | SD_ID | TBL_NAME | TBL_TYPE      | VIEW_EXPANDED_TEXT | VIEW_ORIGINAL_TEXT | IS_REWRITE_ENABLED |
+--------+-------------+-------+------------------+-------+------------+-----------+-------+----------+---------------+--------------------+--------------------+--------------------+
|      1 |  1607271108 |     1 |                0 | root  | USER       |         0 |     1 | tbl      | MANAGED_TABLE | NULL               | NULL               |                    |
+--------+-------------+-------+------------------+-------+------------+-----------+-------+----------+---------------+--------------------+--------------------+--------------------+
1 row in set (0.00 sec)

相关文章

  • Hive单节点搭建

    https://cwiki.apache.org/confluence/display/Hive/GettingS...

  • Hive环境搭建

    基于三节点的Hadoop集群搭建Hive 安装中前的准备 先要搭建好hadoop集群 安装中用到的软件: hive...

  • kubeadm搭建高可用集群

    使用 kubeadm 搭建单节点集群已经介绍过了,关于如何初始化环境,安装依赖组件请参考kubeadm搭建单节点集...

  • 2.2 搭建本地单节点测试网络

    搭建本地单节点测试网络 本教程用于描述如何搭建本地单节点测试网络。本教程功能上类似于 mininode,但是脚本更...

  • Hive组件部署-单节点

    1.安装前提 1.已经安装好Mysql,并且设置MySQL的服务是开机自启的。Centos中MySQL服务的启动、...

  • hadoop单节点搭建

    总结一下这些天做的乱七八糟的工作,虽然我大部分的时间都在摸鱼,但也是做了不少功夫。在被官方文档坑+其他各型网站坑过...

  • Hadoop 单节点搭建

    Hadoop 单节点搭建 环境: VirtualBox Unbuntu14.04 LTS 安装JDK 查看当前j...

  • rabbitmq单节点搭建

    rabbitmq 搭建 相关链接 https://www.cnblogs.com/huhongy/p/125583...

  • elasticsearch 集群环境搭建

    单节点安装 在elasticsearch 提供服务前,我们先搭建一套es环境,首先我们搭建一个es节点,https...

  • 2. EOS 测试网络搭建指南

    EOS 测试网络搭建指南 本章节用于指导新手如何搭建 EOS 测试网络。测试网络种类包括:单节点、本地多节点、多主...

网友评论

      本文标题:Hive单节点搭建

      本文链接:https://www.haomeiwen.com/subject/hqdowktx.html