This guide describes the setup of a standalone HBase instance running against the local filesystem. This is not an appropriate configuration for a production instance of HBase, but will allow you to experiment with HBase. This section shows you how to create a table in HBase using the hbase shell
CLI, insert rows into the table, perform put and scan operations against the table, enable or disable the table, and start and stop HBase. Apart from downloading HBase, this procedure should take less than 10 minutes.
Local Filesystem and Durability The following is fixed in HBase 0.98.3 and beyond. See HBASE-11272 and HBASE-11218. |
Using HBase with a local filesystem does not guarantee durability. The HDFS local filesystem implementation will lose edits if files are not properly closed. This is very likely to happen when you are experimenting with new software, starting and stopping the daemons often and not always cleanly. You need to run HBase on HDFS to ensure all writes are preserved. Running against the local filesystem is intended as a shortcut to get you familiar with how the general system works, as the very first phase of evaluation. See HBASE-3696 and its associated issues for more details about the issues of running on the local filesystem.
Loopback IP - HBase 0.94.x and earlier The below advice is for hbase-0.94.x and older versions only. This is fixed in hbase-0.96.0 and beyond. |
Prior to HBase 0.94.x, HBase expected the loopback IP address to be 127.0.0.1. Ubuntu and some other distributions default to 127.0.1.1 and this will cause problems for you. See Why does HBase care about /etc/hosts? for detail
The following /etc/hosts file works correctly for HBase 0.94.x and earlier, on Ubuntu. Use this as a template if you run into trouble.
127.0.0.1 localhost 127.0.0.1 ubuntu.ubuntu-domain ubuntu
2.1. JDK Version Requirements
HBase requires that a JDK be installed. See Java for information about supported JDK versions.
2.2. Get Started with HBase
Choose a download site from this list of Apache Download Mirrors. Click on the suggested top link. This will take you to a mirror of HBase Releases. Click on the folder named stable and then download the binary file that ends in .tar.gz to your local filesystem. Prior to 1.x version, be sure to choose the version that corresponds with the version of Hadoop you are likely to use later (in most cases, you should choose the file for Hadoop 2, which will be called something like hbase-0.98.13-hadoop2-bin.tar.gz). Do not download the file ending in src.tar.gzfor now.
Extract the downloaded file, and change to the newly-created directory.
$ tar xzvf hbase-<?eval ${project.version}?>-bin.tar.gz $ cd hbase-<?eval ${project.version}?>/
For HBase 0.98.5 and later, you are required to set the
JAVA_HOME
environment variable before starting HBase. Prior to 0.98.5, HBase attempted to detect the location of Java if the variables was not set. You can set the variable via your operating system’s usual mechanism, but HBase provides a central mechanism, conf/hbase-env.sh. Edit this file, uncomment the line starting withJAVA_HOME
, and set it to the appropriate location for your operating system. TheJAVA_HOME
variable should be set to a directory which contains the executable filebin/java. Most modern Linux operating systems provide a mechanism, such as /usr/bin/alternatives on RHEL or CentOS, for transparently switching between versions of executables such as Java. In this case, you can setJAVA_HOME
to the directory containing the symbolic link to bin/java, which is usually /usr.JAVA_HOME=/usr
These instructions assume that each node of your cluster uses the same configuration. If this is not the case, you may need to set JAVA_HOME
separately for each node.Edit conf/hbase-site.xml, which is the main HBase configuration file. At this time, you only need to specify the directory on the local filesystem where HBase and ZooKeeper write data. By default, a new directory is created under /tmp. Many servers are configured to delete the contents of /tmp upon reboot, so you should store the data elsewhere. The following configuration will store HBase’s data in the hbase directory, in the home directory of the user called
testuser
. Paste the<property>
tags beneath the<configuration>
tags, which should be empty in a new HBase install.Example 2. Example hbase-site.xml for Standalone HBase<configuration> <property> <name>hbase.rootdir</name> <value>file:///home/testuser/hbase</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/home/testuser/zookeeper</value> </property> </configuration>
You do not need to create the HBase data directory. HBase will do this for you. If you create the directory, HBase will attempt to do a migration, which is not what you want.
The bin/start-hbase.sh script is provided as a convenient way to start HBase. Issue the command, and if all goes well, a message is logged to standard output showing that HBase started successfully. You can use the
jps
command to verify that you have one running process calledHMaster
. In standalone mode HBase runs all daemons within this single JVM, i.e. the HMaster, a single HRegionServer, and the ZooKeeper daemon.Java needs to be installed and available. If you get an error indicating that Java is not installed, but it is on your system, perhaps in a non-standard location, edit the conf/hbase-env.sh file and modify the JAVA_HOME
setting to point to the directory that contains bin/javayour system.
Connect to HBase.
Connect to your running instance of HBase using the
hbase shell
command, located in the bin/ directory of your HBase install. In this example, some usage and version information that is printed when you start HBase Shell has been omitted. The HBase Shell prompt ends with a>
character.$ ./bin/hbase shell hbase(main):001:0>
Display HBase Shell Help Text.
Type
help
and press Enter, to display some basic usage information for HBase Shell, as well as several example commands. Notice that table names, rows, columns all must be enclosed in quote characters.Create a table.
Use the
create
command to create a new table. You must specify the table name and the ColumnFamily name.hbase(main):001:0> create 'test', 'cf' 0 row(s) in 0.4170 seconds => Hbase::Table - test
List Information About your Table
Use the
list
command tohbase(main):002:0> list 'test' TABLE test 1 row(s) in 0.0180 seconds => ["test"]
Put data into your table.
To put data into your table, use the
put
command.hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1' 0 row(s) in 0.0850 seconds hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2' 0 row(s) in 0.0110 seconds hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3' 0 row(s) in 0.0100 seconds
Here, we insert three values, one at a time. The first insert is at
row1
, columncf:a
, with a value ofvalue1
. Columns in HBase are comprised of a column family prefix,cf
in this example, followed by a colon and then a column qualifier suffix,a
in this case.Scan the table for all data at once.
One of the ways to get data from HBase is to scan. Use the
scan
command to scan the table for data. You can limit your scan, but for now, all data is fetched.hbase(main):006:0> scan 'test' ROW COLUMN+CELL row1 column=cf:a, timestamp=1421762485768, value=value1 row2 column=cf:b, timestamp=1421762491785, value=value2 row3 column=cf:c, timestamp=1421762496210, value=value3 3 row(s) in 0.0230 seconds
Get a single row of data.
To get a single row of data at a time, use the
get
command.hbase(main):007:0> get 'test', 'row1' COLUMN CELL cf:a timestamp=1421762485768, value=value1 1 row(s) in 0.0350 seconds
Disable a table.
If you want to delete a table or change its settings, as well as in some other situations, you need to disable the table first, using the
disable
command. You can re-enable it using theenable
command.hbase(main):008:0> disable 'test' 0 row(s) in 1.1820 seconds hbase(main):009:0> enable 'test' 0 row(s) in 0.1770 seconds
Disable the table again if you tested the
enable
command above:hbase(main):010:0> disable 'test' 0 row(s) in 1.1820 seconds
Drop the table.
To drop (delete) a table, use the
drop
command.hbase(main):011:0> drop 'test' 0 row(s) in 0.1370 seconds
Exit the HBase Shell.
To exit the HBase Shell and disconnect from your cluster, use the
quit
command. HBase is still running in the background.
In the same way that the bin/start-hbase.sh script is provided to conveniently start all HBase daemons, thebin/stop-hbase.sh script stops them.
$ ./bin/stop-hbase.sh stopping hbase.................... $
After issuing the command, it can take several minutes for the processes to shut down. Use the
jps
to be sure that the HMaster and HRegionServer processes are shut down.