paulwong

#

一网打尽13款开源Java大数据工具

下面将介绍大数据领域支持Java的主流开源工具

1. HDFS

HDFS是Hadoop应用程序中主要的分布式储存系统, HDFS集群包含了一个NameNode(主节点),这个节点负责管理所有文件系统的元数据及存储了真实数据的DataNode(数据节点,可以有很多)。HDFS针对海量数据所设计,所以相比传统文件系统在大批量小文件上的优化,HDFS优化的则是对小批量大型文件的访问和存储。

2. MapReduce

Hadoop MapReduce是一个软件框架,用以轻松编写处理海量(TB级)数据的并行应用程序,以可靠和容错的方式连接大型集群中上万个节点(商用硬件)。

3. HBase

Apache HBase是Hadoop数据库,一个分布式、可扩展的大数据存储。它提供了大数据集上随机和实时的读/写访问,并针对了商用服务器集群上的大型表格做出优化——上百亿行,上千万列。其核心是Google Bigtable论文的开源实现,分布式列式存储。就像Bigtable利用GFS(Google File System)提供的分布式数据存储一样,它是Apache Hadoop在HDFS基础上提供的一个类Bigatable。

4. Cassandra

Apache Cassandra是一个高性能、可线性扩展、高有效性数据库,可以运行在商用硬件或云基础设施上打造完美的任务关键性数据平台。在横跨数据中心的复制中,Cassandra同类最佳,为用户提供更低的延时以及更可靠的灾难备份。通过log-structured update、反规范化和物化视图的强支持以及强大的内置缓存,Cassandra的数据模型提供了方便的二级索引(column indexe)。

5. Hive

Apache Hive是Hadoop的一个数据仓库系统,促进了数据的综述(将结构化的数据文件映射为一张数据库表)、即席查询以及存储在Hadoop兼容系统中的大型数据集分析。Hive提供完整的SQL查询功能——HiveQL语言,同时当使用这个语言表达一个逻辑变得低效和繁琐时,HiveQL还允许传统的Map/Reduce程序员使用自己定制的Mapper和Reducer。

6. Pig

Apache Pig是一个用于大型数据集分析的平台,它包含了一个用于数据分析应用的高级语言以及评估这些应用的基础设施。Pig应用的闪光特性在于它们的结构经得起大量的并行,也就是说让它们支撑起非常大的数据集。Pig的基础设施层包含了产生Map-Reduce任务的编译器。Pig的语言层当前包含了一个原生语言——Pig Latin,开发的初衷是易于编程和保证可扩展性。

7. Chukwa

Apache Chukwa是个开源的数据收集系统,用以监视大型分布系统。建立于HDFS和Map/Reduce框架之上,继承了Hadoop的可扩展性和稳定性。Chukwa同样包含了一个灵活和强大的工具包,用以显示、监视和分析结果,以保证数据的使用达到最佳效果。

8. Ambari

Apache Ambari是一个基于web的工具,用于配置、管理和监视Apache Hadoop集群,支持Hadoop HDFS,、Hadoop MapReduce、Hive、HCatalog,、HBase、ZooKeeper、Oozie、Pig和Sqoop。Ambari同样还提供了集群状况仪表盘,比如heatmaps和查看MapReduce、Pig、Hive应用程序的能力,以友好的用户界面对它们的性能特性进行诊断。

9. ZooKeeper

Apache ZooKeeper是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护、命名服务、分布式同步、组服务等。ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。

10. Sqoop

Sqoop是一个用来将Hadoop和关系型数据库中的数据相互转移的工具,可以将一个关系型数据库中数据导入Hadoop的HDFS中,也可以将HDFS中数据导入关系型数据库中。

11. Oozie

