4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
32 <<quickstart,Quickstart>> will get you up and running on a single-node, standalone instance of HBase.
35 == Quick Start - Standalone HBase
37 This section describes the setup of a single-node standalone HBase.
38 A _standalone_ instance has all HBase daemons -- the Master, RegionServers,
39 and ZooKeeper -- running in a single JVM persisting to the local filesystem.
40 It is our most basic deploy profile. We will show you how
41 to create a table in HBase using the `hbase shell` CLI,
42 insert rows into the table, perform put and scan operations against the
43 table, enable or disable the table, and start and stop HBase.
45 Apart from downloading HBase, this procedure should take less than 10 minutes.
47 === JDK Version Requirements
49 HBase requires that a JDK be installed.
50 See <<java,Java>> for information about supported JDK versions.
52 === Get Started with HBase
54 .Procedure: Download, Configure, and Start HBase in Standalone Mode
55 . Choose a download site from this list of link:https://www.apache.org/dyn/closer.lua/hbase/[Apache Download Mirrors].
56 Click on the suggested top link.
57 This will take you to a mirror of _HBase Releases_.
58 Click on the folder named _stable_ and then download the binary file that ends in _.tar.gz_ to your local filesystem.
59 Do not download the file ending in _src.tar.gz_ for now.
61 . Extract the downloaded file, and change to the newly-created directory.
63 [source,subs="attributes"]
66 $ tar xzvf hbase-{Version}-bin.tar.gz
70 . You must set the `JAVA_HOME` environment variable before starting HBase.
71 To make this easier, HBase lets you set it within the _conf/hbase-env.sh_ file. You must locate where Java is
72 installed on your machine, and one way to find this is by using the _whereis java_ command. Once you have the location,
73 edit the _conf/hbase-env.sh_ file and uncomment the line starting with _#export JAVA_HOME=_, and then set it to your Java installation path.
75 .Example extract from _hbase-env.sh_ where _JAVA_HOME_ is set
76 # Set environment variables here.
77 # The java implementation to use.
78 export JAVA_HOME=/usr/jdk64/jdk1.8.0_112
81 . Edit _conf/hbase-site.xml_, which is the main HBase configuration file.
82 At this time, you need to specify the directory on the local filesystem where HBase and ZooKeeper write data and acknowledge some risks.
83 By default, a new directory is created under /tmp.
84 Many servers are configured to delete the contents of _/tmp_ upon reboot, so you should store the data elsewhere.
85 The following configuration will store HBase's data in the _hbase_ directory, in the home directory of the user called `testuser`.
86 Paste the `<property>` tags beneath the `<configuration>` tags, which should be empty in a new HBase install.
88 .Example _hbase-site.xml_ for Standalone HBase
95 <name>hbase.rootdir</name>
96 <value>file:///home/testuser/hbase</value>
99 <name>hbase.zookeeper.property.dataDir</name>
100 <value>/home/testuser/zookeeper</value>
103 <name>hbase.unsafe.stream.capability.enforce</name>
106 Controls whether HBase will check for stream capabilities (hflush/hsync).
108 Disable this if you intend to run on LocalFileSystem, denoted by a rootdir
109 with the 'file://' scheme, but be mindful of the NOTE below.
111 WARNING: Setting this to false blinds you to potential data loss and
112 inconsistent system state in the event of process and/or node failures. If
113 HBase is complaining of an inability to use hsync or hflush it's most
114 likely not a false positive.
121 You do not need to create the HBase data directory.
122 HBase will do this for you. If you create the directory,
123 HBase will attempt to do a migration, which is not what you want.
125 NOTE: The _hbase.rootdir_ in the above example points to a directory
126 in the _local filesystem_. The 'file://' prefix is how we denote local
127 filesystem. You should take the WARNING present in the configuration example
128 to heart. In standalone mode HBase makes use of the local filesystem abstraction
129 from the Apache Hadoop project. That abstraction doesn't provide the durability
130 promises that HBase needs to operate safely. This is fine for local development
131 and testing use cases where the cost of cluster failure is well contained. It is
132 not appropriate for production deployments; eventually you will lose data.
134 To home HBase on an existing instance of HDFS, set the _hbase.rootdir_ to point at a
135 directory up on your instance: e.g. _hdfs://namenode.example.org:8020/hbase_.
136 For more on this variant, see the section below on Standalone HBase over HDFS.
138 . The _bin/start-hbase.sh_ script is provided as a convenient way to start HBase.
139 Issue the command, and if all goes well, a message is logged to standard output showing that HBase started successfully.
140 You can use the `jps` command to verify that you have one running process called `HMaster`.
141 In standalone mode HBase runs all daemons within this single JVM, i.e.
142 the HMaster, a single HRegionServer, and the ZooKeeper daemon.
143 Go to _http://localhost:16010_ to view the HBase Web UI.
145 NOTE: Java needs to be installed and available.
146 If you get an error indicating that Java is not installed,
147 but it is on your system, perhaps in a non-standard location,
148 edit the _conf/hbase-env.sh_ file and modify the `JAVA_HOME`
149 setting to point to the directory that contains _bin/java_ on your system.
153 .Procedure: Use HBase For the First Time
156 Connect to your running instance of HBase using the `hbase shell` command, located in the [path]_bin/_ directory of your HBase install.
157 In this example, some usage and version information that is printed when you start HBase Shell has been omitted.
158 The HBase Shell prompt ends with a `>` character.
166 . Display HBase Shell Help Text.
168 Type `help` and press Enter, to display some basic usage information for HBase Shell, as well as several example commands.
169 Notice that table names, rows, columns all must be enclosed in quote characters.
173 Use the `create` command to create a new table.
174 You must specify the table name and the ColumnFamily name.
177 hbase(main):001:0> create 'test', 'cf'
178 0 row(s) in 0.4170 seconds
180 => Hbase::Table - test
183 . List Information About your Table
185 Use the `list` command to confirm your table exists
188 hbase(main):002:0> list 'test'
191 1 row(s) in 0.0180 seconds
197 Now use the `describe` command to see details, including configuration defaults
200 hbase(main):003:0> describe 'test'
201 Table test is ENABLED
203 COLUMN FAMILIES DESCRIPTION
204 {NAME => 'cf', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE =>
205 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'f
206 alse', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE
212 . Put data into your table.
214 To put data into your table, use the `put` command.
217 hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1'
218 0 row(s) in 0.0850 seconds
220 hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2'
221 0 row(s) in 0.0110 seconds
223 hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3'
224 0 row(s) in 0.0100 seconds
227 Here, we insert three values, one at a time.
228 The first insert is at `row1`, column `cf:a`, with a value of `value1`.
229 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.
231 . Scan the table for all data at once.
233 One of the ways to get data from HBase is to scan.
234 Use the `scan` command to scan the table for data.
235 You can limit your scan, but for now, all data is fetched.
238 hbase(main):006:0> scan 'test'
240 row1 column=cf:a, timestamp=1421762485768, value=value1
241 row2 column=cf:b, timestamp=1421762491785, value=value2
242 row3 column=cf:c, timestamp=1421762496210, value=value3
243 3 row(s) in 0.0230 seconds
246 . Get a single row of data.
248 To get a single row of data at a time, use the `get` command.
251 hbase(main):007:0> get 'test', 'row1'
253 cf:a timestamp=1421762485768, value=value1
254 1 row(s) in 0.0350 seconds
259 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.
260 You can re-enable it using the `enable` command.
263 hbase(main):008:0> disable 'test'
264 0 row(s) in 1.1820 seconds
266 hbase(main):009:0> enable 'test'
267 0 row(s) in 0.1770 seconds
270 Disable the table again if you tested the `enable` command above:
273 hbase(main):010:0> disable 'test'
274 0 row(s) in 1.1820 seconds
279 To drop (delete) a table, use the `drop` command.
282 hbase(main):011:0> drop 'test'
283 0 row(s) in 0.1370 seconds
286 . Exit the HBase Shell.
288 To exit the HBase Shell and disconnect from your cluster, use the `quit` command.
289 HBase is still running in the background.
292 .Procedure: Stop HBase
293 . In the same way that the _bin/start-hbase.sh_ script is provided to conveniently start all HBase daemons, the _bin/stop-hbase.sh_ script stops them.
297 $ ./bin/stop-hbase.sh
298 stopping hbase....................
302 . After issuing the command, it can take several minutes for the processes to shut down.
303 Use the `jps` to be sure that the HMaster and HRegionServer processes are shut down.
305 The above has shown you how to start and stop a standalone instance of HBase.
306 In the next sections we give a quick overview of other modes of hbase deploy.
308 [[quickstart_pseudo]]
309 === Pseudo-Distributed Local Install
311 After working your way through <<quickstart,quickstart>> standalone mode,
312 you can re-configure HBase to run in pseudo-distributed mode.
313 Pseudo-distributed mode means that HBase still runs completely on a single host,
314 but each HBase daemon (HMaster, HRegionServer, and ZooKeeper) runs as a separate process:
315 in standalone mode all daemons ran in one jvm process/instance.
316 By default, unless you configure the `hbase.rootdir` property as described in
317 <<quickstart,quickstart>>, your data is still stored in _/tmp/_.
318 In this walk-through, we store your data in HDFS instead, assuming you have HDFS available.
319 You can skip the HDFS configuration to continue storing your data in the local filesystem.
321 .Hadoop Configuration
324 This procedure assumes that you have configured Hadoop and HDFS on your local system and/or a remote
325 system, and that they are running and available. It also assumes you are using Hadoop 2.
327 link:https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/SingleCluster.html[Setting up a Single Node Cluster]
328 in the Hadoop documentation is a good starting point.
332 . Stop HBase if it is running.
334 If you have just finished <<quickstart,quickstart>> and HBase is still running, stop it.
335 This procedure will create a totally new directory where HBase will store its data, so any databases you created before will be lost.
339 Edit the _hbase-site.xml_ configuration.
340 First, add the following property which directs HBase to run in distributed mode, with one JVM instance per daemon.
346 <name>hbase.cluster.distributed</name>
351 Next, change the `hbase.rootdir` from the local filesystem to the address of your HDFS instance, using the `hdfs:////` URI syntax.
352 In this example, HDFS is running on the localhost at port 8020. Be sure to either remove the entry for `hbase.unsafe.stream.capability.enforce` or set it to true.
358 <name>hbase.rootdir</name>
359 <value>hdfs://localhost:8020/hbase</value>
363 You do not need to create the directory in HDFS.
364 HBase will do this for you.
365 If you create the directory, HBase will attempt to do a migration, which is not what you want.
369 Use the _bin/start-hbase.sh_ command to start HBase.
370 If your system is configured correctly, the `jps` command should show the HMaster and HRegionServer processes running.
372 . Check the HBase directory in HDFS.
374 If everything worked correctly, HBase created its directory in HDFS.
375 In the configuration above, it is stored in _/hbase/_ on HDFS.
376 You can use the `hadoop fs` command in Hadoop's _bin/_ directory to list this directory.
380 $ ./bin/hadoop fs -ls /hbase
382 drwxr-xr-x - hbase users 0 2014-06-25 18:58 /hbase/.tmp
383 drwxr-xr-x - hbase users 0 2014-06-25 21:49 /hbase/WALs
384 drwxr-xr-x - hbase users 0 2014-06-25 18:48 /hbase/corrupt
385 drwxr-xr-x - hbase users 0 2014-06-25 18:58 /hbase/data
386 -rw-r--r-- 3 hbase users 42 2014-06-25 18:41 /hbase/hbase.id
387 -rw-r--r-- 3 hbase users 7 2014-06-25 18:41 /hbase/hbase.version
388 drwxr-xr-x - hbase users 0 2014-06-25 21:49 /hbase/oldWALs
391 . Create a table and populate it with data.
393 You can use the HBase Shell to create a table, populate it with data, scan and get values from it, using the same procedure as in <<shell_exercises,shell exercises>>.
395 . Start and stop a backup HBase Master (HMaster) server.
397 NOTE: Running multiple HMaster instances on the same hardware does not make sense in a production environment, in the same way that running a pseudo-distributed cluster does not make sense for production.
398 This step is offered for testing and learning purposes only.
400 The HMaster server controls the HBase cluster.
401 You can start up to 9 backup HMaster servers, which makes 10 total HMasters, counting the primary.
402 To start a backup HMaster, use the `local-master-backup.sh`.
403 For each backup master you want to start, add a parameter representing the port offset for that master.
404 Each HMaster uses two ports (16000 and 16010 by default). The port offset is added to these ports, so using an offset of 2, the backup HMaster would use ports 16002 and 16012.
405 The following command starts 3 backup servers using ports 16002/16012, 16003/16013, and 16005/16015.
409 $ ./bin/local-master-backup.sh start 2 3 5
412 To kill a backup master without killing the entire cluster, you need to find its process ID (PID). The PID is stored in a file with a name like _/tmp/hbase-USER-X-master.pid_.
413 The only contents of the file is the PID.
414 You can use the `kill -9` command to kill that PID.
415 The following command will kill the master with port offset 1, but leave the cluster running:
419 $ cat /tmp/hbase-testuser-1-master.pid |xargs kill -9
422 . Start and stop additional RegionServers
424 The HRegionServer manages the data in its StoreFiles as directed by the HMaster.
425 Generally, one HRegionServer runs per node in the cluster.
426 Running multiple HRegionServers on the same system can be useful for testing in pseudo-distributed mode.
427 The `local-regionservers.sh` command allows you to run multiple RegionServers.
428 It works in a similar way to the `local-master-backup.sh` command, in that each parameter you provide represents the port offset for an instance.
429 Each RegionServer requires two ports, and the default ports are 16020 and 16030.
430 Since HBase version 1.1.0, HMaster doesn't use region server ports, this leaves 10 ports (16020 to 16029 and 16030 to 16039) to be used for RegionServers.
431 For supporting additional RegionServers, set environment variables HBASE_RS_BASE_PORT and HBASE_RS_INFO_BASE_PORT to appropriate values before running script `local-regionservers.sh`.
432 e.g. With values 16200 and 16300 for base ports, 99 additional RegionServers can be supported, on a server.
433 The following command starts four additional RegionServers, running on sequential ports starting at 16022/16032 (base ports 16020/16030 plus 2).
437 $ .bin/local-regionservers.sh start 2 3 4 5
440 To stop a RegionServer manually, use the `local-regionservers.sh` command with the `stop` parameter and the offset of the server to stop.
443 $ .bin/local-regionservers.sh stop 3
448 You can stop HBase the same way as in the <<quickstart,quickstart>> procedure, using the _bin/stop-hbase.sh_ command.
451 [[quickstart_fully_distributed]]
452 === Advanced - Fully Distributed
454 In reality, you need a fully-distributed configuration to fully test HBase and to use it in real-world scenarios.
455 In a distributed configuration, the cluster contains multiple nodes, each of which runs one or more HBase daemon.
456 These include primary and backup Master instances, multiple ZooKeeper nodes, and multiple RegionServer nodes.
458 This advanced quickstart adds two more nodes to your cluster.
459 The architecture will be as follows:
461 .Distributed Cluster Demo Architecture
462 [cols="1,1,1,1", options="header"]
464 | Node Name | Master | ZooKeeper | RegionServer
465 | node-a.example.com | yes | yes | no
466 | node-b.example.com | backup | yes | yes
467 | node-c.example.com | no | yes | yes
470 This quickstart assumes that each node is a virtual machine and that they are all on the same network.
471 It builds upon the previous quickstart, <<quickstart_pseudo>>, assuming that the system you configured in that procedure is now `node-a`.
472 Stop HBase on `node-a` before continuing.
474 NOTE: Be sure that all the nodes have full access to communicate, and that no firewall rules are in place which could prevent them from talking to each other.
475 If you see any errors like `no route to host`, check your firewall.
477 [[passwordless.ssh.quickstart]]
478 .Procedure: Configure Passwordless SSH Access
480 `node-a` needs to be able to log into `node-b` and `node-c` (and to itself) in order to start the daemons.
481 The easiest way to accomplish this is to use the same username on all hosts, and configure password-less SSH login from `node-a` to each of the others.
483 . On `node-a`, generate a key pair.
485 While logged in as the user who will run HBase, generate a SSH key pair, using the following command:
492 If the command succeeds, the location of the key pair is printed to standard output.
493 The default name of the public key is _id_rsa.pub_.
495 . Create the directory that will hold the shared keys on the other nodes.
497 On `node-b` and `node-c`, log in as the HBase user and create a _.ssh/_ directory in the user's home directory, if it does not already exist.
498 If it already exists, be aware that it may already contain other keys.
500 . Copy the public key to the other nodes.
502 Securely copy the public key from `node-a` to each of the nodes, by using the `scp` or some other secure means.
503 On each of the other nodes, create a new file called _.ssh/authorized_keys_ _if it does
504 not already exist_, and append the contents of the _id_rsa.pub_ file to the end of it.
505 Note that you also need to do this for `node-a` itself.
508 $ cat id_rsa.pub >> ~/.ssh/authorized_keys
511 . Test password-less login.
513 If you performed the procedure correctly, you should not be prompted for a password when you SSH from `node-a` to either of the other nodes using the same username.
515 . Since `node-b` will run a backup Master, repeat the procedure above, substituting `node-b` everywhere you see `node-a`.
516 Be sure not to overwrite your existing _.ssh/authorized_keys_ files, but concatenate the new key onto the existing file using the `>>` operator rather than the `>` operator.
518 .Procedure: Prepare `node-a`
520 `node-a` will run your primary master and ZooKeeper processes, but no RegionServers. Stop the RegionServer from starting on `node-a`.
522 . Edit _conf/regionservers_ and remove the line which contains `localhost`. Add lines with the hostnames or IP addresses for `node-b` and `node-c`.
524 Even if you did want to run a RegionServer on `node-a`, you should refer to it by the hostname the other servers would use to communicate with it.
525 In this case, that would be `node-a.example.com`.
526 This enables you to distribute the configuration to each node of your cluster any hostname conflicts.
529 . Configure HBase to use `node-b` as a backup master.
531 Create a new file in _conf/_ called _backup-masters_, and add a new line to it with the hostname for `node-b`.
532 In this demonstration, the hostname is `node-b.example.com`.
534 . Configure ZooKeeper
536 In reality, you should carefully consider your ZooKeeper configuration.
537 You can find out more about configuring ZooKeeper in <<zookeeper,zookeeper>> section.
538 This configuration will direct HBase to start and manage a ZooKeeper instance on each node of the cluster.
540 On `node-a`, edit _conf/hbase-site.xml_ and add the following properties.
545 <name>hbase.zookeeper.quorum</name>
546 <value>node-a.example.com,node-b.example.com,node-c.example.com</value>
549 <name>hbase.zookeeper.property.dataDir</name>
550 <value>/usr/local/zookeeper</value>
554 . Everywhere in your configuration that you have referred to `node-a` as `localhost`, change the reference to point to the hostname that the other nodes will use to refer to `node-a`.
555 In these examples, the hostname is `node-a.example.com`.
557 .Procedure: Prepare `node-b` and `node-c`
559 `node-b` will run a backup master server and a ZooKeeper instance.
561 . Download and unpack HBase.
563 Download and unpack HBase to `node-b`, just as you did for the standalone and pseudo-distributed quickstarts.
565 . Copy the configuration files from `node-a` to `node-b`.and `node-c`.
567 Each node of your cluster needs to have the same configuration information.
568 Copy the contents of the _conf/_ directory to the _conf/_ directory on `node-b` and `node-c`.
571 .Procedure: Start and Test Your Cluster
572 . Be sure HBase is not running on any node.
574 If you forgot to stop HBase from previous testing, you will have errors.
575 Check to see whether HBase is running on any of your nodes by using the `jps` command.
576 Look for the processes `HMaster`, `HRegionServer`, and `HQuorumPeer`.
577 If they exist, kill them.
581 On `node-a`, issue the `start-hbase.sh` command.
582 Your output will be similar to that below.
587 node-c.example.com: starting zookeeper, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-zookeeper-node-c.example.com.out
588 node-a.example.com: starting zookeeper, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-zookeeper-node-a.example.com.out
589 node-b.example.com: starting zookeeper, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-zookeeper-node-b.example.com.out
590 starting master, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-master-node-a.example.com.out
591 node-c.example.com: starting regionserver, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-regionserver-node-c.example.com.out
592 node-b.example.com: starting regionserver, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-regionserver-node-b.example.com.out
593 node-b.example.com: starting master, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-master-nodeb.example.com.out
596 ZooKeeper starts first, followed by the master, then the RegionServers, and finally the backup masters.
598 . Verify that the processes are running.
600 On each node of the cluster, run the `jps` command and verify that the correct processes are running on each server.
601 You may see additional Java processes running on your servers as well, if they are used for other purposes.
603 .`node-a` `jps` Output
611 .`node-b` `jps` Output
620 .`node-c` `jps` Output
628 .ZooKeeper Process Name
631 The `HQuorumPeer` process is a ZooKeeper instance which is controlled and started by HBase.
632 If you use ZooKeeper this way, it is limited to one instance per cluster node and is appropriate for testing only.
633 If ZooKeeper is run outside of HBase, the process is called `QuorumPeer`.
634 For more about ZooKeeper configuration, including using an external ZooKeeper instance with HBase, see <<zookeeper,zookeeper>> section.
637 . Browse to the Web UI.
642 In HBase newer than 0.98.x, the HTTP ports used by the HBase Web UI changed from 60010 for the
643 Master and 60030 for each RegionServer to 16010 for the Master and 16030 for the RegionServer.
646 If everything is set up correctly, you should be able to connect to the UI for the Master
647 `http://node-a.example.com:16010/` or the secondary master at `http://node-b.example.com:16010/`
649 If you can connect via `localhost` but not from another host, check your firewall rules.
650 You can see the web UI for each of the RegionServers at port 16030 of their IP addresses, or by
651 clicking their links in the web UI for the Master.
653 . Test what happens when nodes or services disappear.
655 With a three-node cluster you have configured, things will not be very resilient.
656 You can still test the behavior of the primary Master or a RegionServer by killing the associated processes and watching the logs.
661 The next chapter, <<configuration,configuration>>, gives more information about the different HBase run modes, system requirements for running HBase, and critical configuration areas for setting up a distributed HBase cluster.