HBase (local mode) remote access

Source: Internet
Author: User
Tags mkdir zookeeper

If you beginner hbase, there is no need to get a cluster, HBase local mode enough.

Write a simple tutorial here. For toddlers who want to use code to access HBase's children's shoes.

Directory:

0. Preparation

1). Development environment

2). Modify Host Name

3). Install JDK in CentOS

1. Install HBase (local mode)

1). Download

2). Unzip

3). Configure

4). Run

5). HBase Shell Access

2. Remote Access

3. Summary

0. Preparation

1). Development environment

One laptop,win10,eclipse,vmware 10,centos 7.3

This is the development environment of my notebook, basically eclipse runs on Windows, HBase runs in the VM.

If you install eclipse in a centos7.3, this is not a remote access. The situation is not discussed here.

2). Modify the machine name of CentOS 7.3

The local mode of HBase, by default, uses the host name as the address of the/hbase/master. If the host name is localhost, there is a problem with eclipse remote access. So we need to fix the hostname of CentOS.

VI /etc/sysconfig/Network
Networking=yes
Hostname=docker

# vi/etc/hosts192.168. 1.135 Docker

Re-start CentOS
# init 6

Because this VM is also used to learn Docker, the hostname is changed to Docker.

3). Install JDK in CentOS

Download a JDK in the form of RPM and

# RPM-IVH jdk-8u101-linux-x64.rpm

Other such as. tar.gz form also does not matter, installs on the line.

2. Installing HBase

Local mode means that the underlying file system is not using HDFS, but is using the OS's local file system directly.

1). Download

Download hbase-1.2.6, this to hbase.apache.org to download, you can in Win10, and then copy into CentOS, you can also directly under the CentOS

# wget ...

Download zookeeper-3.4.6, this download as long as the decompression can be placed in/opt/zookeeper-3.4.6

2). Unzip

Assume that the file is/opt/hbase-1.2. 6. Tar  /tar zvxf hbase-1.2. 6. tar. gz

When HBase is decompressed, it is located in/opt/hbase-1.2.6

3). Configure

Native run, need to configure two files: conf/hbase-env.sh, Conf/hbase-site.xml

conf/hbase-env.sh

Depending on the location of your JDK, configure Java_home

# cd/opt/hbase-1.2. 6  VI conf/hbase-env. SH ... export java_home=/usr/java/latest ...

Conf/hbase-site.xml

vi conf/hbase-site.xml<configuration>  <property>    <name> hbase.rootdir</name>    <value>file://opt/hbase-1.2.6/data/hbase  </value>  </property>  <property>    <name> hbase.zookeeper.property.datadir</name>    <value>/opt/hbase-1.2.  6/data/zookeeper</value>  </property></configuration>

Create two new directories to save the data

# cd/opt/hbase-1.2. 6  mkdir -Pdata/mkdir data/zookeeper

4). Run

After running, you can open HBase Web UI-http://192.168.1.135:16010 in the browser

Because the local mode zookeeper is within the JVM running in HBase, the zookeeper process is not visible using the JPS command, which can be viewed using the downloaded Zookeeper connection:

# cd/opt/zookeeper-3.4. 6 # bin/zkcli. SH

To connect to zookeeper, you can view the address of master:

If you do not change the hostname, the CentOS default is localhost, then the red box this place is localhost.

Stop running:

5). HBase Shell Access

New table, table name: Test, column family: CF

Then put a line in the test table: Rowkey: "Row1", column: A, cf:a, value: "Value1"

Then through the get query, the results are as follows:

Two. Remote access

"Remote" means that the program that is accessed does not run in the CentOS run, in other words, the Access program and the VM running the HBase with two IPs. (Like my win10:192.168.1.102, vm:192.168.1.135)

Create a new Java project in eclipse, a normal Java project, using only main () to run.

Then create a directory under the project directory: Lib, in the same class as SRC, all the jars in the Hbase-1.2.6/lib directory in the VM are copied, all of them into Eclipse Lib, set the Eclipse Project's build path, add all the jars in the Lib, This should be known in Java.

Project directory Structure:

Testconnection.java

 PackageEx1;Importorg.apache.hadoop.conf.Configuration;Importorg.apache.hadoop.hbase.HBaseConfiguration;ImportOrg.apache.hadoop.hbase.TableName;Importorg.apache.hadoop.hbase.client.Connection;Importorg.apache.hadoop.hbase.client.ConnectionFactory;ImportOrg.apache.hadoop.hbase.client.Get;ImportOrg.apache.hadoop.hbase.client.Result;Importorg.apache.hadoop.hbase.client.Table;Importorg.apache.hadoop.hbase.util.Bytes; Public classtestconnection { Public Staticconfiguration configuration; Static{Configuration=hbaseconfiguration.create (); Configuration.set ("Hbase.zookeeper.quorum", "192.168.1.135") ; System.out.println ("==============="); }         Public Static voidMain (string[] args)throwsException {Connection conn=connectionfactory.createconnection (configuration); Table Table= Conn.gettable (tablename.valueof ("Test")); Get Get=NewGet (Bytes.tobytes ("Row1")); Get.addcolumn (Bytes.tobytes ("CF"), Bytes.tobytes ("a")); Result R=Table.get (GET); if(R.isempty ()) {System.out.println ("Result is null"); } System.out.println ("Result=" +NewString (R.value ()));    Conn.close (); }}

To change the win10/etc/hosts file (C:\Windows\System32\drivers\etc\hosts) before running the program, add the following line:

192.168.1.135 Docker

After you change this file, the Web UI can also access the http://docker:16010

Operation Result:

3. Summary:

In fact, to say so much, the fishing is said to be: HBase local mode using host name as the address .

The HBase client (that is, the code in Eclipse) accesses hbase through the address in the zookeeper (the place where the red box is painted), and if zookeeper holds localhost, And localhost's IP is 127.0.0.1,

Then it becomes a visit to win10 himself, not to visit CentOS.

The hostname of the VM is changed so that the name is only a name, so that it can be associated with other IPs, not 127.0.0.1.

HBase (local mode) remote access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.