Apache Oozie是一个可扩展、可靠及可扩充的工作流调度系统,用以管理Hadoop作业。Oozie Workflow作业是活动的Directed Acyclical Graphs(DAGs)。Oozie Coordinator作业是由周期性的Oozie Workflow作业触发,周期一般决定于时间(频率)和数据可用性。Oozie与余下的Hadoop堆栈结合使用,开箱即用的支持多种类型Hadoop作业(比如:Java map-reduce、Streaming map-reduce、Pig、 Hive、Sqoop和Distcp)以及其它系统作业(比如Java程序和Shell脚本)。

12. Mahout

Apache Mahout是个可扩展的机器学习和数据挖掘库,当前Mahout支持主要的4个用例:

  • 推荐挖掘:搜集用户动作并以此给用户推荐可能喜欢的事物。
  • 聚集:收集文件并进行相关文件分组。
  • 分类:从现有的分类文档中学习,寻找文档中的相似特征,并为无标签的文档进行正确的归类。
  • 频繁项集挖掘:将一组项分组,并识别哪些个别项会经常一起出现。

13. HCatalog

Apache HCatalog是Hadoop建立数据的映射表和存储管理服务,它包括:

  • 提供一个共享模式和数据类型机制。
  • 提供一个抽象表,这样用户就不需要关注数据存储的方式和地址。
  • 为类似Pig、MapReduce及Hive这些数据处理工具提供互操作性。

posted @ 2013-05-03 09:05 paulwong 阅读(503) | 评论 (0)编辑 收藏

HADOOP服务器

Centos集群服务器,公网ip
服务器地址
master: mypetsbj.xicp.net:13283
slave1 : mypetsbj.xicp.net:13282
slave2 : mypetsbj.xicp.net:13286

http://mypetsbj.xicp.net:13296
http://mypetsbj.xicp.net:13304
http://mypetsbj.xicp.net:14113
http://mypetsbj.xicp.net:11103

服务器开机时间
08:00 到 23:59 

opt/hadoop

用户名/密码
hadoop/wzp

posted @ 2013-05-01 00:02 paulwong 阅读(353) | 评论 (0)编辑 收藏

数字签名

     摘要: 处理流程: 假设有一份要传输的文档 使用某一指定算法将此文档内容进行计算,得出一字符串,称为“摘要” 使用私钥将此摘要进行加密,得出一字符串,称为“签名” 将私钥对应的公钥、摘要和签名一同发给对方 对方用公钥对签名进行解密,得出一字符串,与摘要对比,看是否符合,如符合,则证明对方身份确认...  阅读全文

posted @ 2013-04-26 16:22 paulwong 阅读(492) | 评论 (0)编辑 收藏

制作BAT/SH文件运行JAVA

WINDOWS版:
@ECHO OFF
REM @ECHO STARTUP App
REM @ECHO 设置环境变量,循环当前目录下的lib目录下所有jar文件,并设置CLASSPATH
FOR %%F IN (lib\*.jar) DO call :addcp %%F
goto extlibe
:addcp
SET CLASSPATH=%CLASSPATH%;%1
goto :eof
:extlibe
REM @ECHO 当前目录下的bin目录为class文件存放目录,设置bin目录到CLASSPATH中
SET CLASSPATH=%CLASSPATH%;bin\
REM @ECHO 显示CLASSPATH
REM SET CLASSPATH
REM @ECHO 运行应用程序
REM JAVA com.paul.socket.charge.client.ClientJFrame
start javaw com.paul.socket.charge.client.ClientJFrame

LINUX版:
#!/bin/sh

classpath=".:../classes/:../lib/*"
hdfs_input=hadoop/input
hdfs_output=hadoop/output0
mainclass=main.WordFinderMain
classesfolder=/job/classes

java -cp $classpath $mainclass $hdfs_input $hdfs_output $classesfolder

posted @ 2013-04-18 10:06 paulwong 阅读(386) | 评论 (0)编辑 收藏

一个PIG脚本例子分析

执行脚本:
PIGGYBANK_PATH=$PIG_HOME/contrib/piggybank/java/piggybank.jar
INPUT=pig/input/test-pig-full.txt
OUTPUT=pig/output/test-pig-output-$(date  +%Y%m%d%H%M%S)
PIGSCRIPT=analyst_status_logs.pig

