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();
}
}