目录
1.安装单用户模式
2.安装MySQL
3.文件配置
4.启动验证
数据仓库工具hive是基于Hadoop集群运行的,在安装hive之前,确保电脑已经启动Hadoop集群。
1.安装单用户模式
对hive软件包进行上传解压,重命名后,输入命令启动hive。
[root@master ~]# cd /export/software/ [root@master software]# rz -be [root@master software]# tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /export/servers/ [root@master software]# cd /export/servers/ [root@master servers]# ls apache-hive-1.2.1-bin hadoop-2.6.4 jdk [root@master servers]# mv apache-hive-1.2.1-bin hive [root@master servers]# ls hadoop-2.6.4 hive jdk [root@master servers]# cd hive/ [root@master hive]# bin/hive
启动hive时,若出现以下错误:
若启动集群后,NamNode处于安全模式,会造成hive启动不成功,需要关闭安全模式。
图1-1 NameNode处于安全模式
[root@master hive]# hadoop dfsadmin -safemode leave
若启动集群后,出现如图1-2所示错误。需要将hive安装目录lib文件下一个jar包复制到Hadoop安装目录下,并需要把原来版本删除。
图1-2 初始化失败
[root@master hive]# cd /export/servers/hadoop-2.6.4/share/hadoop/yarn/lib/ [root@master lib]# cp /export/servers/hive/lib/jline-2.12.jar . [root@master lib]# ls activation-1.1.jar jaxb-impl-2.2.3-1.jar aopalliance-1.0.jar jersey-client-1.9.jar asm-3.2.jar jersey-core-1.9.jar commons-cli-1.2.jar jersey-guice-1.9.jar commons-codec-1.4.jar jersey-json-1.9.jar commons-collections-3.2.2.jar jersey-server-1.9.jar commons-compress-1.4.1.jar jettison-1.1.jar commons-httpclient-3.1.jar jetty-6.1.26.jar commons-io-2.4.jar jetty-util-6.1.26.jar commons-lang-2.6.jar jline-0.9.94.jar commons-logging-1.1.3.jar jline-2.12.jar guava-11.0.2.jar jsr305-1.3.9.jar guice-3.0.jar leveldbjni-all-1.8.jar guice-servlet-3.0.jar log4j-1.2.17.jar jackson-core-asl-1.9.13.jar netty-3.6.2.Final.jar jackson-jaxrs-1.9.13.jar protobuf-java-2.5.0.jar jackson-mapper-asl-1.9.13.jar servlet-api-2.5.jar jackson-xc-1.9.13.jar stax-api-1.0-2.jar javax.inject-1.jar xz-1.0.jar jaxb-api-2.2.2.jar zookeeper-3.4.6.jar [root@master lib]# rm -f jline-0.9.94.jar [root@master lib]# cd /export/servers/hive/ [root@master hive]# bin/hive Logging initialized using configuration in jar:file:/export/servers/hive/lib/hive-common-1.2.1.jar!/hive-log4j.properties hive> exit; [root@master hive]#
出现hive命令行窗口表示单用户模式安装成功。
2.安装MySQL
查询Linux系统中数据库软件安装情况。
[root@master hive]# rpm -qa|grep mariadb* mariadb-libs-5.5.56-2.el7.x86_64 [root@master hive]# yum remove mariadb* Loaded plugins: fastestmirror, langpacks Resolving Dependencies --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be erased --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 --> Running transaction check ---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased --> Finished Dependency Resolution base/7/x86_64 | 3.6 kB 00:00 extras/7/x86_64 | 2.9 kB 00:00 updates/7/x86_64 | 2.9 kB 00:00 Dependencies Resolved ============================================================================ Package Arch Version Repository Size ============================================================================ Removing: mariadb-libs x86_64 1:5.5.56-2.el7 @anaconda 4.4 M Removing for dependencies: postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M Transaction Summary ============================================================================ Remove 1 Package (+1 Dependent package) Installed size: 17 M Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : 2:postfix-2.10.1-6.el7.x86_64 1/2 Erasing : 1:mariadb-libs-5.5.56-2.el7.x86_64 2/2 Verifying : 1:mariadb-libs-5.5.56-2.el7.x86_64 1/2 Verifying : 2:postfix-2.10.1-6.el7.x86_64 2/2 Removed: mariadb-libs.x86_64 1:5.5.56-2.el7 Dependency Removed: postfix.x86_64 2:2.10.1-6.el7 Complete! [root@master hive]#
将系统中自带的mariadb软件卸载,卸载过程若出现交互,一律填写"y"。
以下代码实现安装MySQL数据库,并将数据库登录权限更改为:root用户在任何主机上使用密码可登录MySQL。
[root@master hive]# sudo rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-release-el7-5 ################################# [100%]
[root@master hive]# yum install mysql mysql-server mysql-devel
[root@master hive]# service mysql start
Redirecting to /bin/systemctl start mysql.service
[root@master hive]# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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 |
| performance_schema |
+--------------------+
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 user,host,password from user;
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
| root | master | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | master | |
+------+-----------+----------+
6 rows in set (0.00 sec)
mysql> update user set host='%' where host='::1';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> delete from user where host='127.0.0.1';
Query OK, 1 row affected (0.00 sec)
mysql> delete from user where host='master';
Query OK, 2 rows affected (0.00 sec)
mysql> delete from user where host='localhost';
Query OK, 2 rows affected (0.00 sec)
mysql> update user set password=password('123456') where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select user,host,password from user;
+------+------+-------------------------------------------+
| user | host | password |
+------+------+-------------------------------------------+
| root | % | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+------+-------------------------------------------+
1 row in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
[root@master hive]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@master hive]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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>
若出现yum 安装不成功情况,可查看主机是否可上网。访问外网不成功,可查看设置静态IP文件是否出错。
3.文件配置
hive-env.sh
设置hadoop环境变量,作用是无论系统是否配置hadoop环境变量,在hive执行时可通过hive-env.sh加载hadoop环境变量。将以下内容添加到hive-env.sh文件末尾。
export HADOOP_HOME=/export/servers/hadoop-2.6.4
export HIVE_CONF_DIR=/export/servers/hive/conf
[root@master ~]# cd /export/servers/hive [root@master hive]# cd conf/ [root@master conf]# cp hive-env.sh.template hive-env.sh [root@master conf]# vi hive-env.sh
hive-site.xml
conf目录下没有该文件,利用vi新建该文件,并将以下内容粘贴到hive-site.xml文件中。(注意:
[root@master conf]# vi hive-site.xml
上传连接Mysql JDBC驱动jar包。
[root@master conf]# cd ../lib/ [root@master lib]# rz -be
4.启动验证
输入对应启动hive命令,成功进入命令行窗口。同时Mysql下出现metastore数据库,表示多用户模式安装成功。
[root@master hive]# bin/hive Logging initialized using configuration in jar:file:/export/servers/hive/lib/hive-common-1.2.1.jar!/hive-log4j.properties hive> [root@master hive]# mysql -uroot -p123456 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 13 Server version: 5.6.51 MySQL Community Server (GPL) Copyright (c) 2000, 2021, 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 | | metastore | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec) mysql>



