1. 먼저 mac에 hadoop 1.0.4 을 설치하고, hdf로 동작되는지 확인 (hbase 0.94.6이랑 맞는 pair 버전)

http://blrunner.com/29


2, Zookeeper 설치

2181포트를 띄우도록 함


3. hbase 0.94.6설치 / 설정 변경 


설치 - http://knight76.tistory.com/entry/Hbase-mac-install-mac%EC%97%90-hbase-mac-%EC%84%A4%EC%B9%98

설정을 변경


1) 설정 수정

conf/hbase-site.xml  수정


<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>


<configuration>


        <property>

                <name>hbase.rootdir</name>

                <value>hdfs://127.0.0.1:9000/hbase</value>

                <description></description>

        </property>

        <property>

                <name>hbase.cluster.distributed</name>

                <value>true</value>

        </property>


        <property>

                <name>hbase.zookeeper.property.dataDir</name>

                <value>/nosql/zookeeper</value>

        </property>


        <property>

                <name>hbase.zookeeper.quorum</name>

                <value>127.0.0.1</value>

        </property>


        <property>

                <name>hbase.zookeeper.property.clientPort</name>

                <value>2181</value>

        </property>


        <property>

                <name>hbase.regionserver.info.bindAddress</name>

                <value>127.0.0.1</value>

        </property>


</configuration>




conf/hbase-env.sh 수정


export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

export HBASE_LOG_DIR=${HBASE_HOME}/logs

export HBASE_MANAGES_ZK=true



2)실행

master 실행

% bin/start-hbase.sh


master backup 실행

% bin/local-master-backup.sh start 1


region server 실행

$ ./local-regionservers.sh start 1


3) 데몬 확인

$ ps -ef | grep master | grep hbase

... org.apache.hadoop.hbase.master.HMaster start

..  org.apache.hadoop.hbase.master.HMaster -D hbase.master.port=60001 -D hbase.master.info.port=60011 --backup start


$ ps -ef | grep region | grep hbase

.. org.apache.hadoop.hbase.regionserver.HRegionServer start

.. org.apache.hadoop.hbase.regionserver.HRegionServer -D hbase.regionserver.port=60201 -D hbase.regionserver.info.port=60301 start


4. Java Test Code로 확인

1) 소스
package com.google.sample.hbase;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;

public class HBaseTest {
public static void main(String[] args) {
Configuration config = HBaseConfiguration.create();
config.set("hbase.master", "127.0.0.1"); 
    // config.set("hbase.zookeeper.quorum", "127.0.0.1");   // 이것도 되는지 확인
try {
HBaseAdmin hBaseAdmin = new HBaseAdmin(config);

if (hBaseAdmin.isTableAvailable("key1") == false) {
HTableDescriptor tableDs = new HTableDescriptor("key1");
tableDs.addFamily(new HColumnDescriptor("cf"));
hBaseAdmin.createTable(tableDs);
} else {
hBaseAdmin.disableTable("key1");
hBaseAdmin.deleteTable("key1");

HTableDescriptor tableDs = new HTableDescriptor("key1");
tableDs.addFamily(new HColumnDescriptor("cf"));
hBaseAdmin.createTable(tableDs);
}
HTable hTable = new HTable(config, "key1");
Put p = new Put(Bytes.toBytes("row1"));
p.add(Bytes.toBytes("cf"), Bytes.toBytes("a"), Bytes.toBytes("value1"));
hTable.put(p);
p = new Put(Bytes.toBytes("row2"));
p.add(Bytes.toBytes("cf"), Bytes.toBytes("b"), Bytes.toBytes("value2"));
hTable.put(p);
p = new Put(Bytes.toBytes("row3"));
p.add(Bytes.toBytes("cf"), Bytes.toBytes("c"), Bytes.toBytes("value3"));
hTable.put(p);
Scan s = new Scan();
ResultScanner scanner = hTable.getScanner(s);
try {
for (Result rowResult = scanner.next(); rowResult != null; rowResult = scanner.next()) {
System.out.println("row: " + rowResult);
}
} finally {
scanner.close();
}
hTable.close();
hBaseAdmin.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}


잘도는 지 확인 

row: keyvalues={row1/cf:a/1365158122457/Put/vlen=6/ts=0}

row: keyvalues={row2/cf:b/1365158122476/Put/vlen=6/ts=0}

row: keyvalues={row3/cf:c/1365158122478/Put/vlen=6/ts=0}




Posted by '김용환'

댓글을 달아 주세요