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)
网友评论