`
lookqlp
  • 浏览: 341762 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

security cdh mapreduce access hbase

阅读更多
执行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)提示需要加入配置:
<property>
        <name>hbase.rpc.protection</name>
        <value>privacy</value>
</property>
经过测试,就因为有了该配置导致如上问题,client hbase site xml不能加入此配置。
说明:
在cdh5.2.0中,
<property>
      <name>hbase.rpc.engine</name>
      <value>org.apache.hadoop.hbase.ipc.SecureRpcEngine</value>
    </property>
此配置也不需要加入xml中。
xml例如:
<property>
<name>hbase.rootdir</name>
<value>hdfs://ip-10-1-33-20.ec2.internal:8020/hbase</value>
</property>
<property>
<name>hbase.client.write.buffer</name>
<value>2097152</value>
</property>
<property>
<name>hbase.client.pause</name>
<value>100</value>
</property>
<property>
<name>hbase.client.retries.number</name>
<value>35</value>
</property>
<property>
<name>hbase.client.scanner.caching</name>
<value>100</value>
</property>
<property>
<name>hbase.client.keyvalue.maxsize</name>
<value>10485760</value>
</property>
<property>
<name>hbase.rpc.timeout</name>
<value>60000</value>
</property>
<property>
<name>hbase.snapshot.enabled</name>
<value>true</value>
</property>
<property>
<name>hbase.security.authentication</name>
<value>kerberos</value>
</property>
<property>
<name>zookeeper.session.timeout</name>
<value>60000</value>
</property>
<property>
<name>zookeeper.znode.parent</name>
<value>/hbase</value>
</property>
<property>
<name>zookeeper.znode.rootserver</name>
<value>root-region-server</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>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</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
<property>
<name>hbase.master.kerberos.principal</name>
<value>hbase/_HOST@YEAHMOBI.COM</value>
</property>
<property>
<name>hbase.regionserver.kerberos.principal</name>
<value>hbase/_HOST@YEAHMOBI.COM</value>


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》




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics