是否有将Web资源下载到hdfs的命令?

时间:2014-03-05 04:05:47

标签: hadoop hdfs

我想写一个用于将web资源推送到hadoop的程序。我使用hadoop 2.2.0,发现'put'不能像这样工作:

hadoop fs -put http://localhost/test.log hdfs://localhost:9000/log/ 

有没有办法将文件放到hdfs,而不先下载它?

PS:假设我没有为hadoop服务器和网络资源服务器做好准备。

3 个答案:

答案 0 :(得分:5)

如Jigar建议的那样管理文件:

curl http://stackoverflow.com/questions/22188311/is-there-a-command-for-downloading-a-web-resource-to-hdfs | hadoop fs -appendToFile - question.html

从技术上讲,这个用例需要一个独特的“客户端”,它作为一个单独的流连接到远程URL并将其内容泵入HDFS。可以直接从一个HDFS数据节点执行该命令,以避免使字节转移到补充客户端主机。无论如何,在下载时HDFS节点之间的网络通信是无法避免的,因为文件将物理地存储在多个节点中。

答案 1 :(得分:0)

我认为你可以使用linux管道和curl下载文件并将文件存储到hdfs

答案 2 :(得分:0)

通过使用curl,我们可以将数据存储到HDFS中。使用Java

查看以下示例
public static void main(String[] args) throws IOException {
      URL url = new URL("http://example.com/feed/csv/month");
      HttpURLConnection conn = (HttpURLConnection)url.openConnection();
      conn.connect();
      InputStream connStream = conn.getInputStream();

      FileSystem hdfs = FileSystem.get(new Configuration());
      FSDataOutputStream outStream = hdfs.create(new Path(args[0], "month.txt"));
      IOUtils.copy(connStream, outStream);

      outStream.close();
      connStream.close();
      conn.disconnect();
}
相关问题