你当然可以创建一个定期运行,并呼吁
hdfs dfs -copyToLocal <src> <dest>
到所有数据从HDFS复制bash脚本。
或者使用Hadoop的文件系统的Java API以流从Hadoop的数据创建一个输入流:
public static FileSystem getFS(String hadoopUser) {
UserGroupInformation ugi = UserGroupInformation
.createRemoteUser(hadoopUser);
return ugi.doAs(new PrivilegedAction<FileSystem>() {
@Override
public FileSystem run() {
Configuration conf = new Configuration();
try {
return FileSystem.get(conf);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
});
return null;
}
然后......
FileSystem fs = getFS("hdfs");
InputStream in = fs.open(new Path("/path/to/hdfs/file"));
//do stuff with your input stream here...
关于获取数据到elasticsearch,你可以这样做类似于Netflix用inviso做的事情(在github中搜索inviso并查看jes/index_cluster_stats.py以获得想法)。基本上,编写一个与elasticsearch集成的python脚本,并每隔几分钟运行一次脚本,以解析从HDFS中提取的数据,然后将这些数据存储在elasticsearch中。