设为首页 收藏本站
查看: 2136|回复: 0

[经验分享] 日志系统搭建一(flume+hadoop+hive)

[复制链接]

尚未签到

发表于 2015-11-27 20:45:56 | 显示全部楼层 |阅读模式
  由于公司现在业务日志量逐渐增加,一台服务器io满足不了需求,打在多台服务器上面,准备搭建一个简单日志系统。
  
许多公司的平台每天会产生大量的日志(一般为流式数据,如,搜索引擎的pv,查询等),处理这些日志需要特定的日志系统,一般而言,这些系统需要具有以下特征:
(1) 构建应用系统和分析系统的桥梁,并将它们之间的关联解耦;
(2) 支持近实时的在线分析系统和类似于Hadoop之类的离线分析系统;
(3) 具有高可扩展性。即:当数据量增加时,可以通过增加节点进行水平扩展。
本文从设计架构,负载均衡,可扩展性和容错性等方面对比了当今开源的日志系统,包括facebook的scribe,apache的chukwa,linkedin的kafka和cloudera的flume等。

下面表格对比了这四个系统:
DSC0000.jpg

通过对比分析,选用了flume,主要安装简单,易配置,功能强大。flume的安装就不说了。
主要遇到一个配置问题,日志要求按照天归类,很多网友都会有这个问题,我解决方法如下:
1.下载flume 1.3.1版本
2.配置文件如下
#Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
#a1.sources.testtail.interceptors = i1
#a1.sources.testtail.interceptors.i1.type = org.apache.flume.interceptor.TimestampInterceptor$Builder


# Describe/configure the source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /data_disk/logs/flume/
a1.sources.r1.fileHeader = false
a1.sources.r1.interceptors = i1
a1.sources.r1.interceptors.i1.type = timestamp
#a1.sources.r1.command = tail -F  /data_disk/logs/2014-05-11.txt
#a1.sources.r1.port = 44444


#Describe the sink
#a1.sinks.k1.type = logger
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
a1.sinks.k1.hdfs.path = hdfs://10.160.0.237:9000/flume/%Y-%m-%d/
a1.sinks.k1.hdfs.filePrefix = update.u.gsie.cn_
a1.sinks.k1.hdfs.fileType = DataStream
a1.sinks.k1.hdfs.rollInterval = 1
#a1.sinks.k1.hdfs.roundValue = 1
a1.sinks.k1.hdfs.writeFormat = Text
#a1.sinks.k1.hdfs.useLocalTimeStamp = true


#Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100


#Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

3.hadoop安装以及配置
参照网上配置即可
4.hadoop程序编写
cd /data_disk/hadoop_code/

mkdir -p FirstJar/class
cd FirstJar
  vim WordCount,java


  • package test;

  • import java.io.IOException;
  • import java.util.*;

  • import org.apache.hadoop.fs.Path;
  • import org.apache.hadoop.conf.*;
  • import org.apache.hadoop.io.*;
  • import org.apache.hadoop.mapreduce.*;
  • import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  • import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
  • import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  • import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

  • public class WordCount{
  •     public static class Map extends Mapper<LongWritable, Text, Text,IntWritable> {
  •         private final static IntWritableone = new IntWritable(1);
  •         private Text word= new Text();

  •         public void map(LongWritablekey, Text value, Context context) throws IOException, InterruptedException {
  •             String line= value.toString();
  •             StringTokenizer tokenizer= new StringTokenizer(line);
  •             while (tokenizer.hasMoreTokens()) {
  •                 word.set(tokenizer.nextToken());
  •                 context.write(word, one);
  •             }
  •         }
  •     }

  •     public static class Reduce extends Reducer<Text,IntWritable, Text,IntWritable> {
  •         public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
  •             int sum = 0;
  •             for (IntWritable val : values) {
  •                 sum &#43;= val.get();
  •             }
  •             context.write(key, new IntWritable(sum));
  •         }
  •     }

  •     public static void main(String[] args) throws Exception {
  •         Configuration conf= new Configuration();

  •         Job job = new Job(conf, &quot;wordcount&quot;);

  •         job.setJarByClass(WordCount.class);   // &#43;&#43;&#43;&#43;&#43;
  •         job.setOutputKeyClass(Text.class);
  •         job.setOutputValueClass(IntWritable.class);

  •         job.setMapperClass(Map.class);
  •         job.setReducerClass(Reduce.class);

  •         job.setInputFormatClass(TextInputFormat.class);
  •         job.setOutputFormatClass(TextOutputFormat.class);

  •         FileInputFormat.addInputPath(job, new Path(args[0]));
  •         FileOutputFormat.setOutputPath(job, new Path(args[1]));

  •         job.waitForCompletion(true);
  •     }
  • }hadoop 输入文件:
vim file01  
hello world by world

vim file02
hello hadoop by hadoop

vim input.txt
world 1 2 3 ii pp world hadoop 1 hadoop

hadoop dfs -put input.txt input

hadoop dfs -put file0* input

javac -classpath /data_disk/software/hadoop/hadoop-core-1.2.1.jar -d class WordCount.java

jar -cvf wordcount.jar -C class .
hadoop jar wordcount.jar test.WordCount input output

hadoop dfs -ls output
Found 3 items
-rw-r--r--   3 root supergroup          0 2014-05-18 17:54 /user/root/output/_SUCCESS
drwxr-xr-x   - root supergroup          0 2014-05-18 17:53 /user/root/output/_logs
-rw-r--r--   3 root supergroup         39 2014-05-18 17:54 /user/root/output/part-r-00000

hadoop dfs -ls output/part-r-00000

5.hive
利用hive把log数据导入表中,统计计算

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-144377-1-1.html 上篇帖子: flume搭建调试 下篇帖子: (2) flume 入门学习 HelloWorld 及HDFS 遇到的问题 总结
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表