ITeye博客

security cdh mapreduce access hbase

lookqlp · 2014-12-02 15:09 · hbase · cloudera · 开源软件 · HBase · Markdown

执行mapreduce的用户必须是可以访问hdfs相应目录和执行mapreduce的账户,例如hive。 指定hive的节点kinit获取执行权限 在mapreduce main代码中加入访问hbase的权限,例如: import java.io.IOException; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.HTableInterface; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.security.UserGroupInformation; public class Connection { private static final String ZK_PATH = "10.1.33.21,10.1.33.22,10.1.33.23"; public static void main(String[] args) { org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum", ZK_PATH); conf.set("hbase.rpc.protection", "privacy"); conf.set("hadoop.security.authentication", "Kerberos"); UserGroupInformation.setConfiguration(conf); try { UserGroupInformation.loginUserFromKeytab(conf.get("hbase.master.kerberos.principal"), conf.get("hbase.keytab.path")); } catch (IOException e1) { e1.printStackTrace(); } // HTablePool tablePool = new HTablePool(conf, 5); // @SuppressWarnings("deprecation") // HTableInterface usersTable = (HTable)tablePool.getTable("dsp_data"); HTableInterface dsp_data; try { dsp_data = new HTable(conf, "dsp_data"); Put p = new Put(Bytes.toBytes("rowkey2")); p.add(Bytes.toBytes("index"), Bytes.toBytes("click_count"), Bytes.toBytes("111")); dsp_data.put(p); dsp_data.close(); } catch (IOException e) { e.printStackTrace(); } } } 同时,hdfs hive yarn xml加入到jar包中,若不行,采用ToolRunner形式执行jar,此种方式可以加载到正确jar包,若还不行,可将xml配置文件,加入/etc/hbase 配置文件夹下。 官方文章中(http://hbase.apache.org/book/security.html)提示需要加入配置: hbase.rpc.protection privacy 经过测试,就因为有了该配置导致如上问题,client hbase site xml不能加入此配置。 说明: 在cdh5.2.0中, hbase.rpc.engine org.apache.hadoop.hbase.ipc.SecureRpcEngine 此配置也不需要加入xml中。 xml例如: hbase.rootdir hdfs://ip-10-1-33-20.ec2.internal:8020/hbase hbase.client.write.buffer 2097152 hbase.client.pause 100 hbase.client.retries.number 35 hbase.client.scanner.caching 100 hbase.client.keyvalue.maxsize 10485760 hbase.rpc.timeout 60000 hbase.snapshot.enabled true hbase.security.authentication kerberos zookeeper.session.timeout 60000 zookeeper.znode.parent /hbase zookeeper.znode.rootserver root-region-server hbase.zookeeper.quorum ip-10-1-33-23.ec2.internal,ip-10-1-33-22.ec2.internal,ip-10-1-33-21.ec2.internal,ip-10-1-33-25.ec2.internal,ip-10-1-33-24.ec2.internal hbase.zookeeper.property.clientPort 2181 hbase.master.kerberos.principal hbase/_HOST@YEAHMOBI.COM hbase.regionserver.kerberos.principal hbase/_HOST@YEAHMOBI.COM mr中使用http://www.cloudera.com/content/cloudera/en/documentation/cdh5/v5-0-0/CDH5-Installation-Guide/cdh5ig_mapreduce_hbase.html TableMapReduceUtil.addDependencyJars(job);方式加载。 并且使用user api加入例如: hbase.master.kerberos.principal=hbase/ip-10-1-10-15.ec2.internal@YEAHMOBI.COM hbase.keytab.path=/home/dev/1015q.keytab 补充:2015-03-17 如上mapreduce访问安全的hbase是不可行的,解决办法参见《mapreduce mapper access security hbase》

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。