HBase 2.3.2 集群部署

HBase 2.3.2 集群部署

  • 依赖服务
  • 系统优化
  • 查看 ZooKeeper 集群状态
  • 查看 HDFS 集群状态
  • 创建路径
  • 配置 /etc/profile
  • 配置 $HBASE_HOME/conf/hbase-env.sh
  • 配置 $HBASE_HOME/conf/hbase-site.xml
  • 创建 $HBASE_HOME/conf/backup-masters
  • 配置 $HBASE_HOME/conf/regionservers
  • 存放 hdfs-site.xml
  • 分发配置
  • 启动 HBase 集群
  • 验证 HBase 集群状态

依赖服务

  • JDK 1.8.0_333
  • ZooKeeper 3.5.10:https://blog.csdn.net/weixin_42598916/article/details/135726572?spm=1001.2014.3001.5502
  • Hadoop 3.1.1:https://blog.csdn.net/weixin_42598916/article/details/135726131

系统优化

  • 每个节点都需进行如下优化
# 按需求更改主机名
hostname hadoop1

# 关闭 SELinux
# 将 SELINUX 值更改为 disabled
vi /etc/selinux/config
SELINUX=disabled

# 需要重启后才可生效
# 查看 SELinux 状态
getenforce

# 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld && systemctl status firewalld

# 安装 Chrony 服务
yum install chrony -y

# 配置 Chrony 服务
# 注释默认的 NTP 服务地址
# 配置所需的 NTP 服务地址
vi /etc/chonry.conf
server hadoop1 iburst

# 重启 Chrony 服务并配置开机自启
systemctl enable chronyd --now

# 查看 Chrony 服务状态
chronyc sources -v
210 Number of sources = 1
.-- Source mode  '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |       
MS Name/IP address         Stratum Poll Reach LastRx Last sample
====================================================================================================================
^* hadoop1                        4   6   377    12    -28us[  -45us] +/-   75ms

# 配置免密登录
# 所有节点生成 id_rsa.pub
ssh-keygen -t rsa

# 将每个节点的 id_rsa.pub 信息,分别放入所有节点的 authorized_keys 文件内
cat id_rsa.pub >> hadoop1:/root/.ssh/authorized_keys
cat id_rsa.pub >> hadoop2:/root/.ssh/authorized_keys
cat id_rsa.pub >> hadoop3:/root/.ssh/authorized_keys

# 最终效果
cat /root/.ssh/authorized_keys
# redis-nodes
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDwuKw9LdfDO3Ln+ViNtQEqZtH/RvoFymKkexBXRUK/2XcczKHPv967KHH71L/5vPOQPUXZLZg3TPERlRTIW9MvCh0LmceGAiQHrxczx56RnYh8nESknd2jbHBToGwqgoB8xsB2IQuhze0CqvRs7A0nrbyBvnUpg/DvePTOSSgii4z9kishBCbrCPamQm20drXVDK3gQ9Q+/YJLKa3+mxzI67xfk/jby0A0DD9XKL7fflRgMK0GXEtYsJ04tKc5Bo+w6Zc8gHyryFrKD4wpeoPakqmrdzaTVYI1x5WvrAPrQplxAP8iNfBqRJSHvlDBXVeXgSxz2I4HBshsStkKp root@redis1
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDkspWeTwWoWyr6biMnefOYT4kh+7gPAboHAWe7p67IR9pfu+Rkk/vxLFDbi7X6Td9AhIXEZH6fY5BhihBzhRO/VtjE24QqnXdOLDHV1i0rSEYh6GOAbnVl/93lKidQF/2wvnQET31m1iwls3ul6aWw8/pOcxWy6kB+6MRiOExhu+0erE3jBFLcl+e0IJLKp/nLjCof/qWh3hLGVyhgMn/WmGhf7OyUbedXFqAwwS83/M60jSL1nB1lnIOoHrNSdnrN/GJVXmmwJjJAG4g4hbAg2zNind2rz6p4mq5k7iBbDUFghFwKKYsGeV0Onm7SKErFlHCJNFSOgfVNpaUYJ root@redis2
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+DGKAYw3tbdmv2GDsz3HEOdoKk8JVCEvDFczap2g3DoaqwEBkRag2l9IQ3RZL/WtpKe0f2vZzcm5t3d7e6YhyfEXRn1fjOmynTcykB13xA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C1XxhFlc44X8zdf3mL8gbepG+ndMgBV4eombLg7QjZshCsjhk9d8esofAlrPk5tX/nWWHg3p5jYTh5/6V+iU7VDpWmMVN/87dsjBbmM9P6jTNiwqk4rdSXDKXkmrVygGHnEj95eP35Nq1JKg+GS7RjWWB0+loGQ4eYKO1nj2nYNOlNBi28CKh1uMWf42bDtcfKP3Z4gEOtPBD5rVPiU2Tq6jgtAs/VvaYGv5FHO4MB0lBE1ik8zp/4trfGU5hie/1PzCRAIvsqPEBSzeUs9nhHODj6vZYwgQupK9Qv5jEbQgh6pCGEfFZlfsC03 root@hadoop3

