Hbase 总结(7)

2019-08-30 19:35

hbase.superuser

mapr --mapr修改为hadoop的管理用户

【HBase Master】25 --注意是对应有 Master 的节点 /opt/mapr/hbase/hbase-0.98.9/conf/hbase-site.xml

hbase.rpc.engine

org.apache.hadoop.hbase.ipc.SecureRpcEngine

hbase.coprocessor.master.classes

org.apache.hadoop.hbase.security.access.AccessController

hbase.superuser

mapr --mapr修改为hadoop的管理用户

权限控制解析

2015年5月16日 11:19

1. HBase提供的五个权限标识符:RWXCA,分别对应着 READ('R') , WRITE('W') , EXEC('X') , CREATE('C') , ADMIN('A') HBase提供的安全管控级别包括:

Superuser:拥有所有权限的超级管理员用户。通过hbase.superuser参数配置 Global:全局权限可以作用在集群所有的表上。 Namespace:命名空间级。 Table:表级。

ColumnFamily:列簇级权限。 Cell:单元级。

2. 和关系数据库一样,权限的授予和回收都使用grant和revoke,但格式有所不同。grant语法格式:

grant user permissions table column_family column_qualifier 例如,给用户hive分配对表member有读写的权限, 在启用了

hbase.security.authorization之后,默认每个用户只能访问当前的表。而之前创建的member表的属主是HBase,其他用户对其没有访问权限。此时我们通过hive来查找:

# sudo -u hive hbase shell > scan 'member'

ERROR: org.apache.hadoop.hbase.security.AccessDeniedException: Insufficient permissions (table=member, action=READ)在HBase中赋值权限:

# 语法 : grant 参数后面用逗号分隔 # 权限用五个字母表示: \# READ('R'), WRITE('W'), EXEC('X'), CREATE('C'), ADMIN('A') # 例如,给用户‘test'分配对表t1有读写的权限, hbase(main)> grant 'test','RW','t1' 创建表

>create 'hadoop_test12','CF'

> grant 'hive', 'RW', 'member'

0 row(s) in 0.4660 seconds然后通过user_permission来查看权限

> user_permission 'member'

User Table,Family,Qualifier:Permission

Hive member,,: [Permission: actions=READ,WRITE]再在hive中进行查询,此时hive用户已经可以访问。

> scan 'member'

ROW COLUMN+CELL

Elvis column=address:city, timestamp=1425891057211, value=Beijing

3. 对字段赋权给用户:

grant 'test','R','hadoop_test12','CF','LOC_LVL1_CD' -- CF 列簇名

-- LOC_LVL1_CD 字段名

4. 收回权限revoke的语法格式

revoke user table column family column qualifier 收回hive用户在表member上的权限

hbase(main):040:0> revoke 'test' 'TM_CORP_SNMBR_TOP35_M' 'LOC_LVL1_CD' 0 row(s) in 0.1330 seconds

Hbase Java API

2015年5月16日 10:54

文件夹:/BIDATA/hadoop/jyy/hbase/package

编译:javac -classpath /BIDATA/hadoop/hbase/lib/hbase-client-0.98.7-hadoop2.jar:/BIDATA/hadoop/hbase/lib/hbase-common-0.98.7-hadoop2.jar:/BIDATA/hadoop/hbase/lib/hadoop-common-2.2.0.jar -Xlint:deprecation HbaseTest.java

源代码:《HbaseTest.java》

import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Scan; import java.io.IOException; import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.ZooKeeperConnectionException; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.client.Get; import java.util.List; import java.util.ArrayList; import org.apache.hadoop.hbase.client.Delete; public class HbaseTest{ private static Configuration conf = null; static{ Configuration HBASE_CONFIG = new Configuration(); conf = HBaseConfiguration.create(HBASE_CONFIG); } //把表设置成失效状态 public static void hbaseDisableTable(String tbName){ try { HBaseAdmin hBaseAdmin = new HBaseAdmin(conf); hBaseAdmin.disableTable(tbName); } catch(MasterNotRunningException e){ e.printStackTrace(); } catch(ZooKeeperConnectionException e){ e.printStackTrace(); } catch(IOException e){ e.printStackTrace(); } } //删除表 public static void hbaseDleteTable(String tbName){ try { HBaseAdmin hBaseAdmin = new HBaseAdmin(conf); hBaseAdmin.deleteTable(tbName); } catch(MasterNotRunningException e){ e.printStackTrace(); } catch(ZooKeeperConnectionException e){ e.printStackTrace(); } catch(IOException e){ e.printStackTrace(); } } //新建表 public static void hbaseCreateTable(String tbName,String CF){ try { HBaseAdmin hBaseAdmin = new HBaseAdmin(conf); if (hBaseAdmin.tableExists(tbName)){ hBaseAdmin.disableTable(tbName); hBaseAdmin.deleteTable(tbName); } HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(tbName));//设置新建的表名 tableDescriptor.addFamily(new HColumnDescriptor(CF)); //设置列族名 hBaseAdmin.createTable(tableDescriptor); } catch(MasterNotRunningException e){ e.printStackTrace(); } catch(ZooKeeperConnectionException e){ e.printStackTrace(); } catch(IOException e){ e.printStackTrace(); } } //插入数据(一个字段) public static void hbaseInsertOneColumn(String tbName,String CF,String columnName,String columnVal,String rowVal){ Put put=new Put(rowVal.getBytes()); put.add(CF.getBytes(),columnName.getBytes(),columnVal.getBytes());//列族,列名,字段值 try{ HTable table =new HTable(conf,tbName); table.put(put); table.close(); } catch (IOException e) { e.printStackTrace(); } } //插入数据(一行,所有字段) public static void hbaseInsertOneRow(String tbName,String CF,String columnVal){ String columnList[]=new String[10]; columnList=columnVal.split(\String rowVal=columnList[0]; if (rowVal.equals(\System.out.println(\【Error】Primary Key is Null!\ } else{ Put put=new Put(rowVal.getBytes()); if (!(columnList[1].equals(\getBytes(),columnList[1].getBytes());} if (!(columnList[2].equals(\getBytes(),columnList[2].getBytes());} if (!(columnList[3].equals(\\if (!(columnList[4].equals(\\if (!(columnList[5].equals(\tBytes(),columnList[5].getBytes());} if (!(columnList[6].equals(\tBytes(),columnList[6].getBytes());} if (!(columnList[7].equals(\getBytes(),columnList[7].getBytes());}


Hbase 总结(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:道教咒语大全

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: