• hbase 安装与使用


    安装

    1.下载
    wget http://mirrors.shu.edu.cn/apache/hbase/1.4.6/hbase-1.4.6-bin.tar.gz
    tar -zxvf hbase-1.4.6-bin.tar.gz

    2.配置 hbase-site.xml 文件
    <configuration>
    <property>
    <name>hbase.rootdir</name>
    <value>hdfs://localhost:9000/hbase</value>
    </property>
    <property>
    <name>hbase.cluster.distributed</name>
    <value>true</value>
    </property>

    </configuration>
    hbase.rootdir:该参数制定了HReion服务器的位置,即数据存放的位置。
    主要端口号要和Hadoop相应配置一致。
    hbase.cluster.distributed:HBase的运行模式。
    false是单机模式,
    true是分布式模式。
    若为false, HBase和Zookeeper会运行在同一个JVM里面。默认为false
    3.设置环境变量
    3.1修改HBase下的conf目录中的hbase-env.sh文件
    export JAVA_HOME=/usr/java/jdk1.8.0_161
    export HBASE_MANAGES_ZK=false
    注:
    export HBASE_MANAGES_ZK=true 此配置信息,表示设置由hbase自己管理zookeeper,不需要单独的zookeeper,
    本文搭建的 Hbase 用的是自带的 zookeeper,故设置为true
    3.2 修改 /etc/profile文件
    export PATH=$PATH:/usr/hadoop/hbase-1.4.6/bin

    4.启动(必须先确保 HDFS 已经启动)
    #cd r/hadoop/hbase-1.4.6/bin
    #sh start-hbase.sh
    5922 NodeManager
    6851 RunJar
    5684 ResourceManager
    3510 NameNode
    6392 DataNode
    15304 HRegionServer
    15592 Jps
    5513 SecondaryNameNode
    15134 HQuorumPeer
    15199 HMaster
    5.停止 HBase
    #sh stop-hbase.sh

    基本命令

    [root@slave1 local]#hbase shell #进入HBase客户端命令行
    hbase(main):001:0> status [HBase的状态,例如服务器的数量]
    hbase(main):002:0> version [获取正在使用的HBase版本]
    hbase(main):003:0> table_help [表引用命令提供帮助]
    list [列出HBase的所有表]

    [创建表]
    # 创建表t1,有两个family name:f1,f2,且版本数均为2
    create 't1',{NAME => 'f1', VERSIONS => 2},{NAME => 'f2', VERSIONS => 2}
    create 'test','cf' [test为表名,cf为列族]
    create 'test1','cf1','cf2'
    create 'student','info'

    [查看表结构]
    echo "describe 'student'"|hbase shell
    describe 'student'

    [插入数据到表]
    hbase(main):003:0> put 'student','1001','info:sex','male'
    hbase(main):004:0> put 'student','1001','info:age','18'
    hbase(main):005:0> put 'student','1002','info:name','Janna'
    hbase(main):006:0> put 'student','1002','info:sex','female'
    hbase(main):007:0> put 'student','1002','info:age','20'

    [扫描查看表数据]
    hbase(main):008:0> scan 'student'
    hbase(main):009:0> scan 'student',{STARTROW => '1001', STOPROW => '1001'}
    hbase(main):010:0> scan 'student',{STARTROW => '1001'}
    hbase(main):201:0> scan 'student',{STARTROW=>'1',LIMIT=>1}
    hbase(main):124:0> scan 'student',{LIMIT=>2} #扫描表student的前5条数据

    [更新指定字段的数据]
    hbase(main):012:0> put 'student','1001','info:name','Nick'
    hbase(main):013:0> put 'student','1001','info:age','100'

    [查看[指定行”或“指定列族:列]的数据]
    echo "get 'boye:test','10001','info:name'"|hbase shell
    hbase(main):014:0> get 'student','1001'
    hbase(main):015:0> get 'student','1001','info:name'
    hbase(main):080:0> get 'student','1001','info:age','info:sex'

    [删除数据]
    hbase(main):016:0> deleteall 'student','1001' #删除某rowkey的全部数据
    hbase(main):017:0> delete 'student','1002','info:sex' #删除某rowkey的某一列数据

    [删除表]
    分两步:首先disable,然后drop
    hbase(main):019:0> disable 'student'
    hbase(main):020:0> drop 'student'

    [清空表数据]
    hbase(main):018:0> truncate 'student'
    提示:清空表的操作顺序为先disable,然后再truncate

    [变更表信息]
    将info列族中的数据存放3个版本:
    hbase(main):022:0> alter 'student',{NAME=>'info',VERSIONS=>3}
    hbase(main):132:0> get 'student','1001',{COLUMN=>'info:name',VERSIONS=>1}

    [命名空间]
    hbase(main):132:0> list_namespace #查看命名空间
    hbase(main):132:0> create_namespace 'boye' #创建命名空间
    hbase(main):132:0> create 'boye:test','info','detail' #指定命名空间创建表

  • 相关阅读:
    塔 · 第 二 条 约 定
    nyoj 325
    塔 · 第 一 条 约 定
    大一上
    Django之ORM
    mysql概念
    数据库索引
    使用pymysql进行数据库的增删改查
    sql注入攻击
    pymysql
  • 原文地址:https://www.cnblogs.com/boye169/p/13861767.html
Copyright © 2020-2023  润新知