在CentOS上进行HDFS日志分析,可以按照以下步骤进行:
curl -L https://td-toolbelt.herokuapp.com/sh/install-redhat-td-agent2.sh | sh
/etc/td-agent/td-agent.conf
),添加WebHDFS输出插件配置:<source>
@type tail
path /var/log/mytemp.log
pos_file /var/log/td-agent/mytemp.log.pos
format none
tag td.temp
</source>
<match td.temp>
type webhdfs
host namenodehost
port 50070
path /logs/%Y/%m/%d/access.log
flush_interval 5s
</match>
service td-agent start
/var/log/Bigdata/hdfs/
目录下,并且有自动压缩和归档功能。public class LogAnalyzer {
public static class LogMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text ip = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
String[] fields = line.split("\t");
String ipAddress = fields[0];
ip.set(ipAddress);
context.write(ip, one);
}
}
public static class LogReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "Log Analyzer");
job.setJarByClass(LogAnalyzer.class);
job.setMapperClass(LogMapper.class);
job.setCombinerClass(LogReducer.class);
job.setReducerClass(LogReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path("/logs/*/*/*"));
FileOutputFormat.setOutputPath(job, new Path("/output"));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
hadoop jar loganalyzer.jar LogAnalyzer /logs/*/*/* /output
hadoop fs -cat /output/part-r-00000
journalctl -f
journalctl -r
journalctl -k
journalctl -u hadoop-hdfs
/etc/logrotate.conf
/etc/logrotate.d/hadoop
文件,添加HDFS相关配置。通过以上步骤,你可以在CentOS上有效地收集、存储和分析HDFS日志,从而更好地监控和优化HDFS集群的性能和可靠性。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:Java日志分析在CentOS上怎么做