cdh5.7.0偽分散式叢集之hive安裝
基本環境及軟體:
軟體版本 | 軟體包 |
---|---|
centos-6.4 | |
JDK-1.8 | jdk-8u191-linux-x64.tar.gz |
hadoop-2.6.0 | hadoop-2.6.0-cdh5.7.0.tar.gz |
hive-1.1.0 | hive-1.1.0-cdh5.7.0.tar.gz |
軟體安裝包官網下載地址 :http://archive-primary.cloudera.com/cdh5/cdh/5/
安裝mysql
1.使用yum安裝mysql server。
# yum install -y mysql-server
2.啟動mysql
# service mysqld start
3.設定開機啟動
# chkconfig mysqld on
3.進入mysql :
# mysql
4.在mysql上建立hive元資料庫,並對hive進行授權
mysql> create database if not exists hive_metadata;
mysql> grant all privileges on hive_metadata.* to 'hive'@'%' identified by 'hive';
mysql> grant all privileges on hive_metadata.* to 'hive'@'localhost' identified by 'hive';
mysql> grant all privileges on hive_metadata.* to 'hive'@'bigdata' identified by 'hive';
5.重新整理,即時生效
mysql> flush privileges;
6.簡單測試,
mysql>use hive_metadata;
安裝hive
注意:安裝之前需要先安裝Hadoop,請參考另一篇文章:https://blog.csdn.net/weixin_39689084/article/details/84548507
1.將下載的hive安裝包上傳到虛擬機器的/usr/local/app目錄下
2.解壓縮hive安裝包:
# tar -zxvf hive-1.1.0-cdh5.7.0.tar.gz
3.重新命名hive目錄:
# mv hive-1.1.0-cdh5.7.0 hive-1.1.0
4.配置hive相關的環境變數
# vim ~/.bashrc
#set hive environment
export HIVE_HOME=/usr/local/app/hive-1.1.0
export PATH=$PATH:$HIVE_HOME/bin
# source ~/.bashrc
5.使用yum安裝mysql connector
# yum install -y mysql-connector-java
6.將mysql connector拷貝到hive的lib包中
# cp /usr/share/java/mysql-connector-java-5.1.17.jar /usr/local/app/hive-1.1.0/lib
7.配置 hive-site.xml ,在conf目錄下建立hive-site.xml
# vim hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://bigdata:3306/hive_metadata?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>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
</configuration>
8.配置hive-env.sh
# cp hive-env.sh.template hive-env.sh
# vim hive-env.sh
export JAVA_HOME=/usr/local/app/jdk1.8.0_191
export HIVE_HOME=/usr/local/app/hive-1.1.0
export HADOOP_HOME=/usr/local/app/hadoop-2.6.0
啟動hive
# hive
hive的一些簡單操作:在hive上建立員工和部門兩張表
1.建立表
一、員工表
create table emp(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
)
row format delimited fields terminated by '\t';二、部門表
create table dept(
deptno int,
dname string,
loc string
)
row format delimited fields terminated by '\t';
2,載入資料
a.準備資料,在/usr/local/下建立data目錄,存放測試資料
# cd /usr/local/
# mkdir data
# cd data/
# vim emp.txt
7369 SMITH CLERK 7902 1980-12-17 800.0 0.0 20
7499 ALLEN SALESMAN 7698 1981-02-20 1600.0 300.0 30
7521 WARD SALESMAN 7698 1981-02-22 1250.0 500.0 30
7566 JONES MANAGER 7839 1981-04-02 2975.0 0.0 20
7654 MARTIN SALESMAN 7698 1981-09-28 1250.0 1400.0 30
7698 BLAKE MANAGER 7839 1981-05-01 2850.0 0.0 30
7782 CLARK MANAGER 7839 1981-06-09 2450.0 0.0 10
7788 SCOTT ANALYST 7566 1987-07-13 3000.0 0.0 20
7839 KING PRESIDENT NULL 1981-11-07 5000.0 0.0 10
7844 TURNER SALESMAN 7698 1981-09-08 1500.0 0.0 30
7876 ADAMS CLERK 7788 1987-07-13 1100.0 0.0 20
7900 JAMES CLERK 7698 1981-12-03 950.0 0.0 30
7902 FORD ANALYST 7566 1981-12-03 3000.0 0.0 20
7934 MILLER CLERK 7782 1982-01-23 1300.0 0.0 10# vim dept.txt
10 ACCOUNTING NEWYORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
b.載入資料
hive> load data local inpath '/usr/local/data/emp.txt' into table emp;
hive> load data local inpath '/usr/local/data/dept.txt' into table dept;
c.查詢資料
hive> select * from emp;
hive> select * from dept;
到此hive安裝完成,有錯誤之處,請多多指教 !