第9章 HBase操作

HBase集群建立在Hadoop集群基础之上,而且依赖于ZooKeeper,所以在搭建HBase集群之前需要把Hadoop集群搭建起来,并且搭建好ZooKeeper集群。Hadoop与ZooKeeper集群的搭建在前面章节已讲解过,在此不再赘述。

9.1 集群环境搭建

HBase集群搭建的详细步骤如下(也可以参考官网#quickstart):

1.上传解压HBase安装包

将hbase-1.2.4-bin.tar.gz上传到centos01服务器的/opt/softwares目录并将其解压到目录/opt/modules/,解压命令如下:

[hadoop@centos01 softwares]$ tar -zxf hbase-1.2.4-bin.tar.gz -C /opt/modules/ 2.hbase-env.sh文件配置

修改HBase安装目录/conf下的配置文件hbase-env.sh,配置关联的JDK,加入以下代码:

export JAVA_HOME=http://www.likecs.com/opt/modules/jdk1.8.0_101

如果需要使用HBase自带的ZooKeeper,则去掉该文件中的注释 # export HBASE_MANAGES_ZK=true即可。

3.hbase-site.xml文件配置

修改HBase安装目录/conf下的配置文件hbase-site.xml,加入以下代码:

<configuration> <property><!--需要与HDFS namenode端口一致--> <name>hbase.rootdir</name> <value>hdfs://centos01:9000/hbase</value> </property> <property> <name>hbase.cluster.distributed</name> <value>true</value> </property> <property><!--ZooKeeper节点列表 --> <name>hbase.zookeeper.quorum</name> <value>centos01,centos02,centos03</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/opt/modules/hbase-1.2.4/zkData</value> </property> </configuration>

上述参数解析如下:
hbase.rootdir:HBase的数据存储目录,由于HBase数据存储在HDFS上,所以要写HDFS的目录,注意端口要和Hadoop的fs.defaultFS端口一致。配置好后,HBase数据就会写入到这个目录中,且目录不需要手动创建,HBase启动的时候会自动创建。
hbase.cluster.distributed:设置为true代表开启完全分布式。
hbase.zookeeper.quorum:设置依赖的ZooKeeper节点,此处加入所有ZooKeeper集群即可。
hbase.zookeeper.property.dataDir:设置ZooKeeper的配置、日志等数据存放目录。
另外,还有一个属性hbase.tmp.dir,是设置HBase临时文件存放目录,不设置的话,默认存放在/tmp目录,该目录重启就会清空。

4.regionservers文件配置

regionservers文件列出了所有运行HBase的服务器,即HRegionServer。对该文件的配置与Hadoop中对slaves文件的配置相似,需要在文件中的每一行指定一台服务器,当HBase启动时会读取该文件,将文件中指定的所有服务器启动。当HBase停止的时候,也会同时停止它们。

本例中,我们将三个节点都作为运行HRegionServer的服务器,因此,我们需要作出如下修改:
修改HBase安装目录下的/conf/regionservers文件,去掉默认的localhost,加入如下内容:

centos01 centos02 centos03 5.拷贝hbase到其它节点。

centos01节点配置完成后,需要拷贝整个HBase安装目录文件到集群的其它节点,拷贝命令如下:

[hadoop@centos01 modules]$ scp -r hbase-1.2.4/ hadoop@centos02:/opt/modules/ [hadoop@centos01 modules]$ scp -r hbase-1.2.4/ hadoop@centos03:/opt/modules/ 6.启动与测试

启动HBase集群之前,需要先启动Hadoop集群:

sbin/start-all.sh

然后执行如下命令,启动HBase集群。启动HBase集群的同时,会将ZooKeeper集群也同时启动。

bin/start-hbase.sh

HBase启动日志如下:

[hadoop@centos01 hbase-1.2.4]$ bin/start-hbase.sh centos02: starting zookeeper, logging to /opt/modules/hbase-1.2.4/bin/../logs/hbase-hadoop-zookeeper-centos02.out centos03: starting zookeeper, logging to /opt/modules/hbase-1.2.4/bin/../logs/hbase-hadoop-zookeeper-centos03.out centos01: starting zookeeper, logging to /opt/modules/hbase-1.2.4/bin/../logs/hbase-hadoop-zookeeper-centos01.out starting master, logging to /opt/modules/hbase-1.2.4/bin/../logs/hbase-hadoop-master-centos01.out Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 centos03: starting regionserver, logging to /opt/modules/hbase-1.2.4/bin/../logs/hbase-hadoop-regionserver-centos03.out centos02: starting regionserver, logging to /opt/modules/hbase-1.2.4/bin/../logs/hbase-hadoop-regionserver-centos02.out centos01: starting regionserver, logging to /opt/modules/hbase-1.2.4/bin/../logs/hbase-hadoop-regionserver-centos01.out centos02: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 centos02: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 centos03: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 centos03: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 centos01: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 centos01: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyyfzf.html