转载:http://blog.fens.me/linux-hbase-install/
1 在Ubuntu中环境准备
系统环境:
- Linux Ubuntu 14.04.2 LTS 64bit server
- Java 1.7.0_75
- Hadoop 1.2.1
HBase安装
2.1 下载HBase
下载地址:http://mirror.tcpdiag.net/apache/hbase/ # 解压HBase tar xvf hbase-0.94.18.tar.gz # 移动HBase目录到文件夹 mv hbase-0.94.18/ /home/liujianfei/hadoop/ cp -rf hbase-0.94.18/ /home/liujianfei/hadoop/hbase-0.94.18 # 进入目录 cd /home/liujianfei/hadoop/hbase-0.94.18
2.2 配置HBase
2.2.1 修改启动文件hbase-env.sh
创建目录:
mkdir /home/liujianfei/hadoop/hdata vim conf/hbase-env.sh #打开注释 export JAVA_HOME=/home/conan/toolkit/jdk16 export HBASE_CLASSPATH=/home/conan/hadoop/hadoop-1.1.2/conf export HBASE_MANAGES_ZK=true
2.2.2 修改配置文件 hbase-site.xml
~ vi conf/hbase-site.xml <configuration> <property> <name>hbase.rootdir</name> <value>hdfs://localhost:9000/hbase</value> </property> <property> <name>hbase.cluster.distributed</name> <value>true</value> </property> <property> <name>dfs.replication</name> <value>1</value> </property> <property> <name>hbase.zookeeper.quorum</name> <value>localhost</value> </property> <property> <name>hbase.zookeeper.property.clientPort</name> <value>2181</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/home/liujianfei/hadoop/hdata</value> </property> </configuration>
2.3 启动hadoop和hbase
./home/liujianfei/hadoop/hadoop-1.2.1/bin/start-all.sh ./home/liujianfei/hadoop/hbase-0.94.18/bin/start-hbase.sh # 查看hbase进程 ~ jps
4647 JobTracker 4824 TaskTracker 4556 SecondaryNameNode 7589 HQuorumPeer 4356 DataNode 7660 HMaster 8248 Main 9007 Jps 3859 org.eclipse.equinox.launcher_1.3.0.dist.jar 4076 NameNode 7797 HRegionServer 2.4 打开HBase命令行客户端访问Hbase 进入 cd /home/liujianfei/hadoop/hbase-0.94.18/bin ./hbase shell2.5 HBase简单命令操作
#创建一个新表student hbase(main):003:0> create 'student','info' 0 row(s) in 1.2680 seconds #查看所有的表 hbase(main):004:0> list TABLE student 1 row(s) in 0.0330 seconds #查看student的表结构 hbase(main):005:0> describe 'student' DESCRIPTION ENABLED 'student', {NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', true BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL = > '2147483647', KEEP_DELETED_CELLS => 'false', BLOCKSIZE = > '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => 'true'} 1 row(s) in 0.1100 seconds #同student表中插入一条数据 hbase(main):007:0> put 'student','mary','info:age','19' 0 row(s) in 0.0490 seconds #从student表中取出mary的数据 hbase(main):008:0> get 'student','mary' COLUMN CELL info:age timestamp=1396366643298, value=19 1 row(s) in 0.0190 seconds #让student表失效 hbase(main):009:0> disable 'student' 0 row(s) in 1.2400 seconds #列出所有表 hbase(main):010:0> list TABLE student 1 row(s) in 0.0310 seconds #删除student表 hbase(main):013:0> drop 'student' 0 row(s) in 1.1100 seconds #列出所有表 hbase(main):014:0> list TABLE 0 row(s) in 0.0400 seconds