#analyst_500_404_month.pig
#
analyst_500_404_day.pig
#
analyst_404_percentage.pig
#
analyst_500_percentage.pig
#
analyst_unique_path.pig
#
analyst_user_logs.pig
#
analyst_status_logs.pig


pig -p PIGGYBANK_PATH=$PIGGYBANK_PATH -p INPUT=$INPUT -p OUTPUT=$OUTPUT $PIGSCRIPT


要分析的数据源,LOG 文件
46.20.45.18 - - [25/Dec/2012:23:00:25 +0100] "GET / HTTP/1.0" 302 - "-" "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)" "-" "-" 46.20.45.18 "" 11011AEC9542DB0983093A100E8733F8 0
46.20.45.18 - - [25/Dec/2012:23:00:25 +0100] "GET /sign-in.jspx HTTP/1.0" 200 3926 "-" "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)" "-" "-" 46.20.45.18 "" 11011AEC9542DB0983093A100E8733F8 0
69.59.28.19 - - [25/Dec/2012:23:01:25 +0100] "GET / HTTP/1.0" 302 - "-" "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)" "-" "-" 69.59.28.19 "" 36D80DE7FE52A2D89A8F53A012307B0A 15


PIG脚本:
--注册JAR包,因为要用到DateExtractor
register '$PIGGYBANK_PATH';

--声明一个短函数名
DEFINE DATE_EXTRACT_MM 
org.apache.pig.piggybank.evaluation.util.apachelogparser.DateExtractor('yyyy-MM');

DEFINE DATE_EXTRACT_DD 
org.apache.pig.piggybank.evaluation.util.apachelogparser.DateExtractor('yyyy-MM-dd');

-- pig/input/test-pig-full.txt
--把数据从变量所指的文件加载到PIG中,并定义数据列名,此时的数据集为数组(a,b,c)
raw_logs = load '$INPUT' USING org.apache.pig.piggybank.storage.MyRegExLoader('^(\\S+) (\\S+) (\\S+) \\[([\\w:/]+\\s[+\\-]\\d{4})\\] "(\\S+) (\\S+) (HTTP[^"]+)" (\\S+) (\\S+) "([^"]*)" "([^"]*)" "(\\S+)" "(\\S+)" (\\S+) "(.*)" (\\S+) (\\S+)')
as (remoteAddr: chararray, 
n2: chararray, 
n3: chararray, 
time: chararray, 
method: chararray,
path:chararray,
protocol:chararray,
status: int, 
bytes_string: chararray, 
referrer: chararray, 
browser: chararray, 
n10:chararray,
remoteLogname: chararray, 
remoteAddr12: chararray, 
path2: chararray, 
sessionid: chararray, 
n15: chararray
);

--过滤数据
filter_logs = FILTER raw_logs BY not (browser matches '.*pingdom.*');
--item_logs = FOREACH raw_logs GENERATE browser;

--percent 500 logs
--重定义数据项,数据集只取2项status,month
reitem_percent_500_logs = FOREACH filter_logs GENERATE status,DATE_EXTRACT_MM(time) as month;
--分组数据集,此时的数据结构为MAP(a{(aa,bb,cc),(dd,ee,ff)},b{(bb,cc,dd),(ff,gg,hh)})
group_month_percent_500_logs = GROUP reitem_percent_500_logs BY (month);
--重定义分组数据集数据项,进行分组统计,此时要联合分组数据集和原数据集统计
final_month_500_logs = FOREACH group_month_percent_500_logs 
{
    --对原数据集做count,因为是在foreachj里做count的,即使是对原数据集,也会自动会加month==group的条件
    --从这里可以看出对于group里的数据集,完全没用到
    --这时是以每一行为单位的,统计MAP中的KEY-a对应的数组在原数据集中的个数
    total = COUNT(reitem_percent_500_logs);
    --对原数据集做filter,因为是在foreachj里做count的,即使是对原数据集,也会自动会加month==group的条件
    --重新过滤一下原数据集,得到status==500,month==group的数据集
    t = filter reitem_percent_500_logs by status== 500; --create a bag which contains only T values
    --重定义数据项,取group,统计结果
    generate flatten(group) as col1, 100*(double)COUNT(t)/(double)total;
}
STORE final_month_500_logs into '$OUTPUT' using PigStorage(',');