# 配置 OracleJDK
# 下载 Oracle JDK 并存放至指定路径内
# 配置 /etc/profile 文件
cat > /etc/profile << EOF

# Oracle JDK 1.8.0_333
export JAVA_HOME=/data/service/jdk/jdk1.8.0_333
export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin
EOF

# 刷新配置
source /etc/profile

# 查看 JDK 状态
java -version
java version "1.8.0_333"
Java(TM) SE Runtime Environment (build 1.8.0_333-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.333-b02, mixed mode)

# 配置 HOSTS 文件
cat > /etc/hosts << EOF
# redis-nodes
10.10.10.21 redis1
10.10.10.22 redis2
10.10.10.23 redis3

# hadoop-nodes
10.10.10.131 hadoop1
10.10.10.132 hadoop2
10.10.10.133 hadoop3
EOF

# 关闭 swap
swapoff -a

# 注销 swap 分区挂载
vi /etc/fstab

# 配置 vm.swapiness
echo "vm.swappiness = 0" >> /etc/sysctl.conf

# 刷新配置
sysctl -p

# 配置 transparent_hugepage
# 临时生效
echo never > /sys/kernel/mm/transparent_hugepage/enabled && echo never > /sys/kernel/mm/transparent_hugepage/defrag

# 永久生效
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local && echo "echo never > /sys/kernel/mm/transparent_hugepage/defrag" >> /etc/rc.local

# 配置 最大连接数
# CentOS6 的文件名为 90-nproc.conf
# CentOS7 的文件名为 20-nproc.conf
vi /etc/security/limits.d/20-nproc.conf
* - nofile 655350
* - nproc 655350

查看 ZooKeeper 集群状态

$ZK_HOME/bin/zkCli.sh -server hadoop1:2181,hadoop2:2181,hadoop3:2181
[zk: hadoop1:2181,hadoop2:2181,hadoop3:2181(CONNECTED) 0] ls /
[admin, brokers, cluster, config, consumers, controller, controller_epoch, hadoop-ha, hbase, isr_change_notification, latest_producer_id_block, log_dir_event_notification, rmstore, spark, yarn-leader-election, zookeeper]

查看 HDFS 集群状态

hdfs dfs -ls hdfs://hdfs-test/

创建路径

mkdir -p /data/service/hbase/{hbase_logs,hbase_tmp}

配置 /etc/profile

# HBase 2.3.2
export HBASE_HOME=/data/service/hbase/hbase-2.3.2
export PATH=$HBASE_HOME/bin:$PATH

配置 $HBASE_HOME/conf/hbase-env.sh

export JAVA_HOME=/data/service/jdk/jdk1.8.0_333
export HADOOP_HOME=/data/service/hadoop/hadoop-3.1.1
export HBASE_LOG_DIR=/data/service/hbase/hbase_logs

# HBase 1.2.3 后,HBase 默认使用自带 ZK
# 由于已部署独立 ZK,所以直接关闭
export HBASE_MANAGES_ZK=false
export HBASE_MASTER_OPTS="$HBASE_MASTER_OPTS -Xms2048m -Xmx2048m"
export HBASE_REGIONSERVER_OPTS="$HBASE_MASTER_OPTS -Xms2048m -Xmx2048m"
export HBASE_THRIFT_OPTS="$HBASE_MASTER_OPTS -Xms2048m -Xmx2048m"

配置 $HBASE_HOME/conf/hbase-site.xml

