HBase 伪分布式环境安装指南
目录
- 环境准备
- [安装 Java JDK](#安装 Java JDK)
- [配置 SSH 免密登录](#配置 SSH 免密登录)
- [安装 Hadoop](#安装 Hadoop)
- [安装和配置 HBase](#安装和配置 HBase)
- [启动和验证 HBase](#启动和验证 HBase)
- 常用操作命令
- 故障排查
一、环境准备
1.1 系统信息
bash
# 查看操作系统版本
lsb_release -a
输出:
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
1.2 现有工具检查
bash
# 检查已安装的工具
which python3 python node npm
输出:
/usr/bin/python3
/home/huohuo/.nvm/versions/node/v24.14.1/bin/node
/home/huohuo/.nvm/versions/node/v24.14.1/bin/npm
1.3 必要工具检查
bash
# 检查 Java(未安装)
java -version 2>&1 || echo "Java not installed"
# 检查 SSH
ssh -V 2>&1
# 检查下载工具
which wget curl
二、安装 Java JDK
2.1 更新软件包列表
bash
sudo apt update
2.2 安装 OpenJDK 8
bash
sudo apt install -y openjdk-8-jdk
安装输出:
正在读取软件包列表...
正在分析包的依赖关系树...
下列【新】软件包将被安装:
ca-certificates-java fonts-dejavu-extra java-common libatk-wrapper-java
libatk-wrapper-java-jni libice-dev libpthread-stubs0-dev libsm-dev
libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxt-dev openjdk-8-jdk
openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless x11proto-dev
xorg-sgml-doctools xtrans-dev
...
已下载 48.1 MB,耗时 12秒 (4,105 kB/s)
2.3 验证 Java 安装
bash
java -version
javac -version
输出:
openjdk version "1.8.0_482"
OpenJDK Runtime Environment (build 1.8.0_482-8u482-ga~us1-0ubuntu1~22.04-b08)
OpenJDK 64-Bit Server VM (build 25.482-b08, mixed mode)
javac 1.8.0_482
2.4 Java 安装路径
/usr/lib/jvm/java-8-openjdk-amd64
三、配置 SSH 免密登录
3.1 安装 OpenSSH Server
bash
# 检查 SSH 服务
ssh -V 2>&1
# 安装 OpenSSH Server(如果未安装)
sudo apt install -y openssh-server
3.2 生成 SSH 密钥对
bash
# 生成 RSA 密钥对(无密码)
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
输出:
Generating public/private rsa key pair.
Created directory '/home/huohuo/.ssh'.
Your identification has been saved in /home/huohuo/.ssh/id_rsa
Your public key has been saved in /home/huohuo/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:lspCyp/+BlrBrTqrWjI3IbAlWhDDapjS5BzRsaFkv+8 huohuo@huohuo-virtual-machine
3.3 配置免密登录
bash
# 将公钥添加到授权列表
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# 设置正确的权限
chmod 600 ~/.ssh/authorized_keys
# 测试免密登录
ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no localhost "echo 'SSH 免密登录配置成功'"
输出:
Warning: Permanently added 'localhost' (ED25519) to the list of known hosts.
SSH 免密登录配置成功
3.4 关键文件路径
| 文件 | 路径 | 说明 |
|---|---|---|
| 私钥 | ~/.ssh/id_rsa |
SSH 私钥文件 |
| 公钥 | ~/.ssh/id_rsa.pub |
SSH 公钥文件 |
| 授权密钥 | ~/.ssh/authorized_keys |
免密登录授权列表 |
四、安装 Hadoop
4.1 下载 Hadoop
bash
cd /home/huohuo
# 从清华大学镜像站下载 Hadoop 3.3.6
wget -q https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/hadoop-3.3.6/hadoop-3.3.6.tar.gz
# 解压
tar -xzf hadoop-3.3.6.tar.gz
# 删除压缩包
rm hadoop-3.3.6.tar.gz
4.2 Hadoop 目录结构
/home/huohuo/hadoop-3.3.6/
├── bin # 可执行脚本
├── etc # 配置文件
├── include # 头文件
├── lib # 库文件
├── libexec # 辅助脚本
├── LICENSE.txt # 许可证
├── NOTICE.txt # 通知文件
├── README.txt # 说明文件
├── sbin # 系统脚本
└── share # 共享资源
五、安装和配置 HBase
5.1 下载 HBase
bash
cd /home/huohuo
# 从华为云镜像站下载 HBase 2.5.8
wget --timeout=120 https://repo.huaweicloud.com/apache/hbase/2.5.8/hbase-2.5.8-bin.tar.gz
# 解压
tar -xzf hbase-2.5.8-bin.tar.gz
# 删除压缩包
rm hbase-2.5.8-bin.tar.gz
下载输出:
100%[======================================>] 322,479,779 11.9 MB/s in 26s
5.2 HBase 目录结构
/home/huohuo/hbase-2.5.8/
├── bin # 可执行脚本
├── CHANGES.md # 变更日志
├── conf # 配置文件目录
├── docs # 文档
├── hbase-webapps # Web 应用
├── lib # 库文件
├── LEGAL # 法律文件
├── LICENSE.txt # 许可证
├── NOTICE.txt # 通知文件
└── RELEASENOTES.md # 发布说明
5.3 配置环境变量
编辑 ~/.bashrc 文件,添加以下内容:
bash
# Java
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
# Hadoop
export HADOOP_HOME=/home/huohuo/hadoop-3.3.6
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
# HBase
export HBASE_HOME=/home/huohuo/hbase-2.5.8
# PATH
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HBASE_HOME/bin
使配置生效:
bash
source ~/.bashrc
5.4 配置 HBase 环境脚本
文件路径 : /home/huohuo/hbase-2.5.8/conf/hbase-env.sh
修改前:
bash
# The java implementation to use. Java 1.8+ required.
# export JAVA_HOME=/usr/java/jdk1.8.0/
修改后:
bash
# The java implementation to use. Java 1.8+ required.
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
5.5 配置 HBase 站点
文件路径 : /home/huohuo/hbase-2.5.8/conf/hbase-site.xml
完整配置内容:
xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<configuration>
<!--
伪分布式模式配置
使用本地文件系统存储数据,适合开发和测试
-->
<!-- 启用伪分布式模式 -->
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<!-- HBase 数据存储目录 -->
<property>
<name>hbase.rootdir</name>
<value>file:///home/huohuo/hbase-data</value>
</property>
<!-- 临时目录 -->
<property>
<name>hbase.tmp.dir</name>
<value>/home/huohuo/hbase-tmp</value>
</property>
<!-- ZooKeeper 配置 -->
<property>
<name>hbase.zookeeper.quorum</name>
<value>localhost</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/huohuo/zookeeper-data</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
<!-- HBase Master 配置 -->
<property>
<name>hbase.master</name>
<value>localhost:16000</value>
</property>
<!-- RegionServer 配置 -->
<property>
<name>hbase.regionserver.port</name>
<value>16020</value>
</property>
<property>
<name>hbase.regionserver.info.port</name>
<value>16030</value>
</property>
<!-- 安全相关(开发环境禁用) -->
<property>
<name>hbase.unsafe.stream.capability.enforce</name>
<value>false</value>
</property>
</configuration>
5.6 创建数据目录
bash
# 创建 HBase 数据目录
mkdir -p /home/huohuo/hbase-data
# 创建 HBase 临时目录
mkdir -p /home/huohuo/hbase-tmp
# 创建 ZooKeeper 数据目录
mkdir -p /home/huohuo/zookeeper-data
目录结构:
/home/huohuo/
├── hbase-data/ # HBase 数据存储
├── hbase-tmp/ # HBase 临时文件
└── zookeeper-data/ # ZooKeeper 数据
六、启动和验证 HBase
6.1 启动 HBase
bash
/home/huohuo/hbase-2.5.8/bin/start-hbase.sh
输出:
localhost: running zookeeper, logging to /home/huohuo/hbase-2.5.8/bin/../logs/hbase-huohuo-zookeeper-huohuo-virtual-machine.out
running master, logging to /home/huohuo/hbase-2.5.8/bin/../logs/hbase-huohuo-master-huohuo-virtual-machine.out
: running regionserver, logging to /home/huohuo/hbase-2.5.8/bin/../logs/hbase-huohuo-regionserver-huohuo-virtual-machine.out
6.2 检查运行状态
bash
jps
输出:
7280 HQuorumPeer # ZooKeeper 进程
7402 HMaster # HBase Master 进程
7549 HRegionServer # HBase RegionServer 进程
7910 Jps # Java 进程查看工具
6.3 进入 HBase Shell
bash
/home/huohuo/hbase-2.5.8/bin/hbase shell
输出:
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
Version 2.5.8, r37444de6531b1bdabf2e445c83d0268ab1a6f919, Thu Feb 29 15:37:32 PST 2024
Took 0.0025 seconds
hbase:001:0>
6.4 创建测试表
hbase
# 创建名为 'test' 的表,列族为 'cf'
create 'test', 'cf'
输出:
Created table test
Took 1.1550 seconds
=> Hbase::Table - test
6.5 插入测试数据
hbase
# 插入数据
put 'test', 'row1', 'cf:a', 'value1'
put 'test', 'row2', 'cf:b', 'value2'
输出:
Took 0.7751 seconds
Took 0.0078 seconds
6.6 扫描数据
hbase
# 扫描表数据
scan 'test'
输出:
ROW COLUMN+CELL
row1 column=cf:a, timestamp=2026-03-25T22:00:09.746, value=value1
row2 column=cf:b, timestamp=2026-03-25T22:00:09.785, value=value2
2 row(s)
Took 0.0591 seconds
6.7 退出 Shell
hbase
exit
6.8 验证 Web UI
HBase Master Web UI 地址:
http://localhost:16010
验证命令:
bash
curl -s http://localhost:16010/master-status | head -10
输出:
html
<!DOCTYPE html>
<?xml version="1.0" encoding="UTF-8" ?>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Master: huohuo-virtual-machine</title>
七、常用操作命令
7.1 启动和停止
bash
# 启动 HBase
/home/huohuo/hbase-2.5.8/bin/start-hbase.sh
# 停止 HBase
/home/huohuo/hbase-2.5.8/bin/stop-hbase.sh
7.2 HBase Shell 命令
bash
# 进入 HBase Shell
/home/huohuo/hbase-2.5.8/bin/hbase shell
常用 Shell 命令:
hbase
# 列出所有表
list
# 创建表
create '表名', '列族1', '列族2'
# 查看表结构
describe '表名'
# 插入/更新数据
put '表名', '行键', '列族:列', '值'
# 获取单行数据
get '表名', '行键'
# 扫描表数据
scan '表名'
# 删除数据
delete '表名', '行键', '列族:列'
# 删除表(先禁用再删除)
disable '表名'
drop '表名'
# 查看帮助
help
# 退出 Shell
exit
7.3 日志查看
bash
# 查看 HBase 日志
tail -f /home/huohuo/hbase-2.5.8/logs/*.out
# 查看 ZooKeeper 日志
tail -f /home/huohuo/hbase-2.5.8/logs/hbase-huohuo-zookeeper-*.out
# 查看 Master 日志
tail -f /home/huohuo/hbase-2.5.8/logs/hbase-huohuo-master-*.out
# 查看 RegionServer 日志
tail -f /home/huohuo/hbase-2.5.8/logs/hbase-huohuo-regionserver-*.out
7.4 端口检查
bash
# 检查 HBase 相关端口
netstat -tlnp | grep java
# 或
ss -tlnp | grep java
八、故障排查
8.1 Java 进程检查
bash
# 查看所有 Java 进程
jps -lm
# 查看 HBase 进程详情
ps aux | grep hbase
8.2 端口占用检查
bash
# 检查 16010 端口(Master Web UI)
sudo netstat -tlnp | grep 16010
# 检查 2181 端口(ZooKeeper)
sudo netstat -tlnp | grep 2181
8.3 数据目录权限
bash
# 确保目录权限正确
ls -la /home/huohuo/hbase-data
ls -la /home/huohuo/zookeeper-data
# 修复权限
chmod 755 /home/huohuo/hbase-data
chmod 755 /home/huohuo/zookeeper-data
8.4 清空数据重新启动
如果需要完全重置 HBase:
bash
# 1. 停止 HBase
/home/huohuo/hbase-2.5.8/bin/stop-hbase.sh
# 2. 删除数据目录
rm -rf /home/huohuo/hbase-data/*
rm -rf /home/huohuo/zookeeper-data/*
rm -rf /home/huohuo/hbase-tmp/*
# 3. 重新启动
/home/huohuo/hbase-2.5.8/bin/start-hbase.sh
8.5 常见问题
问题 1: SSH 免密登录失败
症状 : ssh localhost 要求输入密码
解决:
bash
# 重新配置免密登录
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
问题 2: HBase 启动后无法访问
症状 : jps 显示进程,但无法连接
解决:
bash
# 检查日志
tail -100 /home/huohuo/hbase-2.5.8/logs/hbase-huohuo-master-*.log
# 检查端口绑定
netstat -tlnp | grep 16000
问题 3: 时间不同步错误
症状: 日志中出现时钟偏移错误
解决:
bash
# 同步系统时间
sudo apt install -y ntpdate
sudo ntpdate ntp.aliyun.com
九、配置参数说明
9.1 hbase-site.xml 关键参数
| 参数名 | 值 | 说明 |
|---|---|---|
| hbase.cluster.distributed | true | 启用分布式模式 |
| hbase.rootdir | file:///home/huohuo/hbase-data | 数据存储路径 |
| hbase.tmp.dir | /home/huohuo/hbase-tmp | 临时目录 |
| hbase.zookeeper.quorum | localhost | ZooKeeper 地址 |
| hbase.zookeeper.property.dataDir | /home/huohuo/zookeeper-data | ZooKeeper 数据目录 |
| hbase.zookeeper.property.clientPort | 2181 | ZooKeeper 客户端端口 |
| hbase.master | localhost:16000 | Master 地址和端口 |
| hbase.regionserver.port | 16020 | RegionServer 端口 |
| hbase.regionserver.info.port | 16030 | RegionServer Web UI 端口 |
| hbase.unsafe.stream.capability.enforce | false | 禁用流能力检查(开发模式) |
9.2 端口列表
| 服务 | 端口 | 用途 |
|---|---|---|
| ZooKeeper | 2181 | 客户端连接 |
| HMaster | 16000 | RPC 服务 |
| HMaster | 16010 | Web UI |
| RegionServer | 16020 | RPC 服务 |
| RegionServer | 16030 | Web UI |
十、文件路径汇总
10.1 安装路径
| 组件 | 安装路径 |
|---|---|
| Java JDK | /usr/lib/jvm/java-8-openjdk-amd64 |
| Hadoop | /home/huohuo/hadoop-3.3.6 |
| HBase | /home/huohuo/hbase-2.5.8 |
10.2 数据路径
| 用途 | 路径 |
|---|---|
| HBase 数据 | /home/huohuo/hbase-data |
| HBase 临时文件 | /home/huohuo/hbase-tmp |
| ZooKeeper 数据 | /home/huohuo/zookeeper-data |
10.3 配置文件路径
| 配置文件 | 路径 |
|---|---|
| HBase 环境配置 | /home/huohuo/hbase-2.5.8/conf/hbase-env.sh |
| HBase 站点配置 | /home/huohuo/hbase-2.5.8/conf/hbase-site.xml |
| 系统环境变量 | ~/.bashrc |
| SSH 密钥 | ~/.ssh/id_rsa |
| SSH 公钥 | ~/.ssh/id_rsa.pub |
| SSH 授权密钥 | ~/.ssh/authorized_keys |
10.4 日志路径
| 日志类型 | 路径模式 |
|---|---|
| ZooKeeper | /home/huohuo/hbase-2.5.8/logs/hbase--zookeeper-.out |
| Master | /home/huohuo/hbase-2.5.8/logs/hbase--master-.out |
| RegionServer | /home/huohuo/hbase-2.5.8/logs/hbase--regionserver-.out |
十一、环境变量配置
11.1 ~/.bashrc 完整环境变量配置
bash
# NVM (Node Version Manager)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# Java
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
# Hadoop
export HADOOP_HOME=/home/huohuo/hadoop-3.3.6
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
# HBase
export HBASE_HOME=/home/huohuo/hbase-2.5.8
# PATH
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HBASE_HOME/bin
11.2 加载环境变量
bash
source ~/.bashrc
附录: 参考链接
end