【HBase Master】25 --注意是对应有 Master 的节点 /opt/mapr/hbase/hbase-0.98.9/conf/hbase-site.xml
权限控制解析
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
>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());}