<configuration>
  <property>
    <name>hbase.rootdirname>
    <value>hdfs://hdfscluster/hbasevalue>
    <description>指定 HBase 数据存放路径。须与 hdfs-site.xml 的 fs.defaultFS 一致description>
  property>
  <property>
    <name>hbase.cluster.distributedname>
    <value>truevalue>
    <description>开启分布式部署模式description>
  property>
  <property>
    <name>hbase.tmp.dirname>
    <value>/data/service/hbase/hbase_tmpvalue>
    <description>指定临时文件路径description>
  property>
  <property>
    <name>hbase.zookeeper.quorumname>
    <value>hadoop1,hadoop2,hadoop3value>
    <description>指定 ZooKeeper 地址。不指定,则默认使用 HBase 自带 ZooKeeperdescription>
  property>
  <property>
    <name>hbase.zookeeper.property.clientPortname>
    <value>2181value>
    <description>指定 ZooKeeper 连接端口号,须与 Zoo.cfg 中相同description>
  property>
  <property>
    <name>zookeeper.znode.parentname>
    <value>/hbasevalue>
    <description>指定 ZooKeeper 中的存放路径description>
  property>
  <property>
    <name>hbase.unsafe.stream.capability.enforcename>
    <value>falsevalue>
    <description>关闭 HBase 流功能检测description>
  property>

  <property>
    <name>hbase.security.authorizationname>
    <value>truevalue>
  property>
  <property>
    <name>hbase.coprocessor.master.classesname> 
    <value>org.apache.hadoop.hbase.security.access.AccessControllervalue> 
  property>
  <property>
    <name>hbase.coprocessor.regionserver.classesname>
    <value>org.apache.hadoop.hbase.security.access.AccessController,org.apache.hadoop.hbase.security.token.TokenProvidervalue>
  property>
  <property>
    <name>hbase.coprocessor.region.classesname>
    <value>org.apache.hadoop.hbase.security.token.TokenProvider,org.apache.hadoop.hbase.security.access.AccessControllervalue>
  property>

  <property>
    <name>hbase.regionserver.handler.countname>
    <value>20value>
    <description>RegionServer 的 RPC 请求的线程数量。默认为 30。建议为 CPU 内核数的倍数description>
  property>
  <property>
    <name>hbase.hregion.majorcompactionname>
    <value>0value>
    <description>Region 主要合并间隔时间。单位为毫秒,默认为 604800000,即 7 天description>
  property>
  <property>
    <name>hbase.hregion.memstore.flush.sizename>
    <value>134217728value>
    <description>Memstore 大小超过该值后,将被写入 HFile 中。单位为 byte,默认为 134217728,即 128 MB。若 JVM 充足,可调整至 256 MBdescription>
  property>
  <property>
    <name>hbase.hregion.memstore.block.multipliername>
    <value>4value>
    <description>当 Memstore 使用总量超过 hbase.hregion.memstore.flush.size * hbase.hregion.memstore.block.multiplier,则会阻塞写入 Memstore,并将 Memstore 写入 HFile。单位为 byte,默认为 4。若 JVM 充足,可适当调整,但不建议调整过大,过大可能会导致 OOMdescription>
  property>
  <property>
    <name>hfile.block.cache.sizename>
    <value>0.4value>
    <description>block cache 的内存大小限制。单位为 byte,默认为百分比。若业务场景偏向于读,可适当增加该值。但 hbase.regionserver.global.memstore.upperLimit + hfile.block.cache.size 必须小于 0.8description>
  property>
configuration>

创建 $HBASE_HOME/conf/backup-masters

hadoop2

配置 $HBASE_HOME/conf/regionservers

hadoop1
hadoop2
hadoop3

存放 hdfs-site.xml

  • 若不刷新 HBase 内的 hdfs-site.xml,则会使用默认的 hdfs-site.xml 配置。将会导致无法连接到已部署的 HDFS 上。
cp /data/service/hadoop/hadoop-3.1.1/etc/hadoop/hdfs-site.xml /data/service/hbase/hbase-2.3.2/conf

分发配置

  • 将 /data/service/hbase 分发至所有节点

启动 HBase 集群

  • HMaster-Master
$HBASE_HOME/bin/start-hbase.sh

验证 HBase 集群状态

  • HBase Web UI:10.10.10.131:16010
  • 命令行查看
# 进入 HBase Shell
hbase shell

# 查看 HBase 状态
hbase(main):001:0> status
1 active master, 1 backup masters, 3 servers, 0 dead, 0.6667 average load
hbase(main):001:0> create 'hbase_test', {NAME=>'a1'}, {NAME=>'a2'}
hbase(main):001:0> put'hbase_test', '001','a1:name','Tom'
hbase(main):001:0> put'hbase_test', '001','a1:gender','man'
hbase(main):001:0> put'hbase_test', '001','a2:chinese','90'
hbase(main):001:0> put'hbase_test', '001','a2:math','91'

hbase(main):001:0> scan 'hbase_test'
ROW COLUMN+CELL 
001 column=a1:gender, timestamp=2022-11-17T12:53:04.335, value=man 
001 column=a1:name, timestamp=2022-11-17T12:52:57.417, value=Tom 
001 column=a2:chinese, timestamp=2022-11-17T12:53:10.322, value=90 
001 column=a2:math, timestamp=2022-11-17T12:53:16.966, value=91 
hbase(main):001:0>

hbase(main):001:0> get 'hbase_test','001'
COLUMN CELL 
a1:gender timestamp=2022-11-17T12:53:04.335, value=man 
a1:name timestamp=2022-11-17T12:52:57.417, value=Tom 
a2:chinese timestamp=2022-11-17T12:53:10.322, value=90 
a2:math timestamp=2022-11-17T12:53:16.966, value=91

你可能感兴趣的:(HBase,hbase,数据库,大数据)