Eclipse+hbase Development Environment Deployment

Source: Internet
Author: User
Tags zookeeper log4j

First, preface 1. Premise

Because the operation mode of HBase is pseudo-distributed, it needs to use HDFS, so before that, I have completed the development environment of the hadoop-eclipse, detailed look another article: Hadoop Development Environment Deployment-- Developed through the Eclipse remote Connection hadoop2.7.3, the purpose of this article is to deploy the development environment on the Windows side to enable it to run tests on the server side.

2. Environment

Service-side system: centos6.5

Hadoop version: 2.7.3

Java version: 1.8

HBase version: 1.2.6

Eclipse version: juno,4.2.0 (Windows)

Second, install MAVEN and Eclipse plugin 1. Installing MAVEN

To download the Maven installer and Eclipse plugin, the version I'm using is 3.3.9, to make it easy for everyone to share the MAVEN and plugin packages to a network disk:

Baidu Network disk: Https://pan.baidu.com/s/18p3vIPC7tw14gBI-doulZw

Password: Croh

Unzip the Maven tarball into the folder, set the environment variable maven_home, and add path:

The installation is successful if the version information output is typed into the mvn-v in CMD.

2. Modify the MAVEN repository storage address

In order to avoid reloading the system and other reasons to delete the already downloaded dependencies, you can change the Maven warehouse address to another location, the steps are as follows:

    • Locate%maven_home%/conf/settings.xml File
    • Find the localrepository tag, add the path configuration plus your own path

In cmd, typing command mvn help:system, download the dependencies can be in the set of warehouse path to see the specific information.

3. Installing the MAVEN Plugin

In general, there are two ways to install plug-ins in eclipse:

1) on-line installation, the main operation is to select one, and then specify to download the address inside the plugin, of course, you can add another valid address, the general step is to select Help in the menu bar, and then select Install New software ..., then you will see an Install dialog box, Click the Add button on the work with: field side and you will get a new Add Repository dialog box, enter the M2e,location field in the Name field http://m2eclipse.sonatype.org/sites/ M2E, then click OK.

The disadvantage of online installation is that many plug-in addresses are foreign, slow to say, and often install unsuccessfully.

2) Offline installation

After downloading the plug-in, you can find in the plug-in folder, there are two folders: Features and plugins, in the Eclipse home directory to create a new folder, the name can be taken, I take the Mvnplugin, the two folders just said to copy in.

Locate the Dropins directory in the Eclipse home directory, create a new file Maven.link, and fill in:

Path=c:\\eclipse_juno\\eclipse\\mvnplugin

Make adjustments according to your own circumstances.

Restart Eclipse to check if the plugin has been successfully installed,windows–> Preferences:

There are several advantages of offline installation, one is free of online installation of the turtle speed and address failure caused by the installation failure, the second is the way to use link, easy to install and Plug and unplug, recommend this way to install plug-ins.

4. Configure Maven

Select a native-installed Maven path:

Use your own configuration to install Maven:

At this point, complete the installation and configuration of MAVEN and its Eclipse plug-ins.

Three, build the HBase development environment 1. Create a MAVEN project

File->new->other->maven->maven Project,type is Maven-archetype-quickstart, the project is called Myhbase.

2. Add a configuration file to the resource path

Copy Core-site.xml,hdfs-site.xml,mapred-site.xml from the Hadoop configuration folder of the cluster to three files placed in the Hadoop folder, copy Hbase-site.xml from the HBase configuration folder in the cluster, place the HBase folder, and then put this Two folders are added to the project's Resource folder path, respectively:

/src/main/resources/hadoop

/src/main/resources/hbase

3. Add the configuration path to the Classpath

The final directory structure:

4. Modify Hbase-site.xml
<configuration>    <property>        <name>hbase.rootdir</name>        <value>hdfs: // harry.com:9000/hbase</value>    </property>    <property>        <name>dfs.replication</name>        <value>1 </value>    </property>    <property>        <name>hbase.zookeeper.quorum</ name>        <value>harry.com</value>    </property>    <property>        <name >hbase.cluster.distributed</name>        <value>true</value>    </property ></configuration>

Harry.com is a Linux host domain name that has been previously added to the Windows host file.

5. Synchronize HBase Libraries

Copy the Lib directory under the HBase cluster to Windows and add all libraries under Lib to the project in Eclipse.

6. New Test class Hbasetest

