ubuntu hive安装记录

hive 安装及使用:

1、把 apache-hive-1.2.2-bin.tar.gz 上传到 linux 的/opt/software 目录下

2、解压 apache-hive-1.2.2-bin.tar.gz 到/opt/module/目录下面
    tar -zxvf apache-hive-1.2.2-bin.tar.gz -C /opt/module/
    
3、修改 apache-hive-1.2.2-bin.tar.gz 的名称为 hive
    mv apache-hive-1.2.2-bin/ hive
    
4、修改/opt/module/hive/conf 目录下的 hive-env.sh.template 名称为 hive-env.sh
    mv hive-env.sh.template hive-env.sh
    
5、配置 hive-env.sh 文件
    1.配置 HADOOP_HOME 路径
        export HADOOP_HOME=/opt/module/hadoop-2.7.2

    2.配置 HIVE_CONF_DIR 路径
    
================================================================================================
启动hive:

1、启动hdfs,yarn
    sbin/hadoop-daemon.sh start namenode
    sbin/hadoop-daemon.sh start datanode
    sbin/yarn-daemon.sh start resourcemanager
    sbin/yarn-daemon.sh start nodemanager
    
    或者:
    sbin/start-dfs.sh
    sbin/start-yarn.sh

2、在 HDFS 上创建/tmp 和/user/hive/warehouse 两个目录并修改他们的同组权限可写
    bin/hadoop fs -mkdir /tmp
    bin/hadoop fs -mkdir -p /user/hive/warehouse

    bin/hadoop fs -chmod g+w /tmp
    bin/hadoop fs -chmod g+w /user/hive/warehouse


3、启动hive
    bin/hive
    
4、hive操作(类似于mysql):
    增,删,查
    
5、将本地文件导入hive:
    1.在/opt/module/目录下创建 datas
        mkdir datas
    2.创建 student.txt 文件并添加数据
        vi student.txt(以空格分割)

    3.启动hive,使用default 数据库
    4.删除student表
    5.创建新student表
        create table student(id int, name string) row format delimited fields terminated by ' ';
    6.加载/opt/module/datas/student.txt 文件到 student 数据库表中
        load data local inpath '/opt/module/datas/student.txt' into table student;

6、问题:
    无法窗口启动hive:
    
    原因是, Metastore 默认存储在自带的 derby 数据库中,推荐使用 MySQL 存储 Metastore;
    

================================================================================================
安装mysql

1.查看是否安装mysql:
    rpm -qa|grep mysql

2.删除已有mysql:
    rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64
    
3.将MySQL-server-5.6.41-1.el6.x86_64.rpm,MySQL-client-5.6.41-1.el6.x86_64.rpm复制到 /opt/software 下

4.安装 mysql 服务端
    1.安装
        rpm -ivh MySQL-server-5.6.41-1.el6.x86_64.rpm
    
    2.查看随机生的密码:
        cat /root/.mysql_secret
    
    3.查看mysql状态,启动mysql服务:
         service mysql status
          service mysql start

6.安装mysql客户端:
    1.安装
        rpm -ivh MySQL-client-5.6.41-1.el6.x86_64.rpm
    2.登录:
        mysql -uroot -p
        
    3.修改密码:
        set password=password('123456')

7.配置mysql user 表中主机配置:
    show databases;
    use mysql;
    show tables;
    查看表结构:
        desc user;
    select User, Host, Password from user;
    修改 user 表,把 Host 表内容修改为%
        update user set host='%' where host='localhost';
    删除 root 用户的其他 host:
        delete from user where Host in ('hadoop102','127.0.0.1','::1') ';
    刷新:
        flush privileges;


================================================================================================
Hive 元数据配置到 MySql

1、拷贝驱动:
    tar -zxvf mysql-connector-java-8.0.12.tar.gz
    cd mysql-connector-java-8.0.12
    cp mysql-connector-java-8.0.12.jar /opt/module/hive/lib/

2、配置Metastore 到 MySql
    1.在/opt/module/hive/conf 目录下创建一个 hive-site.xml
        vi hive-site.xml
        
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://centos66:3306/metastore?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
<description>password to use against metastore database</description>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
<description>Whether to include the current database in the Hive
prompt.</description>
</property>
<property>
<name>hive.cli.print.header</name>
<value>false</value>
<description>Whether to print the names of the columns in query output.</description>
</property>
</configuration>

3、多窗口测试:
    启动hive(若启动异常,重启机器,开启hadoop集群)


================================================================================================
hive 的一些操作:
    1.查看hdfs文件系统:
        dfs -ls /;
    
    2.查看本地文件:
        ! ls /opt/module/

    3.查看hive中输入历史记录:
        cat /root/.hivehistory

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值