在 CentOS 上实现 HBase 负载均衡
一 架构与原则
二 启用与配置内置负载均衡器
<configuration>
<!-- 集群基础 -->
<property>
<name>hbase.rootdir</name>
<value>hdfs://namenode:8020/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>zk1,zk2,zk3</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
<!-- 选择负载均衡器(默认即为 StochasticLoadBalancer,可显式配置) -->
<property>
<name>hbase.master.loadbalancer.class</name>
<value>org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer</value>
</property>
<!-- 可选:调整均衡器行为 -->
<property>
<name>hbase.master.loadbalancer.period</name>
<value>60000</value>
</property>
<property>
<name>hbase.master.loadbalancer.maxRegionMoves</name>
<value>10</value>
</property>
</configuration>
hbase-daemon.sh stop master
hbase-daemon.sh start master
三 运行与验证负载均衡
hbase shell
hbase> balance_switch true # 开启
hbase> balance_switch false # 关闭
hbase shell
hbase> balancer # 返回 true 表示已下发均衡任务
status 'simple'四 进阶优化与运维建议
0 * * * * /opt/hbase/bin/hbase shell -e "balance_switch true")。五 仅在需要外部访问时添加 HAProxy(可选)
sudo yum install -y haproxy
sudo tee /etc/haproxy/haproxy.cfg >/dev/null <<'EOF'
global
log /dev/log local0
log /dev/log local1 notice
daemon
defaults
log global
option tcplog
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend hbase_thrift_front
bind *:9090
default_backend hbase_thrift_back
backend hbase_thrift_back
balance roundrobin
server rs1 192.168.1.101:9090 check
server rs2 192.168.1.102:9090 check
server rs3 192.168.1.103:9090 check
EOF
sudo systemctl enable --now haproxy