Hbase相关问题

1、Hbase启动

需要先启动zookeeper,进入bin路径,./zkServer.sh start

然后启动hdfs和yarn,用start-all.sh

最后启动hbase,start-hbase.sh,在哪台服务器上启动,哪台就是HMaster,可登陆该台主机的16010端口查看Hbase服务

2、Hbase启动好之后,用jps查看,如果只有HMaster启动起来了,slave节点上并未启动起来,原因有可能是时间未同步,可用date命令查看master的和slave节点的时间,如果不一致可以进行时间同步操作,用ntp,具体操作google一下很多。

3、在IDE通过代码连接Hbase集群:

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;

public class ceshi2 {
    private HBaseAdmin admin = null;
    // 定义配置对象HBaseConfiguration
    private static Configuration configuration;
    public ceshi2() throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
        configuration = HBaseConfiguration.create();
        configuration.set("hbase.rootdir","hdfs://master:9000/hbase");//可以吧hadoop改成你的域名或Ip
        configuration.set("hbase.zookeeper.quorum","master,slave1,slave2");  //hbase集群地址,都需要写上
        configuration.set("hbase.zookeeper.property.clientPort","2181"); //端口号默认2128不用改
        admin = new HBaseAdmin(configuration);
    }
    public List<String> getAllTables() {
        List<String> tables = null;
        if (admin != null) {
            try {
                HTableDescriptor[] allTable = admin.listTables();
                if (allTable.length > 0)
                    tables = new ArrayList<String>();
                for (HTableDescriptor hTableDescriptor : allTable) {
                    tables.add(hTableDescriptor.getNameAsString());
                    System.out.println(hTableDescriptor.getNameAsString());
                }
            }catch (IOException e) {
                e.printStackTrace();
            }
        }
        return tables;
    }
    public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
        // TODO 自动生成的方法存根
        new ceshi2().getAllTables();
    }

}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值