Mac安装Apache HBase-1.3.5

Mac安装Apache HBase-1.3.5教程

HBase安装

1
$ brew install hbase

安装在/usr/local/Cellar/hbase/1.3.5

HBase配置

hbase-env.sh

conf/hbase-env.sh设置JAVA_HOME

1
2
3
4
$ cd /usr/local/Cellar/hbase/1.3.5/libexec/conf
$ vim hbase-env.sh

export JAVA_HOME="$(/usr/libexec/java_home --version 1.8)"

Apache HBase-1.3.5中JAVA_HOME已经默认被配置好了
如果JAVA_HOME没有配置好,则需要设置JAVA_HOME,可以通过下面的命令查看JAVA_HOME

1
2
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home

hbase-site.xml

conf/hbase-site.xml设置HBase的核心配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ vim hbase-site.xml

<configuration>
<property>
<name>hbase.rootdir</name>
// 这里设置让HBase存储文件的地方
<value>file:///usr/local/Cellar/hbase/tmp/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
// 这里设置让HBase存储内建zookeeper文件的地方
<value>/usr/local/Cellar/hbase/tmp/zookeeper</value>
</property>
</configuration>

启动HBase

/usr/local/Cellar/hbase/1.3.5/bin/start-hbase.sh提供HBase的启动

1
2
$ ./start-hbase.sh
starting master, logging to /usr/local/var/log/hbase/hbase-xxx-master-xxx.local.out

验证是否安装成功

1
2
3
4
5
$ jps
722 Launcher
1142 HMaster
726 Launcher
1256 Jps

启动HBase Shell

1
2
3
4
5
6
7
$ ./hbase shell
2019-10-19 11:58:34,879 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.3.5, rb59afe7b1dc650ff3a86034477b563734e8799a9, Wed Jun 5 15:57:14 PDT 2019

hbase(main):001:0>

停止HBase运行

1
2
$ ./stop-hbase.sh
stopping hbase...............

伪分布式模式

必须先关闭HBase

修改hbase-env.sh

1
HBASE_MANAGE_ZK = true

修改hbase-site.xml

设置HBase使用分布式模式运行

1
2
3
4
5
6
7
8
9
10
11
<configuration>
<property>
<name>hbase.rootdir</name>
// Here you have to set the path where you want HBase to store its files.
<value>hdfs://localhost:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
</configuration>

hbase.rootdir路径一定要跟hadoop中core-site.xml中fs.default.name相同

change the hbase.rootdir from the local filesystem to the address of your HDFS instance —offical quick start

如何两处设置不同会引起ERROR: Can’t get master address from ZooKeeper; znode data == null错误错误

在启动HBase之前, 请先启动Hadoop, 使之运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ ./start-hbase.sh
localhost: starting zookeeper, logging to /usr/local/var/log/hbase/hbase-xxx-zookeeper-xxx.local.out
starting master, logging to /usr/local/var/log/hbase/hbase-xxx-master-xxx.local.out
starting regionserver, logging to /usr/local/var/log/hbase/hbase-xxx-1-regionserver-xxx.local.out

$ jps #验证是否启动成功, 包含HMaster和HRegionServer说明启动成功
5614 HRegionServer
2222 NameNode
722 Launcher
2323 DataNode
5461 HMaster
726 Launcher
2650 ResourceManager
2747 NodeManager
2459 SecondaryNameNode
5405 HQuorumPeer
285
5726 Jps

查看hdfs中文件夹

1
2
3
4
5
6
$ ./hdfs dfs -ls /
2019-10-19 12:39:03,895 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Found 3 items
drwxr-xr-x - xxx supergroup 0 2019-10-19 12:38 /hbase
drwxrwxr-x - xxx supergroup 0 2019-10-17 14:41 /tmp
drwxr-xr-x - xxx supergroup 0 2019-10-17 11:44 /user

HBase Shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ hbase shell  #启动HBase Shell

# 创建表
> create 'student', 'description', 'course' #创建表名为student的表, 指明两个列名, 分别为description和course

# 信息明细
> list 'student' #列出list表信息

# 插入数据
# 意思为在student表row1处插入description:age的数据为18
# rowKey为row1,columnFamilyName为description,columnName为age
> put 'student', 'row1', 'description:age', '18'
> put 'student', 'row1', 'description:name', 'liu'
> put 'student', 'row1', 'course:chinese', '100'

# 一次扫描所有数据
> scan 'student'

# 使表失效 / 有效
> disable 'student'
> enable 'student'

# 删除表(要先disable)
> drop 'student'

# 退出shell
> quit