本文共 3274 字,大约阅读时间需要 10 分钟。
搭建好开发环境是HBase项目的第一步。以下是我们为您准备的详细环境配置方案。
在我们的HBase项目中,需要一个分布式的Hadoop集群。我们推荐以下组件版本:
为避免HBase配置过于复杂,我们选择使用单机版Zookeeper进行_tests。以下是Zookeeper配置注意事项:
tickTime=2000initLimit=10syncLimit=5dataDir=/opt/module/zk/dataclientPort=2181
codingce
,并赋予必要的权限。./zkServer.sh start
./zkServer.sh status
./zkServer.sh stop
./zkServer.sh restart
./zkCli.sh -server 127.0.0.1:2181
确保在开发环境中设置正确的环境变量:
export JAVA_HOME=/usr/java/jdk1.8.0_221export HADOOP_HOME=/opt/module/hadoop-3.1.1export ZOOKEEPER_HOME=/opt/module/zookeeper-3.5.6export PATH:$PATH:$HADOOP_HOME/bin:$ZOOKEEPER_HOME/bin:$JAVA_HOME/bin
hbase.rootdir hdfs://hadoop102:8020/hbase hbase.cluster.distributed true hbase.unsafe.stream.capability.enforce false hbase.master.port 16000 hbase.zookeeper.quorum 127.0.0.1:2181 hbase.zookeeper.property.dataDir /opt/module/zk/data
为了简化HBase操作,我们将HBase配置文件软链接到Hadoop配置目录:
ln -s /opt/module/hadoop-3.1.1/etc/hadoop/core-site.xml /opt/module/hbase-2.2.7/conf/core-site.xmlln -s /opt/module/hadoop-3.1.1/etc/hadoop/hdfs-site.xml /opt/module/hbase-2.2.7/conf/hdfs-site.xml
bin/start-hbase.sh
以下是我们推荐使用的项目依赖管理方式:
org.apache.hbase hbase-client 1.4.2 org.apache.hbase hbase-server 1.4.2 org.apache.hadoop hadoop-client 3.1.1 junit junit 4.13.1 org.slf4j slf4j-log4j12 1.7.30
我们为您提供了一组通用的业务操作代码:
public class TestApi_2 { public static void main(String[] args) throws IOException { dropTable("codingce:student"); createTable("user", "info"); getAllRows("codingce:student"); } // 条件详见下方方法注释}
细节操作请参考以下方法:
public static void addRowData(String tableName, String rowKey, String columnFamily, String column, String value) throws IOException { // 代码逻辑详细见上述类中addRowData方法}
public static void getAllRows(String tableName) throws IOException { // 代码逻辑详细见上述类中getAllRows方法}
public static void createTable(String tableName, String... columnFamily) throws IOException { // 代码逻辑详细见上述类中createTable方法}
public static void dropTable(String tableName) throws IOException { // 代码逻辑详细见上述类中dropTable方法}
目前项目处于迁移中,已更改至Gitee平台。如需获取更多代码和文档,请访问:
安装过程中遇到各类问题,以下是解决方法:
zkServer.sh
脚本可执行权限正确。如有其他问题,请随时在社区留言或访问我们的官方文档进行查阅。
转载地址:http://dipgz.baihongyu.com/