The code is as follows:

 Packagecom.harry.hbase.myHbase;//Package com.eric.hbase;Importjava.io.IOException;Importjava.util.ArrayList;Importjava.util.List;Importorg.apache.hadoop.conf.Configuration;Importorg.apache.hadoop.hbase.HBaseConfiguration;ImportOrg.apache.hadoop.hbase.HColumnDescriptor;ImportOrg.apache.hadoop.hbase.HTableDescriptor;ImportOrg.apache.hadoop.hbase.KeyValue;Importorg.apache.hadoop.hbase.MasterNotRunningException;Importorg.apache.hadoop.hbase.ZooKeeperConnectionException;ImportOrg.apache.hadoop.hbase.client.Delete;ImportOrg.apache.hadoop.hbase.client.Get;Importorg.apache.hadoop.hbase.client.HBaseAdmin;Importorg.apache.hadoop.hbase.client.HTable;ImportOrg.apache.hadoop.hbase.client.Put;ImportOrg.apache.hadoop.hbase.client.Result;ImportOrg.apache.hadoop.hbase.client.ResultScanner;ImportOrg.apache.hadoop.hbase.client.Scan;Importorg.apache.hadoop.hbase.util.Bytes; Public classHbasetest {Private Static FinalString table_name = "demo_table";  Public StaticConfiguration conf =NULL;  Publichtable table =NULL;  PublicHbaseadmin admin =NULL; Static{conf=hbaseconfiguration.create (); System.out.println (Conf.get ("Hbase.zookeeper.quorum")); }      /*** Create a table*/       Public Static voidcreattable (String tableName, string[] familys)throwsException {hbaseadmin admin=Newhbaseadmin (conf); if(Admin.tableexists (tableName)) {System.out.println ("Table already exists!"); } Else{htabledescriptor Tabledesc=NewHtabledescriptor (tableName);  for(inti = 0; i < familys.length; i++) {tabledesc.addfamily (NewHcolumndescriptor (Familys[i]));          } admin.createtable (TABLEDESC); System.out.println ("CREATE TABLE" + TableName + "OK."); }      }      /*** Delete Table*/       Public Static voidDeletetable (String tableName)throwsException {Try{hbaseadmin Admin=Newhbaseadmin (conf);          Admin.disabletable (TableName);          Admin.deletetable (TableName); System.out.println ("Delete Table" + TableName + "OK."); } Catch(masternotrunningexception e) {e.printstacktrace (); } Catch(zookeeperconnectionexception e) {e.printstacktrace (); }      }      /*** Insert a row of records*/       Public Static voidAddRecord (String tableName, String RowKey, String family, string qualifier, String value)throwsException {Try{htable table=Newhtable (conf, tableName); Put put=NewPut (Bytes.tobytes (RowKey));          Put.add (Bytes.tobytes (family), bytes.tobytes (qualifier), bytes.tobytes (value));          Table.put (Put); System.out.println ("Insert Recored" + RowKey + "to table" + TableName + "OK."); } Catch(IOException e) {e.printstacktrace (); }      }      /*** Delete a row of records*/       Public Static voidDelrecord (String tableName, string rowKey)throwsioexception {htable table=Newhtable (conf, tableName); List List=NewArrayList (); Delete del=NewDelete (Rowkey.getbytes ());        List.add (DEL);        Table.delete (list); System.out.println ("Del recored" + RowKey + "OK."); }      /*** Find a row of records*/       Public Static voidGetonerecord (String tableName, string rowKey)throwsioexception {htable table=Newhtable (conf, tableName); Get Get=NewGet (Rowkey.getbytes ()); Result RS=Table.get (GET);  for(KeyValue Kv:rs.raw ()) {System.out.print (NewString (Kv.getrow ()) + ""); System.out.print (NewString (kv.getfamily ()) + ":"); System.out.print (NewString (Kv.getqualifier ()) + ""); System.out.print (Kv.gettimestamp ()+ " "); System.out.println (NewString (Kv.getvalue ())); }      }      /*** Show All data*/       Public Static voidGetallrecord (String tableName) {Try{htable table=Newhtable (conf, tableName); Scan s=NewScan (); Resultscanner SS=Table.getscanner (s);  for(Result r:ss) { for(KeyValue Kv:r.raw ()) {System.out.print (NewString (Kv.getrow ()) + ""); System.out.print (NewString (kv.getfamily ()) + ":"); System.out.print (NewString (Kv.getqualifier ()) + ""); System.out.print (Kv.gettimestamp ()+ " "); System.out.println (NewString (Kv.getvalue ())); }          }        } Catch(IOException e) {e.printstacktrace (); }      }                 Public Static voidMain (string[] args) {//TODO auto-generated Method Stub         Try{String tablename= "Scores"; String[] Familys= {"Grade", "course" };              Hbasetest.creattable (tablename, familys); //Add record zkbHbasetest.addrecord (tablename, "ZKB", "Grade", "", "5"); Hbasetest.addrecord (tablename,"ZKB", "Course", "" "," 90 "); Hbasetest.addrecord (tablename,"ZKB", "Course", "math", "97"); Hbasetest.addrecord (tablename,"ZKB", "course", "Art", "87"); //Add record BaoniuHbasetest.addrecord (tablename, "Baoniu", "Grade", "", "4"); Hbasetest. AddRecord (tablename,"Baoniu", "Course", "math", "89"); System.out.println ("===========get One record========"); Hbasetest.getonerecord (tablename,"ZKB"); System.out.println ("===========show All record========");              Hbasetest.getallrecord (tablename); System.out.println ("===========del One record========"); Hbasetest.delrecord (tablename,"Baoniu");              Hbasetest.getallrecord (tablename); System.out.println ("===========show All record========");            Hbasetest.getallrecord (tablename); } Catch(Exception e) {e.printstacktrace (); }          }    }

7. Add Log Configuration

File name Log4j.properties, with the following contents:

 for testing:optionally with log file  #log4j. Rootlogger=debug,appender  log4j.rootlogger=  Info,appender  #log4j. Rootlogger=error,appender    #\u8f93\u51fa\u5230\u63a7\u5236\u53f0  Log4j.appender.appender=org.apache.log4j.ConsoleAppender  #\u6837\u5f0f\u4e3attcclayout  Log4j.appender.appender.layout=org.apache.log4j.ttcclayout

After adding these two files, the directory structure is:

8. Run the Code

Right-click-->run as-->java application, if successful, the console will have the following output:

At this point, HBase was deployed successfully under the Windows System's Eclipse development environment.

Iv. references

1. Installation and configuration of the Eclipse Maven plugin

2. Eclipse installs the SVN, maven plugin

3. Eclipse+hbase Development Environment Construction (already practiced)

4. HBase Development Environment Building (Eclipse+maven)

Finish

Eclipse+hbase Development Environment Deployment

Related Article

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.