說明:hadoop安裝,一共有三種部署方式,分別是本地部署、僞分佈部署、集羣部署。這裏咱們以僞分佈模式爲例進行講解。java
軟件:Myeclipse-2014-GA,hadoop-2.5.1.tar.gz,hadoop-eclipse-plugin-2.5.0.jarapache
軟件下載地址:連接: http://pan.baidu.com/s/1ntuUhux 密碼: stokeclipse
一、首先把hadoop-eclipse-plugin-2.5.0.jar拷貝到Myeclipse的插件目錄裏面ide
二、啓動myeclipse,而後看看插件是否安裝成功oop
三、配置插件信息,如圖所示:spa
注:Host是集羣主機IP,port:50020是默認的,右邊Port是集羣core-site.xml裏面配置的信息插件
四、配置完成以後,新建一個項目,這裏我建的是java項目code
1 package hadoop; 2 3 import java.io.IOException; 4 import java.text.DateFormat; 5 import java.util.Date; 6 7 import org.apache.hadoop.conf.Configuration; 8 import org.apache.hadoop.fs.FileStatus; 9 import org.apache.hadoop.fs.FileSystem; 10 import org.apache.hadoop.fs.Path; 11 12 public class HadoopTest { 13 public static void main(String[] args) throws IOException { 14 System.out.println("12"); 15 Configuration conf = new Configuration(); 16 conf.set("fs.defaultFS", "hdfs://192.168.0.204:9000"); 17 FileSystem fs = FileSystem.get(conf); 18 FileStatus[] s = fs.listStatus(new Path("/")); 19 for (int i = 0; i < s.length; i++) { 20 FileStatus f = s[i]; 21 System.out.println(f.getPath().getName()); 22 System.out.println(f.getLen()); 23 System.out.println(f.getModificationTime()); 24 Date date = new Date(f.getModificationTime()); 25 String d = DateFormat.getDateInstance().format(date); 26 System.out.println(d); 27 } 28 fs.close(); 29 } 30 }
五、成功運行以後,會顯示從集羣裏面獲取的文件信息orm