美文网首页
2018-07-13 hbase

2018-07-13 hbase

作者: 江江江123 | 来源:发表于2018-07-13 11:34 被阅读0次

    hive与hbase
    如果hive相当与hadop中的传统关系数据数据库,那么hbase就是hadoop中的nosql,非关系型数据库

    安装

    环境hadoop,zookeeper
    1.解压hbase
    2.编辑hbase_env.sh
    修改java_home
    修改 HBASE_MANAGES_ZK = FALSE(不使用自带zk)
    3.添加hadoop
    将hadoop /etc/hadoop下的hdfs-site.xml和core-site.xml拷入hbase/conf下
    4.新建hbase_site.xml

    <configuration>
            <!-- 指定hbase在HDFS上存储的路径 -->
            <property>
                    <name>hbase.rootdir</name>
                    <value>hdfs://ip1/hbase</value>
            </property>
            <!-- 指定hbase是分布式的 -->
            <property>
                    <name>hbase.cluster.distributed</name>
                    <value>true</value>
            </property>
            <!-- 指定zk的地址,多个用“,”分割 -->
            <property>
                    <name>hbase.zookeeper.quorum</name>
                    <value>ip1:2181,ip2:2181,ip3:2181</value>
            </property>
        </configuration>
    

    5.编辑regionservers和backup-masters
    regionservers :添加分布式机器
    backup-masters:添加备用主机
    6.拷贝到其它集群
    7.启动
    启动zk,启动hdfs,启动start-hbase.sh

    浏览器访问:ip:16010

    注:启动master
    hbase-daemon.sh start master

    java实现增删改差

    导入hbaseclient

    public class HbaseDemo {
    
        private Configuration conf = null;
        
        @Before
        public void init(){
            conf = HBaseConfiguration.create();
            conf.set("hbase.zookeeper.quorum", "weekend05,weekend06,weekend07");
        }
        
        @Test
        public void testDrop() throws Exception{
            HBaseAdmin admin = new HBaseAdmin(conf);
            admin.disableTable("account");
            admin.deleteTable("account");
            admin.close();
        }
        
        @Test
        public void testPut() throws Exception{
            HTable table = new HTable(conf, "person_info");
            Put p = new Put(Bytes.toBytes("person_rk_bj_zhang_000002"));
            p.add("base_info".getBytes(), "name".getBytes(), "zhangwuji".getBytes());
            table.put(p);
            table.close();
        }
        
    
        @Test
        public void testDel() throws Exception{
            HTable table = new HTable(conf, "user");
            Delete del = new Delete(Bytes.toBytes("rk0001"));
            del.deleteColumn(Bytes.toBytes("data"), Bytes.toBytes("pic"));
            table.delete(del);
            table.close();
        }
    
        @Test
        public void testGet() throws Exception{
            HTable table = new HTable(conf, "person_info");
            Get get = new Get(Bytes.toBytes("person_rk_bj_zhang_000001"));
            get.setMaxVersions(5);
            Result result = table.get(get);
            
            List<Cell> cells = result.listCells();
        
            for(Cell c:cells){
            }
            
            //result.getValue(family, qualifier);  可以从result中直接取出一个特定的value
            
            //遍历出result中所有的键值对
            List<KeyValue> kvs = result.list();
            //kv  ---> f1:title:superise....      f1:author:zhangsan    f1:content:asdfasldgkjsldg
            for(KeyValue kv : kvs){
                String family = new String(kv.getFamily());
                System.out.println(family);
                String qualifier = new String(kv.getQualifier());
                System.out.println(qualifier);
                System.out.println(new String(kv.getValue()));
                
            }
            table.close();
        }
    

    相关文章

      网友评论

          本文标题:2018-07-13 hbase

          本文链接:https://www.haomeiwen.com/subject/lnhjpftx.html