Access hbase through thrift using PHP

Source: Internet
Author: User

Install xammp in the/OPT directory. The WWW directory is/opt/lampp/htdocs/

(1) create a web directory phphbase
[Root @ gd02 htdocs] # mkdir-P/opt/lampp/htdocs/phphphbase/
[Root @ gd02 htdocs] # cd/opt/lampp/htdocs/phphphbase
{View the example file democlient. php used by PHP to access hbase.
[Root @ gd02 phphphbase] # locate democlient. php
/Root/software/hbase-0.20.6/src/examples/thrift/democlient. php
[Root @ gd02 phphphbase] # ls/root/software/hbase-0.20.6/src/examples/thrift/
Democlient. cpp democlient. Java democlient. php democlient. py democlient. RB makefile readme.txt
}

(2) copy the instance file to the web directory phphphbase
[Root @ gd02 phphphbase] # cp/root/software/hbase-0.20.6/src/examples/thrift/democlient. php.
{View the hbase. Thrift file required for generating the PHP library by Thrift
[Root @ gd02 phphphbase] # locate hbase. Thrift
/Root/software/hbase-0.20.6/src/Java/org/Apache/hadoop/hbase/thrift/hbase. Thrift
}

(3) Use thrift to generate class files for PHP to access hbase
[Root @ gd02 phphphbase] # thrift -- Gen PHP/root/software/hbase-0.20.6/src/Java/org/Apache/hadoop/hbase/thrift/hbase. Thrift
[Root @ gd02 phphphbase] # generate the Gen-PHP Directory after LS command is successful
Democlient. php gen-PHP
[Root @ gd02 phphphbase] # Two PHP files are stored in the LS gen-PHP/hbase/directory, which encapsulates the operations for accessing hbase.
Hbase. php hbase_types.php

(4) copy the thrift PHP library file to the current web directory.
[Root @ gd02 phphphbase] # cp-r/root/thrift-0.6.1/lib/PHP/src.
[Root @ gd02 phphphbase] # ls
Democlient. php gen-PHP SRC

(5) copy the generated PHP file to access the hbase class file to the corresponding path under the src directory.
[Root @ gd02 phphphbase] # cp gen-PHP/hbase * src/packages/hbase/

(6) modify the instance file for execution
[Root @ gd02 phphphbase] # Vim democlient. php
Make the following changes:
# $ Globals ['thrift _ root'] = '/users/irubin/thrift/thrift-20080411p1/lib/PHP/src ';
Changed:
$ Globals ['thrift _ root'] = './src ';
# $ Socket = new tsocket ('localhost', 9090 );
Changed:
$ Socket = new tsocket ('gd02', 9090 );
Note that the host name and port number correspond to the host that starts the thrift service and the port number bound to the thrift service.

Note:
After the change, the following statements in democlient. php are actually only the./src/packages/hbase. php file.
Require_once ($ globals ['thrift _ root']. '/packages/hbase. php ');
The src directory contains these directories and files:
[Root @ gd02 phphphbase] # ls src/
Autoload. php ext packages protocol server thrift. php transport
In democlient. php, PHP files under these directories are called.

(7) Start Thrift
The node that starts the thrift Service corresponds to $ hostname in $ socket = new tsocket ($ hostname, $ port) of democlient. php,
The port number specified when the thrift service is started (9090 by default) must also correspond to $ port.
For example, to start the thrift service and specify the port number as 9999, use the hbase thrift-P 9999 start command.

[Root @ gd02 phphphbase] # hbase thrift start 1> thrift. log 2> & 1 & no port number is specified at startup. The default port number is enabled at this time.
[1] 32430
[Root @ gd02 phphphbase] # tail-F thrift. Log
The following warning message is displayed in the log, but thrift can still be started successfully:
11/06/24 21:32:11 warn zookeeper. zkconfig: cannot read zoo. cfg, loading from XML files
Java. Io. ioexception: the server in zoo. cfg cannot be set to localhost in a fully-distributed setup because it won't be reachable. See "Getting started" for more information.
At org. Apache. hadoop. hbase. zookeeper. zkconfig. parsezoocfg (zkconfig. Java: 173)
At org. Apache. hadoop. hbase. zookeeper. zkconfig. makezkprops (zkconfig. Java: 69)
At org. Apache. hadoop. hbase. zookeeper. zkconfig. getzkquorumserversstring (zkconfig. Java: 250)
At org. Apache. hadoop. hbase. zookeeper. zookeeperwatcher. <init> (zookeeperwatcher. Java: 113)
At org. Apache. hadoop. hbase. Client. hconnectionmanager $ hconnectionimplementation. getzookeeperwatcher (hconnectionmanager. Java: 989)
At org. Apache. hadoop. hbase. Client. hconnectionmanager $ hconnectionimplementation. setupzookeepertrackers (hconnectionmanager. Java: 302)
At org. Apache. hadoop. hbase. Client. hconnectionmanager $ hconnectionimplementation. <init> (hconnectionmanager. Java: 293)
At org. Apache. hadoop. hbase. Client. hconnectionmanager. getconnection (hconnectionmanager. Java: 156)
At org. Apache. hadoop. hbase. Client. hbaseadmin. <init> (hbaseadmin. Java: 85)
At org. Apache. hadoop. hbase. Thrift. thriftserver $ hbasehandler. <init> (thriftserver. Java: 194)
At org. Apache. hadoop. hbase. Thrift. thriftserver $ hbasehandler. <init> (thriftserver. Java: 188)
At org. Apache. hadoop. hbase. Thrift. thriftserver. domain (thriftserver. Java: 824)
At org. Apache. hadoop. hbase. Thrift. thriftserver. Main (thriftserver. Java: 881)
11/06/24 21:32:11 info thriftserver: Starting hbase threadpool thrift server on gd02/10.10.104.2: 9090 (the startup node is gd02 and the port number is 9090)
Zookeeper configuration file Zoo. the server in CFG cannot be set as localhost. Here, you only need to modify the zookeeper configuration file zoo on the node on which the thrift service is started. cfg.
Solution:
[Root @ gd02 phphphbase] # locate zoo. cfg
/Etc/zookeeper. Dist/zoo. cfg
[Root @ gd02 phphphbase] # Vim/etc/zookeeper. Dist/zoo. cfg
Change row server.0 = localhost: 2888: 3888 to server.0 = gd02: 2888: 3888

After the startup is successful, you can view the related processes:
[Hadoop @ gd02 phphphbase] $ JPs
JPS 372
6815 hmaster
32736 thriftserver is a Java process that is started by using the hbase thrift start command.
6757 hquorumpeer
6180 jobtracker
5930 namenode
View process details
[Hadoop @ gd02 phphphbase] $ PS-Ef | grep Thrift
We found that the startup process thriftserver is actually calling the class method: org. Apache. hadoop. hbase. Thrift. thriftserver start

(8) test:

Http: // 10.10.104.2/phphbase/democlient. php

10.10.104.2 is the IP address of gd02.

The following result is displayed:
-----------------------------------------------------------------------
Scanning tables...
Found: demo_table
Disabling table: demo_table
Deleting table: demo_table
Found: Researchers
Found: Student
Found: T1
Found: Test
Creating table: demo_table
Column families in demo_table:
Column: entry:, maxver: 10
Column: unused:, maxver: 3

Fatal error: uncaught exception 'exception' with message 'shouldn' t get here! 'In/opt/lampp/htdocs/phphbase/democlient. php: 161
Stack trace:
#0 {main}
Thrown in/opt/lampp/htdocs/phphbase/democlient. php on line 161
-----------------------------------------------------------------------

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.