1.å¦ä½å¨windowså¹³å°ä¸ç¨Eclipseè°è¯è¿è¡HBase
2.eclipse中Java程序实现对HBase操作报错:java.io.IOException: Attempt to start meta tracker failed.
å¦ä½å¨windowså¹³å°ä¸ç¨Eclipseè°è¯è¿è¡HBase
ããæä½æ¥éª¤å¦ä¸ï¼ãã1.ä¸è½½åå®è£ cygwinï¼
ãã2.ä¸è½½æ°çZookeeperå åHBaseå ï¼è¿éZooKeeperçæ¬ä¸º3.3.1ï¼HBaseçæ¬ä¸º0..4
ãã3.æå©ç¨å®ä»¬çæºç å å¨Eclipseä¸çæ2个ç¬ç«çProject,源码注æï¼zookeeperå·¥ç¨ï¼è¦æé£ä¸ªconfç®å½å å ¥å°å·¥ç¨çsrcä¸å»
ãã4.ä¿®æ¹zookeeperå·¥ç¨ä¸çconfç®å½ä¸çzoo.cfgæ件ï¼ä¾åå¦ä¸ï¼
ãã# The number of milliseconds of each tick
ããtickTime=
ãã# the directory where the snapshot is stored.
ããdataDir=D:/zookeeper-3.3.1/data
ãã# the port at which the clients will connect
ããclientPort=
ããå°±æ¯ç»zookeeperæå®æ件åæ¾çå°æ¹ä»¥å端å£
ãã5.å¯å¨zookeeper
ããå¨Eclipseä¸æ°å»ºä¸ä¸ªRun configï¼main class为ï¼org.apache.zookeeper.server.quorum.QuorumPeerMain
ããå¯å¨çç¨åºåæ°ä¸ºï¼D:/workspace/zookeeper3.3.1/conf/zoo.cfg
ããå¯å¨çèææºåæ°ä¸ºï¼
ãã-Dzookeeper.log.dir=D:/workspace/zookeeper3.3.1/log
ãã-Dzookeeper.root.logger=INFO,CONSOLE
ããå¦å¾æ示ï¼
ãã好äºï¼è¿æ ·å°±å¯ä»¥å¨Eclipseä¸æZooKeeperå¯å¨èµ·æ¥äºã
ãã6.ä¿®æ¹HBase projectä¸çä¸ä¸ªç±»
ããorg.apache.hadoop.hbase.LocalHBaseCluster
ããæ¾å°å®çmainå½æ°ï¼æmainå½æ°æ¹æä¸
ããpublic static void main(String[] args) throws IOException {
ããHBaseConfiguration conf = new HBaseConfiguration();
ããconf.set("hbase.zookeeper.quorum", "localhost");
ããconf.set("hbase.zookeeper.property.clientPort", "");
ããLocalHBaseCluster cluster = new LocalHBaseCluster(conf,1);
ããcluster.startup();
ãã}ãã
ãã注æè¡ï¼LocalHBaseCluster cluster = new LocalHBaseCluster(conf,1); æé å½æ°ä¸ç1æ¯ä»£è¡¨Region serverç个æ°ï¼å¨è¿éåªæ³èµ·ä¸ä¸ªregion server.
ãã7.ä¿®æ¹HBaseçé ç½®æ件
ããå¨HBase projectä¸çsrcä¸å¯ä»¥çå°hbase-default.xmlåhbase-site.xml两个æ件ï¼æ¹åªä¸ªé½å¯ä»¥ãç´æ¥å¨hbase-default.xmlæ¹çï¼éè¦çæ¯ä¸é¢3个å±æ§hbase.rootdirï¼hbase.cluster.distributedï¼hbase.tmp.dirï¼
ããæhbase.rootdirï¼hbase.tmp.diré½æåäºæ¬å°çç®å½ï¼å½ç¶å¯ä»¥æ ¹æ®èªå·±çéè¦è°æ´,å½ç¶æ ¼å¼ä¸å®ä¸æ ·åã
ãã<property>
ãã<name>hbase.rootdir</name>
ãã<value>file:///D:/hbase-0..3/data </value>
ãã<description>The directory shared by region servers.
ããShould be fully-qualified to include the filesystem to use.
ããE.g: hdfs://NAMENODE_SERVER:PORT/HBASE_ROOTDIR
ãã</description>
ãã</property>
ãã<property>
ãã<name>hbase.cluster.distributed</name>
ãã<value>false </value>
ãã<description>The mode the cluster will be in. Possible values are
ããfalse: standalone and pseudo-distributed setups with managed Zookeeper
ããtrue: fully-distributed with unmanaged Zookeeper Quorum (see hbase-env.sh)
ãã</description>
ãã</property>
ãã<property>
ãã<name>hbase.tmp.dir</name>
ãã<value>D:/hbase-0..3/tmp </value>
ãã<description>Temporary directory on the local filesystem.</description>
ãã</property>
ãã<property>ãã
ãã8.å¯å¨HBaseï¼ç´æ¥run org.apache.hadoop.hbase.LocalHBaseClusterå°±å¯ä»¥ï¼run configä¸éè¦æ²¡æä»ä¹å«çé ç½®ãå½ç¶å°±ä¹å¯ä»¥debugäºã
eclipse中Java程序实现对HBase操作报错:java.io.IOException: Attempt to start meta tracker failed.
我hadoop和Hbase都是采用伪分布式的
代码如下:
public class HbaseTest {
private static Configuration conf;
static{
conf = HBaseConfiguration.create();
conf.set("hbase.rootdir", "hdfs://...2:/hbase");
//使用eclipse时必须添加这个,否则无法定位
conf.set("hbase.zookeeper.quorum",源码喷子双生流派源码 "...2");
conf.set("hbase.zookeeper.property.clientPort", "");
}
public static void createTable(String tableName){
System.out.println("start create table ......");
try {
HBaseAdmin hbAdmin = new HBaseAdmin(conf);
if(hbAdmin.tableExists(tableName)){
hbAdmin.disableTable(tableName);
hbAdmin.deleteTable(tableName);
System.out.println(tableName + " is exist,detele ....");
}
// HTableDescriptor htd = new HTableDescriptor(tableName);
HTableDescriptor htd = new HTableDescriptor(tableName);
htd.addFamily(new HColumnDescriptor("cf1"));
htd.addFamily(new HColumnDescriptor("cf2"));
htd.addFamily(new HColumnDescriptor("cf3"));
htd.addFamily(new HColumnDescriptor("cf4"));
hbAdmin.createTable(htd);
} catch (MasterNotRunningException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("end create table ......");
}
public static void main(String[] args) {
createTable("testTable");
}
更多0