博客
关于我
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/

    你可能感兴趣的文章
    npm切换到淘宝源
    查看>>
    npm前端包管理工具简介---npm工作笔记001
    查看>>
    npm升级以及使用淘宝npm镜像
    查看>>
    npm发布自己的组件UI包(详细步骤,图文并茂)
    查看>>
    npm和yarn清理缓存命令
    查看>>
    npm和yarn的使用对比
    查看>>
    npm学习(十一)之package-lock.json
    查看>>
    npm安装crypto-js 如何安装crypto-js, python爬虫安装加解密插件 找不到模块crypto-js python报错解决丢失crypto-js模块
    查看>>
    npm报错Failed at the node-sass@4.14.1 postinstall script
    查看>>
    npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
    查看>>
    npm的常用配置项---npm工作笔记004
    查看>>
    npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
    查看>>
    npm编译报错You may need an additional loader to handle the result of these loaders
    查看>>
    npm配置安装最新淘宝镜像,旧镜像会errror
    查看>>
    npm错误 gyp错误 vs版本不对 msvs_version不兼容
    查看>>
    npm错误Error: Cannot find module ‘postcss-loader‘
    查看>>
    NPOI之Excel——合并单元格、设置样式、输入公式
    查看>>
    NPOI利用多任务模式分批写入多个Excel
    查看>>
    NPOI在Excel中插入图片
    查看>>
    NPOI格式设置
    查看>>