posted @ 2013-04-13 15:21 paulwong 阅读(2309) | 评论 (0)编辑 收藏

大对象XML读写

I am using JAXB and I have a large set of data which i have to marshal into a xml.Since marshalling the whole thing into xml in a single step will be using most of the memory , i want to split it into parts and write to the xml file incremently

For example if my generated output xml should be like this:
<Employees>
<employee>......</employee>
<employee>.....</employee>
<employee>.....</employee>
<employee>.....</employee>
..
...
..
</Employees>

I would like to write the <employee> sections separately into a file instead of writing the whole thing together.I am retrieving the employee details from the database and converting to xml.There are almost 8 lakh records.So marshalling the whole thing in single step will use up my memory.How can i do it?????


Use Stax API (XMLStreamWriter) as the underlying XML processing thing;
write <Employees> tag using that, and then pass XMLStreamWriter to
JAXB Marshaller, marshall employee by employee.
This is the pattern I use; similarly works well with unmarshalling.
Not sure if this is in FAQ or not, but it probably should be. 

posted @ 2013-04-12 19:18 paulwong 阅读(273) | 评论 (0)编辑 收藏

把命令行中的值传进PIG中

http://wiki.apache.org/pig/ParameterSubstitution


%pig -param input=/user/paul/sample.txt -param output=/user/paul/output/


PIG中获取
records = LOAD $input;

posted @ 2013-04-10 15:32 paulwong 阅读(347) | 评论 (0)编辑 收藏

PIG中的分组统计百分比

http://stackoverflow.com/questions/15318785/pig-calculating-percentage-of-total-for-a-field

http://stackoverflow.com/questions/13476642/calculating-percentage-in-a-pig-query

posted @ 2013-04-10 14:13 paulwong 阅读(397) | 评论 (0)编辑 收藏

CombinedLogLoader

PIG中的LOAD函数,可以在LOAD数据的同时,进行正则表达式的筛选。

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the
 * NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF
 * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the License at
 * 
 * 
http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 
*/

package org.apache.pig.piggybank.storage.apachelog;

import java.util.regex.Pattern;

import org.apache.pig.piggybank.storage.RegExLoader;

/**
 * CombinedLogLoader is used to load logs based on Apache's combined log format, based on a format like
 * 
 * LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
 * 
 * The log filename ends up being access_log from a line like
 * 
 * CustomLog logs/combined_log combined
 * 
 * Example:
 * 
 * raw = LOAD 'combined_log' USING org.apache.pig.piggybank.storage.apachelog.CombinedLogLoader AS
 * (remoteAddr, remoteLogname, user, time, method, uri, proto, status, bytes, referer, userAgent);
 * 
 
*/

public class CombinedLogLoader extends RegExLoader {
    // 1.2.3.4 - - [30/Sep/2008:15:07:53 -0400] "GET / HTTP/1.1" 200 3190 "-"
    
// "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1"
    private final static Pattern combinedLogPattern = Pattern
        .compile("^(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+.(\\S+\\s+\\S+).\\s+\"(\\S+)\\s+(.+?)\\s+(HTTP[^\"]+)\"\\s+(\\S+)\\s+(\\S+)\\s+\"([^\"]*)\"\\s+\"(.*)\"$");

    public Pattern getPattern() {
        return combinedLogPattern;
    }
}

posted @ 2013-04-08 11:28 paulwong 阅读(285) | 评论 (0)编辑 收藏

Analyzing Apache logs with Pig



