hbase和hive:
hbase: 随机访问和实时读写,数据库,不支持分析
hive:基于MR的离线计算,数据仓库,支持分析
安装hbase:
1、tar -zxvf hbase-1.2.6-bin.tar.gz -C /soft/
2、ln -s hbase-1.2.6 hbase
3、sudo nano /etc/profile,添加一下内容
# hbase环境变量
export HBASE_HOME=/soft/hbase
export PATH=$PATH:$HBASE_HOME/bin
4、source /etc/profile
5、测试安装是否成功:hbase version
配置hbase的本地模式:
1、nano /soft/hbase/conf/hbase-env.sh,添加以下内容:
export JAVA_HOME=/soft/jdk
2、nano /soft/hbase/conf/hbase-site.xml,添加以下内容:
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///home/centos/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/centos/hbase/zk</value>
</property>
</configuration>
3、mkdir -p /home/centos/hbase/zk
4、start-hbase.sh ====== 启动hbase
配置hbase的完全分布模式:
1、nano /soft/hbase/conf/hbase-env.sh,添加以下内容:
export HBASE_MANAGES_ZK=false
2、nano /soft/hbase/conf/hbase-site.xml,添加以下内容:
<configuration>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.rootdir</name>
<value>hdfs://mycluster/user/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/centos/zookeeper</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>s102:2181,s103:2181,s104:2181</value>
</property>
</configuration>
3、将hdfs配置文件拷贝到hbase/conf下
cp /soft/hadoop/etc/hadoop/hdfs-site.xml /soft/hbase/conf/
cp /soft/hadoop/etc/hadoop/core-site.xml /soft/hbase/conf/
4、nano /soft/hbase/conf/regionservers,将内容修改为:
s102
s103
s104
5、将hbase分发到其他节点
xsync.sh /soft/hbase
xsync.sh /soft/hbase-1.2.6
6、使用root用户分发环境变量,然后退出root用户
xsync.sh /etc/profile
7、在s102-s104生效环境变量
8、依次启动zookeeper,hdfs,hbase
xzk.sh start
start-all.sh
start-hbase.sh
9、进入hbase命令行:hbase shell
hbase和sql的语句差异:
hbase | sql | |
---|---|---|
数据库 | namespace | database |
表 | table | table |
建库 | create_namespace 'ns1' | create database ns1; |
列出库 | list_namespace | show databases; |
建表 | create 'test:t1','f1','f2' | create table t1(id int, ......); |
列出指定库下的表 | list_namespace_tables 'ns1' | 先use ns1;后show tables; |
删表 | 先disable 't1' 后drop 't1' | drop table t1; |
插入数据 | put 'ns1:t1','row1','f1:name','tom' | insert into xxx values xxx; |
删除数据 | delete 'ns1:t1','row1','f1:name' | delete from ......; |
查询数据 | scan 'test:t1' | select * from xxx; |