HBase Shell 명령어
DDL 작업: 테이블 관리
네임스페이스 생성 및 테이블 조회:
create_namespace 'example_ns'
list_namespace
테이블 생성 및 구조 확인:
create 'example_ns:sample_table', 'cf1', 'cf2'
describe 'example_ns:sample_table'
테이블 수정 및 컬럼 패밀리 삭제:
alter 'example_ns:sample_table', {NAME => 'cf1', VERSIONS => 3}
alter 'example_ns:sample_table', NAME => 'cf2', METHOD => 'delete'
테이블 삭제 절차:
disable 'example_ns:sample_table'
drop 'example_ns:sample_table'
DML 작업: 데이터 조작
데이터 입력 및 조회:
put 'example_ns:data_table', 'row1', 'info:name', 'userA'
get 'example_ns:data_table', 'row1'
scan 'example_ns:data_table'
데이터 삭제:
delete 'example_ns:data_table', 'row1', 'info:name'
deleteall 'example_ns:data_table', 'row1', 'info:email'
HBase Java API 연결
의존성 설정 (pom.xml)
<dependencies>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>3.0.0-beta-1</version>
</dependency>
</dependencies>
연결 관리 클래스
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
public class HBaseConnector {
private static Connection hbaseLink = null;
static {
try {
hbaseLink = ConnectionFactory.createConnection();
} catch (IOException e) {
throw new RuntimeException("HBase 연결 실패", e);
}
}
public static Connection getConnection() {
return hbaseLink;
}
public static void closeConnection() throws IOException {
if (hbaseLink != null) hbaseLink.close();
}
}
리소스 설정 (hbase-site.xml)
<configuration>
<property>
<name>hbase.zookeeper.quorum</name>
<value>server1,server2,server3</value>
</property>
</configuration>
클러스터 관리 스크립트
시작 스크립트 (cluster-start.sh)
#!/bin/bash
start-all.sh
zkServer.sh start
# 원격 서버 제어
for node in server2 server3; do
ssh $node "zkServer.sh start"
done
nohup hive --service metastore &
nohup hive --service hiveserver2 &
start-hbase.sh
종료 스크립트 (cluster-stop.sh)
#!/bin/bash
stop-all.sh
zkServer.sh stop
for node in server2 server3; do
ssh $node "zkServer.sh stop"
done
hbase-daemon.sh stop master
hbase-daemon.sh stop regionserver