Analyzing log files, churning them and extracting meaningful information is a potential use case in Hadoop. We don’t have to go in for MapReduce programming for these analyses; instead we can go for tools like Pig and Hive for this log analysis. I’d just give you a start off on the analysis part. Let us consider Pig for apache log analysis. Pig has some built in libraries that would help us load the apache log files into pig and also some cleanup operation on string values from crude log files. All the functionalities are available in the piggybank.jar mostly available under pig/contrib/piggybank/java/ directory. As the first step we need to register this jar file with our pig session then only we can use the functionalities in our Pig Latin
1.       Register PiggyBank jar
REGISTER /usr/lib/pig/contrib/piggybank/java/piggybank.jar;
Once we have registered the jar file we need to define a few functionalities to be used in our Pig Latin. For any basic apache log analysis we need a loader to load the log files in a column oriented format in pig, we can create a apache log loader as
2.       Define a log loader
DEFINE ApacheCommonLogLoader org.apache.pig.piggybank.storage.apachelog.CommonLogLoader();
(Piggy Bank has other log loaders as well)
In apache log files the default format of date is ‘dd/MMM/yyyy:HH:mm:ss Z’ . But such a date won’t help us much in case of log analysis we may have to extract date without time stamp. For that we use DateExtractor()
3.       Define Date Extractor
DEFINE DayExtractor org.apache.pig.piggybank.evaluation.util.apachelogparser.DateExtractor('yyyy-MM-dd');
Once we have the required functionalities with us we need to first load the log file into pig
4.       Load apachelog file into pig
--load the log files from hdfs into pig using CommonLogLoader
logs = LOAD '/userdata/bejoys/pig/p01/access.log.2011-01-01' USING ApacheCommonLogLoader AS (ip_address, rfc, userId, dt, request, serverstatus, returnobject, referersite, clientbrowser);
Now we are ready to dive in for the actual log analysis. There would be multiple information you need to extract out of a log; we’d see a few of those common requirements out here
Note: you need to first register the jar, define the classes to be used and load the log files into pig before trying out any of the pig latin below
Requirement 1: Find unique hits per day
PIG Latin
--Extracting the day alone and grouping records based on days
grpd = GROUP logs BY DayExtractor(dt) as day;
--looping through each group to get the unique no of userIds
cntd = FOREACH grpd
{
                tempId =  logs.userId;
                uniqueUserId = DISTINCT tempId;
                GENERATE group AS day,COUNT(uniqueUserId) AS cnt;
}
--sorting the processed records based on no of unique user ids in descending order
srtd = ORDER cntd BY cnt desc;
--storing the final result into a hdfs directory
STORE srtd INTO '/userdata/bejoys/pig/ApacheLogResult1';
Requirement 1: Find unique hits to websites (IPs) per day
PIG Latin
--Extracting the day alone and grouping records based on days and ip address
grpd = GROUP logs BY (DayExtractor(dt) as day,ip_address);
--looping through each group to get the unique no of userIds
cntd = FOREACH grpd
{
                tempId =  logs.userId;
                uniqueUserId = DISTINCT tempId;
                GENERATE group AS day,COUNT(uniqueUserId) AS cnt;
}
--sorting the processed records based on no of unique user ids in descending order
srtd = ORDER cntd BY cnt desc;
--storing the final result into a hdfs directory
STORE srtd INTO '/userdata/bejoys/pig/ ApacheLogResult2 ';
Note: When you use pig latin in grunt shell we need to know a few factors
1.       When we issue a pig statement in grunt and press enter only the semantic check is being done, no execution is triggered.
2.       All the pig statements are executed only after the STORE command is submitted, ie map reduce programs would be triggered only after STORE is submitted
3.       Also in this case you don’t have to load the log files again and again to pig once it is loaded we can use the same for all related operations in that session. Once you are out of the grunt shell the loaded files are lost, you’d have to perform the register and log file loading steps all over again.

posted @ 2013-04-08 02:06 paulwong 阅读(357) | 评论 (0)编辑 收藏

仅列出标题
共115页: First 上一页 67 68 69 70 71 72 73 74 75 下一页 Last