| Welcome to Huynh's Collections. We hope you enjoy your visit. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you're already a member please log in to your account to access all of our features: |
| Tôi chọn Java, Hive hoặc Pig như thế nào? | |
|---|---|
| Tweet Topic Started: Dec 5 2013, 08:53 PM (336 Views) | |
| Huynhnb8x | Dec 5 2013, 08:53 PM Post #1 |
|
Th1nk
![]() ![]() ![]() ![]() ![]()
|
Bạn có nhiều tùy chọn để lập tŕnh Hadoop và tốt nhất là xem xét trường hợp sử dụng để chọn đúng công cụ cho công việc đó. Bạn không bị hạn chế chỉ làm việc với dữ liệu quan hệ nhưng bài này tập trung vào Informix, DB2 và Hadoop để hoạt động tốt với chúng. Việc viết hàng trăm ḍng mă bằng Java để thực hiện một phép nối băm kiểu quan hệ là hoàn toàn phí thời gian do thuật toán MapReduce của Hadoop đă có sẵn. Bạn chọn tùy chọn nào? Đó là vấn đề sở thích cá nhân. Một số người thích viết mă các phép toán tập hợp bằng SQL. Một số người khác thích viết mă kiểu thủ tục. Bạn nên chọn ngôn ngữ mà bạn làm việc hiệu quả nhất. Nếu bạn có nhiều hệ thống quan hệ và muốn kết hợp tất cả các dữ liệu với hiệu năng lớn với một mức giá thấp, th́ Hadoop, MapReduce, Hive và Pig đă sẵn sàng để trợ giúp. Đừng xóa dữ liệu của bạn: Cuộn lại một phân vùng từ Informix vào HDFS Hầu hết các cơ sở dữ liệu quan hệ hiện đại đều có thể phân vùng dữ liệu. Một trường hợp sử dụng phổ biến là phân vùng theo khoảng thời gian. Một cửa sổ thời gian cố định của các dữ liệu được lưu trong cơ sở dữ liệu, ví dụ một khoảng thời gian 18 tháng trôi qua, sau đó dữ liệu được đưa vào lưu trữ. Khả năng tách phân vùng là rất mạnh. Nhưng sau khi phân vùng được tách ra người ta làm ǵ với dữ liệu? Việc lưu trữ dữ liệu cũ vào băng từ là một cách rất tốn kém để loại bỏ các byte dữ liệu cũ. Sau khi đă di chuyển sang môi trường ít có thể truy cập hơn, dữ liệu rất hiếm khi được truy cập trừ khi có một yêu cầu kiểm toán hợp pháp. Hadoop đưa ra một sự thay thế khác tốt hơn. Di chuyển các byte dữ liệu lưu trữ từ các phân vùng cũ vào Hadoop tạo ra khả năng truy cập hiệu năng cao với chi phí thấp hơn nhiều so với việc duy tŕ dữ liệu trong hệ thống giao dịch hoặc quầy dữ liệu/kho dữ liệu ban đầu. Dữ liệu là quá cũ không c̣n giá trị giao dịch nữa, nhưng vẫn c̣n rất có giá trị với tổ chức để dùng cho các phân tích dài hạn. Các ví dụ Sqoop được hiển thị ở trên cung cấp những điều cơ bản về cách di chuyển dữ liệu này từ một phân vùng quan hệ sang HDFS. Fuse – Truy cập các tệp HDFS của bạn thông qua NFS Có thể truy cập dữ liệu Informix/DB2/tệp phẳng trong HDFS thông qua NFS, như hiển thị trong Liệt kê 20. Cách này cung cấp các hoạt động ḍng lệnh mà không cần sử dụng giao diện "hadoop fs-yadayada". Theo quan điểm công nghệ về trường hợp sử dụng, NFS rất bị hạn chế trong một môi trường Dữ liệu lớn, nhưng các ví dụ được cung cấp cho các nhà phát triển và dữ liệu không-lớn-lắm. Liệt kê 20. Thiết lập Fuse - truy cập dữ liệu HDFS của bạn thông qua NFS # this is for CDH4, the CDH3 image doesn't have fuse installed... $ mkdir fusemnt $ sudo hadoop-fuse-dfs dfs://localhost:8020 fusemnt/ INFO fuse_options.c:162 Adding FUSE arg fusemnt/ $ ls fusemnt tmp user var $ ls fusemnt/user cloudera hive $ ls fusemnt/user/cloudera customer DS.txt.gz HF.out HF.txt orders staff $ cat fusemnt/user/cloudera/orders/part-m-00001 1007,2008-05-31,117,null,n,278693 ,2008-06-05,125.90,25.20,null 1008,2008-06-07,110,closed Monday ,y,LZ230 ,2008-07-06,45.60,13.80,2008-07-21 1009,2008-06-14,111,next door to grocery ,n,4745 ,2008-06-21,20.40,10.00,2008-08-21 1010,2008-06-17,115,deliver 776 King St. if no answer ,n,429Q ,2008-06-29,40.60,12.30,2008-08-22 1011,2008-06-18,104,express ,n,B77897 ,2008-07-03,10.40,5.00,2008-08-29 1012,2008-06-18,117,null,n,278701 ,2008-06-29,70.80,14.20,null Flume - tạo ra một tệp sẵn sàng nạp Thế hệ tiếp theo của Flume hay là flume-ng là tŕnh nạp song song tốc độ cao. Các cơ sở dữ liệu có các tŕnh nạp tốc độ cao, vậy làm thế nào để chúng sẽ hoạt động tốt với nhau? Trường hợp sử dụng dữ liệu quan hệ dành cho Flume-ng sẽ tạo ra một tệp sẵn sàng để nạp, tại chỗ hoặc từ xa, sao cho một máy chủ dữ liệu quan hệ có thể dùng tŕnh nạp tốc độ cao của ḿnh. Đúng là chức năng này chồng lên Sqoop, nhưng kịch bản lệnh được hiển thị trong Liệt kê 21 đă được tạo ra theo yêu cầu của một khách hàng đặc biệt cho kiểu nạp cơ sở dữ liệu này. Liệt kê 21. Xuất khẩu dữ liệu HDFS tới một tệp phẳng để nạp bởi một cơ sở dữ liệu $ sudo yum install flume-ng $ cat flumeconf/hdfs2dbloadfile.conf # # started with example from flume-ng documentation # modified to do hdfs source to file sink # # Define a memory channel called ch1 on agent1 agent1.channels.ch1.type = memory # Define an exec source called exec-source1 on agent1 and tell it # to bind to 0.0.0.0:31313. Connect it to channel ch1. agent1.sources.exec-source1.channels = ch1 agent1.sources.exec-source1.type = exec agent1.sources.exec-source1.command =hadoop fs -cat /user/cloudera/orders/part-m-00001 # this also works for all the files in the hdfs directory # agent1.sources.exec-source1.command =hadoop fs # -cat /user/cloudera/tsortin/* agent1.sources.exec-source1.bind = 0.0.0.0 agent1.sources.exec-source1.port = 31313 # Define a logger sink that simply file rolls # and connect it to the other end of the same channel. agent1.sinks.fileroll-sink1.channel = ch1 agent1.sinks.fileroll-sink1.type = FILE_ROLL agent1.sinks.fileroll-sink1.sink.directory =/tmp # Finally, now that we've defined all of our components, tell # agent1 which ones we want to activate. agent1.channels = ch1 agent1.sources = exec-source1 agent1.sinks = fileroll-sink1 # now time to run the script $ flume-ng agent --conf ./flumeconf/ -f ./flumeconf/hdfs2dbloadfile.conf -n agent1 # here is the output file # don't forget to stop flume - it will keep polling by default and generate # more files $ cat /tmp/1344780561160-1 1007,2008-05-31,117,null,n,278693 ,2008-06-05,125.90,25.20,null 1008,2008-06-07,110,closed Monday ,y,LZ230 ,2008-07-06,45.60,13.80,2008-07-21 1009,2008-06-14,111,next door to ,n,4745 ,2008-06-21,20.40,10.00,2008-08-21 1010,2008-06-17,115,deliver 776 King St. if no answer ,n,429Q ,2008-06-29,40.60,12.30,2008-08-22 1011,2008-06-18,104,express ,n,B77897 ,2008-07-03,10.40,5.00,2008-08-29 1012,2008-06-18,117,null,n,278701 ,2008-06-29,70.80,14.20,null # jump over to dbaccess and use the greatest # data loader in informix: the external table # external tables were actually developed for # informix XPS back in the 1996 timeframe # and are now available in may servers # drop table eorders; create external table eorders (on char(10), mydate char(18), foo char(18), bar char(18), f4 char(18), f5 char(18), f6 char(18), f7 char(18), f8 char(18), f9 char(18) ) using (datafiles ("disk:/tmp/myfoo" ) , delimiter ","); select * from eorders; Oozie - thêm luồng công việc cho nhiều tác vụ Oozie sẽ xâu chuỗi nhiều tác vụ của Hadoop với nhau. Có một tập hợp các ví dụ hấp dẫn kèm theo oozie, đă được dùng trong đoạn mă được hiển thị trong Liệt kê 22. Liệt kê 22. Kiểm soát tác vụ bằng oozie # This sample is for CDH3 # untar the examples # CDH4 $ tar -zxvf /usr/share/doc/oozie-3.1.3+154/oozie-examples.tar.gz # CDH3 $ tar -zxvf /usr/share/doc/oozie-2.3.2+27.19/oozie-examples.tar.gz # cd to the directory where the examples live # you MUST put these jobs into the hdfs store to run them $ hadoop fs -put examples examples # start up the oozie server - you need to be the oozie user # since the oozie user is a non-login id use the following su trick # CDH4 $ sudo su - oozie -s /usr/lib/oozie/bin/oozie-sys.sh start # CDH3 $ sudo su - oozie -s /usr/lib/oozie/bin/oozie-start.sh # checkthe status oozie admin -oozie http://localhost:11000/oozie -status System mode: NORMAL # some jar housekeeping so oozie can find what it needs $ cp /usr/lib/sqoop/sqoop-1.3.0-cdh3u4.jar examples/apps/sqoop/lib/ $ cp /home/cloudera/Informix_JDBC_Driver/lib/ifxjdbc.jar examples/apps/sqoop/lib/ $ cp /home/cloudera/Informix_JDBC_Driver/lib/ifxjdbcx.jar examples/apps/sqoop/lib/ # edit the workflow.xml file to use your relational database: ################################# <command> import --driver com.informix.jdbc.IfxDriver --connect jdbc:informix-sqli://192.168.1.143:54321/stores_demo:informixserver=ifx117 --table orders --username informix --password useyours --target-dir /user/${wf:user()}/${examplesRoot}/output-data/sqoop --verbose<command> ################################# # from the directory where you un-tarred the examples file do the following: $ hrmr examples;hput examples examples # now you can run your sqoop job by submitting it to oozie $ oozie job -oozie http://localhost:11000/oozie -config \ examples/apps/sqoop/job.properties -run job: 0000000-120812115858174-oozie-oozi-W # get the job status from the oozie server $ oozie job -oozie http://localhost:11000/oozie -info 0000000-120812115858174-oozie-oozi-W Job ID : 0000000-120812115858174-oozie-oozi-W ----------------------------------------------------------------------- Workflow Name : sqoop-wf App Path : hdfs://localhost:8020/user/cloudera/examples/apps/sqoop/workflow.xml Status : SUCCEEDED Run : 0 User : cloudera Group : users Created : 2012-08-12 16:05 Started : 2012-08-12 16:05 Last Modified : 2012-08-12 16:05 Ended : 2012-08-12 16:05 Actions ---------------------------------------------------------------------- ID Status Ext ID Ext Status Err Code --------------------------------------------------------------------- 0000000-120812115858174-oozie-oozi-W@sqoop-node OK job_201208120930_0005 SUCCEEDED - -------------------------------------------------------------------- # how to kill a job may come in useful at some point oozie job -oozie http://localhost:11000/oozie -kill 0000013-120812115858174-oozie-oozi-W # job output will be in the file tree $ hcat /user/cloudera/examples/output-data/sqoop/part-m-00003 1018,2008-07-10,121,SW corner of Biltmore Mall ,n,S22942 ,2008-07-13,70.50,20.00,2008-08-06 1019,2008-07-11,122,closed till noon Mondays ,n,Z55709 ,2008-07-16,90.00,23.00,2008-08-06 1020,2008-07-11,123,express ,n,W2286 ,2008-07-16,14.00,8.50,2008-09-20 1021,2008-07-23,124,ask for Elaine ,n,C3288 ,2008-07-25,40.00,12.00,2008-08-22 1022,2008-07-24,126,express ,n,W9925 ,2008-07-30,15.00,13.00,2008-09-02 1023,2008-07-24,127,no deliveries after 3 p.m. ,n,KF2961 ,2008-07-30,60.00,18.00,2008-08-22 # if you run into this error there is a good chance that your # database lock file is owned by root $ oozie job -oozie http://localhost:11000/oozie -config \ examples/apps/sqoop/job.properties -run Error: E0607 : E0607: Other error in operation [<openjpa-1.2.1-r752877:753278 fatal store error> org.apache.openjpa.persistence.RollbackException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred.], {1} # fix this as follows $ sudo chown oozie:oozie /var/lib/oozie/oozie-db/db.lck # and restart the oozie server $ sudo su - oozie -s /usr/lib/oozie/bin/oozie-stop.sh $ sudo su - oozie -s /usr/lib/oozie/bin/oozie-start.sh HBase, một kho lưu trữ key-value hiệu năng cao HBase là một kho lưu trữ key-value hiệu năng cao. Nếu trường hợp sử dụng của bạn cần có khả năng mở rộng quy mô và chỉ cần kiểu giao dịch cơ sở dữ liệu tương đương như các giao dịch giao kết tự động, th́ rất có thể HBase là công nghệ cần dùng. HBase không phải là một cơ sở dữ liệu. Tên của nó không thích hợp v́ đối với một số người, thuật ngữ base ngụ ư là cơ sở dữ liệu. Nó thực sự làm việc tuyệt vời cho các kho lưu trữ key-value hiệu năng cao. Có một số sự chồng chéo giữa chức năng của HBase, Informix, DB2 và các cơ sở dữ liệu quan hệ khác. Đối với các giao dịch ACID, tuân thủ SQL đầy đủ, và nhiều chỉ mục th́ một cơ sở dữ liệu quan hệ truyền thống sẽ là sự lựa chọn hiển nhiên. Bài tập viết mă cuối cùng này nhằm đem đến sự hiểu biết cơ bản về HBase. Bài tập này được thiết kế đơn giản và hoàn toàn không đại diện cho phạm vi chức năng của HBase. Hăy sử dụng ví dụ này để hiểu một số trong những khả năng cơ bản trong HBase. "HBase, The Definitive Guide" (HBase một hướng dẫn đáng tin cậy) của Lars George, là cuốn sách bắt buộc phải đọc nếu bạn có kế hoạch thực hiện hoặc loại bỏ HBase trong trường hợp sử dụng cụ thể của ḿnh. Ví dụ cuối cùng, được hiển thị trong Liệt kê 23 và 24, sử dụng giao diện REST được cung cấp với HBase để chèn các cặp khóa-các giá trị vào một bảng HBase. Chạy bài thử nghiệm bằng curl. Liệt kê 23. Tạo một bảng HBase và chèn vào một hàng # enter the command line shell for hbase $ hbase shell HBase Shell; enter 'help<RETURN> for list of supported commands. Type "exit<RETURN> to leave the HBase Shell Version 0.90.6-cdh3u4, r, Mon May 7 13:14:00 PDT 2012 # create a table with a single column family hbase(main):001:0> create 'mytable', 'mycolfamily' # if you get errors from hbase you need to fix the # network config # here is a sample of the error: ERROR: org.apache.hadoop.hbase.ZooKeeperConnectionException: HBase is able to connect to ZooKeeper but the connection closes immediately. This could be a sign that the server has too many connections (30 is the default). Consider inspecting your ZK server logs for that error and then make sure you are reusing HBaseConfiguration as often as you can. See HTable's javadoc for more information. # fix networking: # add the eth0 interface to /etc/hosts with a hostname $ sudo su - # ifconfig | grep addr eth0 Link encap:Ethernet HWaddr 00:0C:29:8C:C7:70 inet addr:192.168.1.134 Bcast:192.168.1.255 Mask:255.255.255.0 Interrupt:177 Base address:0x1400 inet addr:127.0.0.1 Mask:255.0.0.0 [root@myhost ~]# hostname myhost [root@myhost ~]# echo "192.168.1.134 myhost" >gt; /etc/hosts [root@myhost ~]# cd /etc/init.d # now that the host and address are defined restart Hadoop [root@myhost init.d]# for i in hadoop* > do > ./$i restart > done # now try table create again: $ hbase shell HBase Shell; enter 'help<RETURN> for list of supported commands. Type "exit<RETURN> to leave the HBase Shell Version 0.90.6-cdh3u4, r, Mon May 7 13:14:00 PDT 2012 hbase(main):001:0> create 'mytable' , 'mycolfamily' 0 row(s) in 1.0920 seconds hbase(main):002:0> # insert a row into the table you created # use some simple telephone call log data # Notice that mycolfamily can have multiple cells # this is very troubling for DBAs at first, but # you do get used to it hbase(main):001:0> put 'mytable', 'key123', 'mycolfamily:number','6175551212' 0 row(s) in 0.5180 seconds hbase(main):002:0> put 'mytable', 'key123', 'mycolfamily:duration','25' # now describe and then scan the table hbase(main):005:0> describe 'mytable' DESCRIPTION ENABLED {NAME => 'mytable', FAMILIES => [{NAME => 'mycolfam true ily', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => ' 0', COMPRESSION => 'NONE', VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'f alse', BLOCKCACHE => 'true'}]} 1 row(s) in 0.2250 seconds # notice that timestamps are included hbase(main):007:0> scan 'mytable' ROW COLUMN+CELL key123 column=mycolfamily:duration, timestamp=1346868499125, value=25 key123 column=mycolfamily:number, timestamp=1346868540850, value=6175551212 1 row(s) in 0.0250 seconds Liệt kê 24. Sử dụng giao diện REST của Hbase # HBase includes a REST server $ hbase rest start -p 9393 & # you get a bunch of messages.... # get the status of the HBase server $ curl http://localhost:9393/status/cluster # lots of output... # many lines deleted... mytable,,1346866763530.a00f443084f21c0eea4a075bbfdfc292. stores=1 storefiless=0 storefileSizeMB=0 memstoreSizeMB=0 storefileIndexSizeMB=0 # now scan the contents of mytable $ curl http://localhost:9393/mytable/* # lines deleted 12/09/05 15:08:49 DEBUG client.HTable$ClientScanner: Finished with scanning at REGION => # lines deleted <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <CellSet><Row key="a2V5MTIz"> <Cell timestamp="1346868499125" column="bXljb2xmYW1pbHk6ZHVyYXRpb24=">MjU=</Cell> <Cell timestamp="1346868540850" column="bXljb2xmYW1pbHk6bnVtYmVy">NjE3NTU1MTIxMg==</Cell> <Cell timestamp="1346868425844" column="bXljb2xmYW1pbHk6bnVtYmVy">NjE3NTU1MTIxMg==</Cell> </Row></CellSet> # the values from the REST interface are base64 encoded $ echo a2V5MTIz | base64 -d key123 $ echo bXljb2xmYW1pbHk6bnVtYmVy | base64 -d mycolfamily:number # The table scan above gives the schema needed to insert into the HBase table $ echo RESTinsertedKey | base64 UkVTVGluc2VydGVkS2V5Cg== $ echo 7815551212 | base64 NzgxNTU1MTIxMgo= # add a table entry with a key value of "RESTinsertedKey" and # a phone number of "7815551212" # note - curl is all on one line $ curl -H "Content-Type: text/xml" -d '<CellSet> <Row key="UkVTVGluc2VydGVkS2V5Cg=="> <Cell column="bXljb2xmYW1pbHk6bnVtYmVy">NzgxNTU1MTIxMgo=<Cell> <Row><CellSet> http://192.168.1.134:9393/mytable/dummykey 12/09/05 15:52:34 DEBUG rest.RowResource: POST http://192.168.1.134:9393/mytable/dummykey 12/09/05 15:52:34 DEBUG rest.RowResource: PUT row=RESTinsertedKey\x0A, families={(family=mycolfamily, keyvalues=(RESTinsertedKey\x0A/mycolfamily:number/9223372036854775807/Put/vlen=11)} # trust, but verify hbase(main):002:0> scan 'mytable' ROW COLUMN+CELL RESTinsertedKey\x0A column=mycolfamily:number,timestamp=1346874754883,value=7815551212\x0A key123 column=mycolfamily:duration, timestamp=1346868499125, value=25 key123 column=mycolfamily:number, timestamp=1346868540850, value=6175551212 2 row(s) in 0.5610 seconds # notice the \x0A at the end of the key and value # this is the newline generated by the "echo" command # lets fix that $ printf 8885551212 | base64 ODg4NTU1MTIxMg== $ printf mykey | base64 bXlrZXk= # note - curl statement is all on one line! curl -H "Content-Type: text/xml" -d '<CellSet><Row key="bXlrZXk="> <Cell column="bXljb2xmYW1pbHk6bnVtYmVy">ODg4NTU1MTIxMg==<Cell> <Row><CellSet> http://192.168.1.134:9393/mytable/dummykey # trust but verify hbase(main):001:0> scan 'mytable' ROW COLUMN+CELL RESTinsertedKey\x0A column=mycolfamily:number,timestamp=1346875811168,value=7815551212\x0A key123 column=mycolfamily:duration, timestamp=1346868499125, value=25 key123 column=mycolfamily:number, timestamp=1346868540850, value=6175551212 mykey column=mycolfamily:number, timestamp=1346877875638, value=8885551212 3 row(s) in 0.6100 seconds |
| Knowledge crawling | |
![]() |
|
| « Previous Topic · Tài liệu sưu tầm · Next Topic » |
| Track Topic · E-mail Topic |
9:00 AM Jul 11
|
Theme by James... of the ZBTZ and themeszetaboards.com





![]](http://z5.ifrm.com/static/1/pip_r.png)



9:00 AM Jul 11