安装HBase
环境准备
首先应完成完全分布式安装Hadoop
并配置免密登录、上传Zookeeper、HBase安装包至master节点
配置Zookeeper
解压Zookeeper安装包
tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz -C /opt
在解压目录创建data和log目录
cd /opt/apache-zookeeper-3.8.0-bin
mkdir data log
编辑配置文件:复制conf目录下的样例文件,并修改dataDir(数据文件目录)和dataLogDir(日志文件目录)
cd conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
=>
dataDir=/opt/apache-zookeeper-3.8.0-bin/data
dataLogDir=/opt/apache-zookeeper-3.8.0-bin/log
在data目录中新建myid文件,向里面写入1。这里的1表示是集群的第几台机器,slave节点则这里为2,3,4…
cd ../data/
echo 1 >> myid
再次编辑zoo.cfg,添加主节点和从节点地址
cd /opt/apache-zookeeper-3.8.0-bin/conf/
vi zoo.cfg
=> # 底部添加
server.1=master:2888:3888
server.2=slave1:2888:3888
接着将Zookeeper安装文件分发到子节点
scp -r /opt/apache-zookeeper-3.8.0-bin/ slave1:/opt/
修改子节点上的myid
cd /opt/apache-zookeeper-3.8.0-bin/data/
echo 2 > myid
# echo 3 > myid
cat myid
启动Zookeeper
启动前需关闭防火墙,以及在master上启动Hadoop
systemctl stop firewalld.service
systemctl disable firewalld.service
cd /opt/hadoop/sbin/
./start-all.sh
在所有节点上执行:
bash /opt/apache-zookeeper-3.8.0-bin/bin/zkServer.sh start
查看启动状态
bash /opt/apache-zookeeper-3.8.0-bin/bin/zkServer.sh status
HBase环境
解压HBase安装包
tar -zxvf hbase-2.1.0-bin.tar.gz -C /opt
mv /opt/hbase-2.1.0 /opt/hbase
配置Java路径: 1. 找到java和Hadoop路径 2. 填写配置
# 找到JavaHome和HadoopHome
echo $JAVA_HOME
# /opt/jdk8u282-b08
echo $HADOOP_HOME
# /opt/hadoop
# 填写配置
cd /opt/hbase/conf/
vi hbase-env.sh
=> # 修改JAVA_HOME和添加HADOOP_HOME及HBASE_MANAGES_ZK
export JAVA_HOME=/opt/jdk8u282-b08
export HADOOP_HOME=/opt/hadoop
export HBASE_MANAGES_ZK=false
配置regionservers,用于处理数据
vi /opt/hbase/conf/regionservers
=>
slave1
创建HBase的临时目录
cd /opt/hbase/
mkdir tmp
配置HBase
复制htrace-core
cp lib/client-facing-thirdparty/htrace-core-3.1.0-incubating.jar /opt/hbase/lib/
配置hbase-site.xml
vi /opt/hbase/conf/hbase-site.xml
编辑configuration标签为:
<configuration>
<property>
<name>hbase.regionserver.handler.count</name>
<value>1000</value>
</property>
<property>
<name>hbase.client.write.buffer</name>
<value>5242880</value>
</property>
<property>
<name>hbase.rootdir</name>
<value>hdfs://master:9000/hbase</value>
</property>
<property>
<name>zookeeper.session.timeout</name>
<value>120000</value>
</property>
<property>
<name>hbase.zookeeper.property.tickTime</name>
<value>6000</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/opt/apache-zookeeper-3.8.0-bin</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>master,slave1</value>
</property>
<property>
<name>hbase.tmp.dir</name>
<value>/opt/hbase/tmp</value>
</property>
<property>
<name>hbase.wal.provider</name>
<value>filesystem</value>
</property>
<property>
<name>hbase.wal.dir</name>
<value>hdfs://master:9000/hbase</value>
</property>
<property>
<name>hbase.client.write.buffer</name>
<value>2097152</value>
</property>
<property>
<name>hbase.regionserver.handler.count</name>
<value>200</value>
</property>
<property>
<name>hbase.hstore.compaction.min</name>
<value>6</value>
</property>
<property>
<name>hbase.hregion.memstore.block.multiplier</name>
<value>16</value>
</property>
<property>
<name>hfile.block.cache.size</name>
<value>0.2</value>
</property>
<property>
<name>hbase.master</name>
<value>master:60000</value>
<description>HMaster</description>
</property>
<property>
<name>hbase.unsafe.stream.capability.enforce</name>
<value>false</value>
</property>
<property>
<name>hbase.master.distributed.log.splitting</name>
<value>false</value>
</property>
</configuration>
将Hadoop的core-site.xml复制到HBase的conf目录下
cp $HADOOP_HOME/etc/hadoop/core-site.xml /opt/hbase/conf/
将配置完成的HBase安装文件分发到所有子节点
scp -r /opt/hbase/ slave1:/opt/
在所有节点里添加环境变量
vi /etc/profile
=> # 末尾添加
export HBASE_HOME=/opt/hbase
export PATH=${HBASE_HOME}/bin:$PATH
<= # :wq
source /etc/profile
启动HBase
在master上执行
bash /opt/hbase/bin/start-hbase.sh
注意:当提示:
master running as process 1472. Stop it first.
slave1: regionserver running as process 1607. Stop it first.
slave2: regionserver running as process 870. Stop it first.
需要去对应的主机kill掉对应的进程
kill 1472 # at master
kill 1607 # at slave1
kill 870 # at slave2
在浏览器中打开master:16010,如可以正常显示则安装成功
如果显示Master is initializing
,可能是因为主机间时间差异过大,需校正时间
yum install ntpdate
ntpdate time.nist.gov
测试HBase
首先master进入hbase shell
cd /opt/hbase/bin/
./hbase shell
列出所有表:list
list
创建命名空间,类似创建数据库
create_namespace 'test'
建表:create ‘表名’,‘列簇名’,‘列簇名’,‘列簇名’
create 'table_name', 'col1', 'col2'
添加数据:第一个为表名,第二个为Row Key,第三个为列族名:属性名,第四个为属性的value值:
put 'table_name', '001', 'col1:name', 'tiansuohaoer'
put 'table_name', '001', 'col1:age', '24'
显示表结构
desc 'table_name'
获取数据
get 'table_name', '001', 'col1:name'
get 'table_name', '001', 'col1:age'
查看所有数据
scan 'table_name'
删除表:
drop 'table_name'