小熊奶糖(BearCandy)
小熊奶糖(BearCandy)
发布于 2024-11-14 / 10 阅读
0
0

hadoop配置hbase和zookeeper

在Hadoop集群上配置HBase涉及多个步骤,包括安装依赖项、配置HBase环境变量、修改HBase配置文件以及启动HBase服务。以下是详细的步骤和需要修改的配置文件。

1. 安装依赖项

确保你已经安装了以下依赖项:

  • Java
  • Hadoop

安装Java和Hadoop

确保Java和Hadoop已经正确安装并配置好。你可以参考前面的Hadoop配置部分。

2. 下载和解压HBase

从Apache HBase官网下载HBase的二进制包,并解压到你选择的目录下。

wget https://downloads.apache.org/hbase/2.4.11/hbase-2.4.11-bin.tar.gz
tar -xzvf hbase-2.4.11-bin.tar.gz
mv hbase-2.4.11 /usr/local/hbase

3. 配置环境变量

编辑 ~/.bashrc~/.profile文件,添加HBase的环境变量:

export HBASE_HOME=/usr/local/hbase
export PATH=$PATH:$HBASE_HOME/bin

然后使环境变量生效:

source ~/.bashrc

4. 修改HBase配置文件

HBase的主要配置文件位于 $HBASE_HOME/conf/目录下。你需要根据你的环境来调整这些配置文件。

hbase-site.xml

这是HBase的主要配置文件。你需要配置HDFS路径、ZooKeeper地址等。以下是一个示例配置:

<configuration>
    <property>
        <name>hbase.rootdir</name>
        <value>hdfs://namenode:9000/hbase</value>
        <description>The directory shared by region servers.</description>
    </property>
    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
        <description>The mode the cluster will be in. Possible values are false: standalone and pseudo-distributed setups with managed ZooKeeper true: fully-distributed with unmanaged ZooKeeper Quorum (see hbase-env.sh)</description>
    </property>
    <property>
        <name>hbase.zookeeper.quorum</name>
        <value>zookeeper1,zookeeper2,zookeeper3</value>
        <description>Comma separated list of servers in the ZooKeeper Quorum. For example, "host1.mydomain.com,host2.mydomain.com,host3.mydomain.com". By default this is set to localhost for local and pseudo-distributed modes of operation. For a fully-distributed setup, this should be set to a full list of ZooKeeper quorum servers. If HBASE_MANAGES_ZK is set in hbase-env.sh this is the list of servers which we will start/stop ZooKeeper on.</description>
    </property>
    <property>
        <name>hbase.zookeeper.property.clientPort</name>
        <value>2181</value>
        <description>Property from ZooKeeper's config zoo.cfg. The port at which the clients will connect.</description>
    </property>
    <property>
        <name>hbase.regionserver.global.memstore.upperLimit</name>
        <value>0.4</value>
        <description>Fraction of total heap size, given to memstores in aggregate. When total size of all the memstores crosses this limit, flushing of some regions happens. Default is 0.4. This is a fraction of the heap, so 0.4 means 40% of the heap.</description>
    </property>
    <property>
        <name>hbase.regionserver.global.memstore.lowerLimit</name>
        <value>0.35</value>
        <description>Fraction of total heap size, given to memstores in aggregate. When total size of all the memstores crosses this limit, flushing of some regions happens. Default is 0.35. This is a fraction of the heap, so 0.35 means 35% of the heap.</description>
    </property>
</configuration>

hbase-env.sh

这个文件用于设置HBase的环境变量。如果你没有这个文件,可以从 hbase-env.sh.template复制并重命名。

cp $HBASE_HOME/conf/hbase-env.sh.template $HBASE_HOME/conf/hbase-env.sh

编辑 hbase-env.sh文件,添加以下内容:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export HBASE_MANAGES_ZK=false
export HBASE_PID_DIR=/var/hbase/pids
export HBASE_LOG_DIR=/var/log/hbase

5. 配置Hadoop

确保Hadoop的配置文件已经正确设置,特别是 core-site.xmlhdfs-site.xml。HBase需要能够访问HDFS。

core-site.xml

<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://namenode:8020</value>
    </property>
</configuration>

hdfs-site.xml

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

6. 配置ZooKeeper

HBase依赖于ZooKeeper来进行协调。确保ZooKeeper已经正确安装并配置好。

安装ZooKeeper

wget https://downloads.apache.org/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
tar -xzvf apache-zookeeper-3.7.0-bin.tar.gz
mv apache-zookeeper-3.7.0-bin /usr/local/zookeeper

配置ZooKeeper

编辑 $ZOOKEEPER_HOME/conf/zoo.cfg文件,添加以下内容:

tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=zookeeper1:2888:3888
server.2=zookeeper2:2888:3888
server.3=zookeeper3:2888:3888

在每个ZooKeeper节点上创建 myid文件,并写入对应的ID(1、2、3):

echo "1" > /var/zookeeper/myid

7. 启动ZooKeeper

在每个ZooKeeper节点上启动ZooKeeper服务:

$ZOOKEEPER_HOME/bin/zkServer.sh start

8. 启动HBase

在HBase主节点上启动HBase服务:

$HBASE_HOME/bin/start-hbase.sh

9. 验证安装

使用HBase shell验证安装是否成功:

$HBASE_HOME/bin/hbase shell

在HBase shell中运行以下命令:

create 'test', 'cf'
put 'test', 'row1', 'cf:a', 'value1'
scan 'test'

总结

以上步骤应该可以帮助你在Hadoop集群上成功安装和配置HBase。如果有任何特定的问题或错误信息,请提供详细信息,我可以进一步帮助你解决问题。


评论