1. 程式人生 > 其它 >【Hbase】1.3.1版本安裝

【Hbase】1.3.1版本安裝

環境:

1核4G記憶體128G磁碟,三臺機器同一個配置

192.168.242.131
192.168.242.132
192.168.242.133

—— Linux Centos7 x64 系統平臺

—— JDK,基於Java開發的元件的執行環境

—— Hadoop, Hbase資料的儲存層依賴HDFS

—— Zookeeper,監控協調

其他各種依賴:

sudo yum install -y net-tools
sudo yum install -y vim
sudo yum install -y wget
sudo yum install -y lrzsz
sudo yum install
-y pcre pcre-devel sudo yum install -y zlib zlib-devel sudo yum install -y openssl openssl-devel sudo yum install -y unzip sudo yum install -y libtool sudo yum install -y gcc-c++ sudo yum install -y telnet sudo yum install -y tree sudo yum install -y nano sudo yum install -y psmisc sudo yum install
-y rsync sudo yum install -y ntp

JDK版本直接採用yum安裝

sudo yum install -y java-1.8.0-openjdk-devel.x86_64 

Zookeeper版本沒有限制,任意就行,安裝參考:

https://www.cnblogs.com/mindzone/p/15468883.html

Hadoop 3版本和2版本部署有差異,這裡單獨再寫2版本Hadoop的叢集部署

Hbase版本要和Hadoop匹配,這是一個部署坑

Hbase 1.3.1 匹配 Hadoop 2.7.2 沒啥問題

Hadoop 2.7.2 安裝

1號機131下載壓縮包

wget https://archive.apache.org/dist/hadoop/common/hadoop-2.7.2/hadoop-2.7.2.tar.gz

解壓到指定目錄

mkdir -p /opt/module
tar -zxvf hadoop-2.7.2.tar.gz -C /opt/module/

配置Hadoop和JDK的環境變數

vim /etc/profile

在尾部追加變數資訊(其他機器也新增)

# HADOOP_HOME
export HADOOP_HOME=/opt/module/hadoop-2.7.2
export PATH=$PATH:$HADOOP_HOME/bin
export PATH=$PATH:$HADOOP_HOME/sbin

# JAVA_HOME 這裡看自己的具體jdk版本,不要直接cv , 用 find / -name java 查詢一下
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-1.el7_9.x86_64
export PATH=$PATH:$JAVA_HOME/bin

立即使變數生效:

source /etc/profile

然後測試變數設定是否有效

hadoop version

成功則會展示hadoop的資訊

[root@localhost ~]# hadoop version
Hadoop 2.7.2
Subversion https://git-wip-us.apache.org/repos/asf/hadoop.git -r b165c4fe8a74265c792ce23f546c64604acf0e41
Compiled by jenkins on 2016-01-26T00:08Z
Compiled with protoc 2.5.0
From source with checksum d0fda26633fa762bff87ec759ebe689c
This command was run using /opt/module/hadoop-2.7.2/share/hadoop/common/hadoop-common-2.7.2.jar

備份配置檔案:

# 配置檔案備份
cd /opt/module/hadoop-2.7.2/etc/hadoop/
cp -r core-site.xml core-site.xml.bak
cp -r hadoop-env.sh hadoop-env.sh.bak
cp -r hdfs-site.xml hdfs-site.xml.bak
cp -r mapred-env.sh mapred-env.sh.bak
cp -r mapred-site.xml mapred-site.xml.bak
cp -r yarn-env.sh yarn-env.sh.bak
cp -r yarn-site.xml yarn-site.xml.bak

core-site.xml

宣告主節點的地址

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed 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. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
<!-- 指定HDFS中NameNode的地址 -->
<property>
        <name>fs.defaultFS</name>
      <value>hdfs://192.168.242.131:9000</value>
</property>

<!-- 指定Hadoop執行時產生檔案的儲存目錄 -->
<property>
        <name>hadoop.tmp.dir</name>
        <value>/opt/module/hadoop-2.7.2/data/tmp</value>
</property>
</configuration>

hadoop-env.sh

只需要宣告一下JDK位置

# The java implementation to use.
# export JAVA_HOME=${JAVA_HOME}
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-1.el7_9.x86_64

hdfs-site.xml

定義副本數量和輔助節點地址

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed 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. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
        <name>dfs.replication</name>
        <value>3</value>
</property>

<!-- 指定Hadoop輔助名稱節點主機配置 -->
<property>
      <name>dfs.namenode.secondary.http-address</name>
      <value>192.168.242.133:50090</value>
</property>
</configuration>

mapred-env.sh

宣告JDK路徑

# export JAVA_HOME=/home/y/libexec/jdk1.6.0/
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-1.el7_9.x86_64

marpred-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed 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. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
<!-- 指定MR執行在Yarn上 -->
<property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
</property>
</configuration>

