系列文章目录
Flume+HBase+Kafka集成数据采集/存储/分发完整流程测试
一、说明
两个flume节点采集slave1,slave2应用服务器,汇总在master上的flume,然后master上flume分为两端传递数据,一端是传递给Kafka,一端是传递给HBase,之前各个组件的配置我都已经总结好,详细请看上面的几篇文章,这一篇文章主要是对整个数据采集存储、分发做一个详细的测试。
二、应用服务模拟器程序开发
新建一个普通项目编写代码
将这个代码打包上传到master
package com.builddata.jar;
import java.io.*;
public class LogReadAndWriter {
private static String readFileName;
private static String writeFileName;
public static void main(String[] args) {
readFileName = args[0];
writeFileName = args[1];
try {
// readInput()
readFileByLines(readFileName);
}catch (Exception e){
}
}
public static void readFileByLines(String filename){
FileInputStream fis = null;
InputStreamReader isr = null;
BufferedReader br = null;
String tempString = null;
try{
System.out.println("以行为单位读取文件内容,一次读一整行:");
fis = new FileInputStream(filename);
// 从文件系统中的某个文件中获取字节
isr = new InputStreamReader(fis,"GBK");
br = new BufferedReader(isr);
int count = 0;
while ((tempString = br.readLine()) != null){
count++;
// 显示符号
Thread.sleep(100);
String str = new String(tempString.getBytes("UTF8"),"GBK");
System.out.println("row:"+count+">>>>>>>>>>"+tempString);
method1(writeFileName,tempString);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if (isr != null){
try{
isr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void method1(String file, String content){
BufferedWriter out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file,true)));
out.write("\n");
out.write(content);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
在usr新建jars包
mkdir -p jars
将文件拷贝到jars目录下面
cp weblogs.jar /usr/jars
分发到其他两台服务器上去:
scp -r weblogs.jar slave1: /usr/jars
scp -r weblogs.jar slave2: /usr/jars
回到master中编写启动脚本: