博客
关于我
HBase环境搭建与使用
阅读量:762 次
发布时间:2019-03-21

本文共 3274 字,大约阅读时间需要 10 分钟。

Hadoop环境搭建与HBase配置指南

环境搭建

搭建好开发环境是HBase项目的第一步。以下是我们为您准备的详细环境配置方案。

Hadoop集群

在我们的HBase项目中,需要一个分布式的Hadoop集群。我们推荐以下组件版本:

  • Hadoop版本:3.1.1
    • Hadoop集群数:2-3台节点
    • Hadoop应用:Hadoop Yarn及支持的服务(如Hdfs、Hdfs.High Accuracy、Hdfsfuse)

Zookeeper单机

为避免HBase配置过于复杂,我们选择使用单机版Zookeeper进行_tests。以下是Zookeeper配置注意事项:

  • Zookeeper版本:3.5.6
    • 下载地址:从Apache官方镜像站点下载,确保使用与HBase兼容的版本。
  • 配置文件
    tickTime=2000initLimit=10syncLimit=5dataDir=/opt/module/zk/dataclientPort=2181
  • 用户管理:在操作系统中创建专用用户codingce,并赋予必要的权限。

启动与管理Zookeeper

  • 启动Zookeeper
    ./zkServer.sh start
  • 查看状态
    ./zkServer.sh status
  • 停止Zookeeper
    ./zkServer.sh stop
  • 重启Zookeeper
    ./zkServer.sh restart
  • 连接测试
    ./zkCli.sh -server 127.0.0.1:2181

Hbase配置

1. 环境变量

确保在开发环境中设置正确的环境变量:

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

2. Hbase配置文件(hbase-site.xml)

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

3. 创建逻辑连接

为了简化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

4. 启动Hbase

bin/start-hbase.sh

Java操作

Maven项目配置

以下是我们推荐使用的项目依赖管理方式:

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平台。如需获取更多代码和文档,请访问:

    今天碰到的坑

    安装过程中遇到各类问题,以下是解决方法:

    • Zookeeper安装失败:请确保zkServer.sh脚本可执行权限正确。
    • HBase连接问题:请确保Zookeeper服务已经启动,并且客户端能够连接到正确的端口。
    • 权限问题:操作时请切换至正确的用户账号进行操作,确保权限配置合理。

    如有其他问题,请随时在社区留言或访问我们的官方文档进行查阅。

    转载地址:http://dipgz.baihongyu.com/

    你可能感兴趣的文章
    mysql复制表结构和数据
    查看>>
    mysql复杂查询,优质题目
    查看>>
    MySQL外键约束
    查看>>
    MySQL多表关联on和where速度对比实测谁更快
    查看>>
    MySQL多表左右连接查询
    查看>>
    mysql大批量删除(修改)The total number of locks exceeds the lock table size 错误的解决办法
    查看>>
    mysql如何做到存在就更新不存就插入_MySQL 索引及优化实战(二)
    查看>>
    mysql如何删除数据表,被关联的数据表如何删除呢
    查看>>
    MySQL如何实现ACID ?
    查看>>
    mysql如何记录数据库响应时间
    查看>>
    MySQL子查询
    查看>>
    Mysql字段、索引操作
    查看>>
    mysql字段的细节(查询自定义的字段[意义-行列转置];UNION ALL;case-when)
    查看>>
    mysql字段类型不一致导致的索引失效
    查看>>
    mysql字段类型介绍
    查看>>
    mysql字段解析逗号分割_MySQL逗号分割字段的行列转换技巧
    查看>>
    MySQL字符集与排序规则
    查看>>
    MySQL字符集乱码
    查看>>
    mysql存储IP地址的数据类型
    查看>>
    mysql存储中文 但是读取乱码_mysql存储中文乱码
    查看>>