yarn-env.sh可以不改,指令碼直接獲取了$JAVA_HOME

yarn-site.xml

指定資源管理器地址

<?xml version="1.0"?>
<!--
  Licensed 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. See accompanying LICENSE file.
-->
<configuration>

<!-- Site specific YARN configuration properties -->
<!-- Reducer獲取資料的方式 -->
<property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
</property>

<!-- 指定YARN的ResourceManager的地址 -->
<property>
        <name>yarn.resourcemanager.hostname</name>
        <value>192.168.242.132</value>
</property>
</configuration>

配置叢集節點地址

vim /opt/module/hadoop-2.7.2/etc/hadoop/slaves

寫上所有機器地址,但是不要多空格空行

192.168.242.131
192.168.242.132
192.168.242.133

然後把Hadoop分發到剩餘的機器

# xsync指令碼
xsync /opt/module/hadoop-2.7.2

# 沒有xsync指令碼, 用scp拷貝
scp /opt/module/hadoop-2.7.2 root@192.168.242.132:/opt/module/
scp /opt/module/hadoop-2.7.2 root@192.168.242.133:/opt/module/

首次啟動需要對HDFS進行格式化操作

hdfs namenode -format

如果需要再次格式化,先清空data目錄的資料

rm -rf /opt/module/hadoop-2.7.2/data
hdfs namenode -format

叢集部署完成!

Hadoop叢集啟動:

# 1號機啟動 
$HADOOP_HOME/sbin/start-dfs.sh

# 2號機啟動
$HADOOP_HOME/sbin/start-yarn.sh

1號機執行資訊:

[root@192 ~]# $HADOOP_HOME/sbin/start-dfs.sh
Starting namenodes on [192.168.242.131]
192.168.242.131: starting namenode, logging to /opt/module/hadoop-2.7.2/logs/hadoop-root-namenode-192.168.242.131.out
192.168.242.131: starting datanode, logging to /opt/module/hadoop-2.7.2/logs/hadoop-root-datanode-192.168.242.131.out
192.168.242.133: starting datanode, logging to /opt/module/hadoop-2.7.2/logs/hadoop-root-datanode-192.168.242.133.out
192.168.242.132: starting datanode, logging to /opt/module/hadoop-2.7.2/logs/hadoop-root-datanode-192.168.242.132.out
Starting secondary namenodes [192.168.242.133]
192.168.242.133: starting secondarynamenode, logging to /opt/module/hadoop-2.7.2/logs/hadoop-root-secondarynamenode-192.168.242.133.out
[root@192 ~]#

2號機執行資訊:

[root@192 ~]# $HADOOP_HOME/sbin/start-yarn.sh
starting yarn daemons
starting resourcemanager, logging to /opt/module/hadoop-2.7.2/logs/yarn-root-resourcemanager-192.168.242.132.out
192.168.242.133: starting nodemanager, logging to /opt/module/hadoop-2.7.2/logs/yarn-root-nodemanager-192.168.242.133.out
192.168.242.131: starting nodemanager, logging to /opt/module/hadoop-2.7.2/logs/yarn-root-nodemanager-192.168.242.131.out
192.168.242.132: starting nodemanager, logging to /opt/module/hadoop-2.7.2/logs/yarn-root-nodemanager-192.168.242.132.out
[root@192 ~]#

Zookeeper保持執行狀態:

[root@192 ~]# zk-cluster status
---------- zookeeper 192.168.242.131 狀態 ------------
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/module/apache-zookeeper-3.7.0/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
---------- zookeeper 192.168.242.132 狀態 ------------
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/module/apache-zookeeper-3.7.0/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader
---------- zookeeper 192.168.242.133 狀態 ------------
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/module/apache-zookeeper-3.7.0/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@192 ~]#

Hbase叢集安裝:

1號機下載壓縮包:

wget https://dlcdn.apache.org/hbase/stable/hbase-2.4.9-bin.tar.gz

解包到指定目錄

tar -zxvf hbase-2.4.9-bin.tar.gz -C /opt/module/

備份配置檔案

cp -r /opt/module/hbase-2.4.9/conf/hbase-env.sh /opt/module/hbase-2.4.9/conf/hbase-env.sh.bak
cp -r /opt/module/hbase-2.4.9/conf/hbase-site.xml /opt/module/hbase-2.4.9/conf/hbase-site.xml.bak
cp -r /opt/module/hbase-2.4.9/conf/regionservers /opt/module/hbase-2.4.9/conf/regionservers.bak

hbase-env.sh

追加環境變數

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-1.el7_9.x86_64
export HBASE_MANAGES_ZK=false

hbase-site.xml

1、注意rootdir和hadoop的HDFS埠一致,(本文Ctrl + F查詢9000)

2、Zookeeper的datadir寫出自己設定的路徑,否則Hbase的shell執行時找不到zk

