发布时间: 2021-04-08 15:57:15
1.安装zookeeper集群
1.1下载与安装zookeeper
wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz -P /usr/local/src/
tar zxvf zookeeper-3.4.8.tar.gz -C /opt
cd /opt && mv zookeeper-3.4.8 zookeeper
cd zookeeper
cp conf/zoo_sample.cfg conf/zoo.cfg
[hd@master zookeeper]# pwd
/home/hd/apps/zookeeper
1.2 配置文件
[hd@master zookeeper]# vi conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/home/hd/apps/zookeeper/logs
dataDir=/home/hd/apps/zookeeper/data
clientPort=2181
#(主机名, 心跳端口、数据端口)
server.1= 192.168.1.148:2888:3888
server.2= 192.168.1.149:2888:3888
server.3= 192.168.1.150:2888:3888
#环境变量
[hd@master zookeeper]# sudo vi /etc/profile
export ZOOKEEPER_HOME=/home/hd/apps/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
[hd@master zookeeper]# source /etc/profile
#第一台机
[hd@master zookeeper]# echo 1 > data/myid
[hd@master zookeeper]# cat data/myid
1
#第二台机
[hd@master zookeeper]# echo 2 > data/myid
[hd@master zookeeper]# cat data/myid
2
#第三台机
[hd@master zookeeper]# echo 3 > data/myid
[hd@master zookeeper]# cat data/myid
3
zkServer.sh start2
zkServer.sh status
#第一台机
[hd@master zookeeper]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/hd/apps/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hd@master zookeeper]#
[hd@master zookeeper]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/hd/apps/zookeeper/bin/../conf/zoo.cfg
Mode: follower
#第二台机
[hd@slave01 ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/hd/apps/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hd@slave01 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/hd/apps/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[hd@slave01 ~]#
#第三台机
[hd@slave02 ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/hd/apps/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hd@slave02 ~]#
[hd@slave02 ~]#
[hd@slave02 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/hd/apps/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[hd@slave02 ~]#
wget http://mirror.bit.edu.cn/apache/hbase/1.3.1/hbase-1.3.1-bin.tar.gz
#解压
tar -xzvf hbase-1.3.1-bin.tar.gz -C /usr/local/
#重命名
mv hbase-1.3.1 hbase
[hd@master apps]# tar -zxvf hbase-1.4.0-bin.tar.gz
[hd@master apps]# mv hbase-1.4.0 hbase
[hd@master apps]# cd hbase
[hd@master hbase]# pwd
/home/hd/apps/hbase
配置环境变量
vim /etc/profile
#内容
export HBASE_HOME=/home/hd/apps/hbase
export PATH=$HBASE_HOME/bin:$PATH
#使立即生效
source /etc/profile
hbase 相关的配置主要包括hbase-env.sh、hbase-site.xml、regionservers三个文件,都在 /usr/local/hbase/conf目录下面:
2.1.1配置hbase-env.sh
#内容
export JAVA_HOME=/home/hd/apps/java
export HBASE_CLASSPATH=/home/hd/apps/hbase/conf
#此配置信息,设置由hbase自己管理zookeeper,不需要单独的zookeeper。
export HBASE_MANAGES_ZK=true
export HBASE_HOME=/home/hd/apps/hbase
export HADOOP_HOME=/home/hd/apps/hadoop
#Hbase日志目录
export HBASE_LOG_DIR=/home/hd/apps/hbase/logs
2.1.2配置 hbase-site.xml
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://master:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.master</name>
<value>master:60000</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>master,slave01,slave02</value>
</property>
</configuration>
2.1.3配置regionservers
[hd@master hbase]# vi conf/regionservers
slave01
slave02
2.2复制hbase到从节点中
[hd@master hbase]# scp -r /home/hd/apps/hbase hd@slave01:/home/hd/apps/
[hd@master hbase]# scp -r /home/hd/apps/hbase hd@slave02:/home/hd/apps/
1.启动顺序: hadoop-> zookeeper-> hbase
2.停止顺序:hbase-> zookeeper-> hadoop
2.3重启hbase
~/hbase/bin/stop-hbase.sh
~/hadoop/sbin/stop-all.sh
~/hadoop/sbin/start-all.sh
~/hbase/bin/start-hbase.sh
此表有两个列族,CF1和CF2,其中CF1和CF2下分别有两个列name和gender,Chinese和Math
3.2创建表
hbase_1102有两个列族CF1和CF2
hbase(main):041:0> create 'hbase_1102', {NAME=>'cf1'}, {NAME=>'cf2'}
3.3向表中添加数据
向表中添加数据,在想HBase的表中添加数据的时候,只能一列一列的添加,不能同时添加多列。
hbase(main):042:0> put'hbase_1102', '001','cf1:name','Tom'
hbase(main):043:0> put'hbase_1102', '001','cf1:gender','man'
hbase(main):044:0> put'hbase_1102', '001','cf2:chinese','90'
hbase(main):045:0> put'hbase_1102', '001','cf2:math','91'
这样表结构就起来了,其实比较自由,列族里边可以自由添加子列很方便。如果列族下没有子列,加不加冒号都是可以的。
如果在添加数据的时候,需要手动的设置时间戳,则在put命令的最后加上相应的时间戳,时间戳是long类型的,所以不需要加引号
3.4查看表中的所有数据
hbase(main):046:0> scan 'hbase_1102'
ROW COLUMN+CELL
001 column=cf1:gender, timestamp=1478053832459, value=man
001 column=cf1:name, timestamp=1478053787178, value=Tom
001 column=cf2:chinese, timestamp=1478053848225, value=90001 column=cf2:math, timestamp=1478053858144, value=911 row(s) in0.0140seconds
hbase(main):048:0> get'hbase_1102','001'
COLUMN CELL
cf1:gender timestamp=1478053832459, value=man
cf1:name timestamp=1478053787178, value=Tom
cf2:chinese timestamp=1478053848225, value=90
cf2:math timestamp=1478053858144, value=914 row(s) in0.0290seconds
上一篇: Mpls VPN专题之MPLS单域实验篇
下一篇: 一篇看懂Linux根文件系统类型