<property>
<name>hbase.rootdir</name>
<value>hdfs://192.168.242.131:9000/HBase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
 <!-- 0.98 後的新變動,之前版本沒有.port,預設埠為 60000 -->
<property>
<name>hbase.master.port</name>
<value>16000</value>
</property>
<property> 
<name>hbase.zookeeper.quorum</name>
 <value>192.168.242.131,192.168.242.132,192.168.242.133</value>
</property>
<property> 
<name>hbase.zookeeper.property.dataDir</name>
    <!-- 指定的zk目錄 -->
 <value>/opt/module/apache-zookeeper-3.7.0/zk-data</value>
</property>

regionservers

不要空格和空行

192.168.242.131
192.168.242.132
192.168.242.133

軟連結Hadoop的配置檔案

ln -s /opt/module/hadoop-3.3.1/etc/hadoop/core-site.xml /opt/module/hbase-2.4.9/conf/core-site.xml
ln -s /opt/module/hadoop-3.3.1/etc/hadoop/hdfs-site.xml /opt/module/hbase-2.4.9/conf/hdfs-site.xml

Hbase到這,1號機的裝完了,然後分發到剩下的機器中

# xsync指令碼
xsync /opt/module/hbase-1.3.1

# 沒有xsync指令碼, 用scp拷貝
scp /opt/module/hbase-1.3.1 root@192.168.242.132:/opt/module/
scp /opt/module/hbase-1.3.1 root@192.168.242.133:/opt/module/

伺服器時間同步處理:

這個問題在Hbase shell檢視status狀態時會報錯

錯誤描述:主節點未初始化異常,不影響使用,但是原因是因為叢集的時間不一致導致

參考:

https://blog.csdn.net/renzhewudi77/article/details/86301395

解決辦法是同步時間一致

以1號機作為時間統一標準,做時間伺服器

安裝ntp服務(不管沒有有都執行一次)

sudo yum install -y ntp

首先編輯1號機的ntp配置

vim /etc/ntp.conf

主要內容:

# 改成自己網段的,例如我的網段是242
# (授權192.168.1.0-192.168.1.255網段上的所有機器可以從這臺機器上查詢和同步時間)
# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap為
restrict 192.168.242.0 mask 255.255.255.0 nomodify notrap

#  註釋下面的資訊
(叢集在區域網中,不使用其他網際網路上的時間)
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
為這樣:
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst

# 備用本地時間提供同步
(當該節點丟失網路連線,依然可以採用本地時間作為時間伺服器為叢集中的其他節點提供時間同步)
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
server 127.127.1.0
fudge 127.127.1.0 stratum 10

系統ntp配置修改

vim /etc/sysconfig/ntpd

追加配置項:

# 增加內容
#(讓硬體時間與系統時間一起同步)
SYNC_HWCLOCK=yes

剩下是ntp的執行處理

# 檢視ntp狀態
service ntpd status

# 服務啟動
service ntpd start

# 開機自啟動
chkconfig ntpd on

其他機器只需要設定定時任務和時間伺服器進行同步即可

# 編寫定時任務(非1號機的機器執行,1號機作為時間伺服器)
crontab -e
# 任務編輯指令碼中寫: # (其他機器配置10分鐘與時間伺服器同步一次)
*/10 * * * * /usr/sbin/ntpdate 192.168.242.131

啟動與停止Hbase叢集

/opt/module/hbase-2.4.9/bin/start-hbase.sh
/opt/module/hbase-2.4.9/bin/stop-hbase.sh

啟動

[root@192 ~]# /opt/module/hbase-1.3.1/bin/start-hbase.sh
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
starting master, logging to /opt/module/hbase-1.3.1/bin/../logs/hbase-root-master-192.168.242.131.out
OpenJDK 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
192.168.242.133: starting regionserver, logging to /opt/module/hbase-1.3.1/bin/../logs/hbase-root-regionserver-192.168.242.133.out
192.168.242.132: starting regionserver, logging to /opt/module/hbase-1.3.1/bin/../logs/hbase-root-regionserver-192.168.242.132.out
192.168.242.131: starting regionserver, logging to /opt/module/hbase-1.3.1/bin/../logs/hbase-root-regionserver-192.168.242.131.out
192.168.242.133: OpenJDK 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
192.168.242.133: OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
192.168.242.133: OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
192.168.242.132: OpenJDK 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
192.168.242.132: OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
192.168.242.132: OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
192.168.242.131: OpenJDK 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
192.168.242.131: OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
192.168.242.131: OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
[root@192 ~]#

訪問Hbase的Shell檢查是否正常執行

# 訪問
/opt/module/hbase-2.4.9/bin/hbase shell

檢視狀態

status

輸出資訊:

hbase(main):002:0> status
1 active master, 0 backup masters, 3 servers, 1 dead, 1.0000 average load

訪問地址檢視:

http://192.168.242.131:16010