一、概述最近開始著手高校雲平台的搭建,前些天做了hadoop叢集測試環境的安裝與配置的經驗分享,
這篇文章主要介紹win7 64位下 eclipse4.2 串連遠程Redhat Linux 5下hadoop-1.2.0叢集開發環境搭建二、環境1、window 7 64位2、eclipse 4.23、Redhat Linux 54、hadoop-1.2.0三、安裝配置hadoop叢集參考我的文章:http://blog.csdn.net/shan9liang/article/details/9841933http://www.jialinblog.com/?p=176 四、在Eclipse下安裝配置hadoop外掛程式1、編譯Eclipse-hadoop外掛程式參考:http://www.cnblogs.com/chenying99/archive/2013/05/31/3109566.html2、安裝安裝外掛程式就很簡單了,把上面編譯的外掛程式檔案放到 Eclipse的安裝目錄下的plugins,重新啟動Eclipse3、配置(1)將hadoop解壓到windows檔案系統的某個目錄中(2) 開啟Eclipse,設定好workspace
開啟Window-->Preferens,你會發現Hadoop Map/Reduce選項,在這個選項裡你需要配置Hadoop installation directory。配置完成後退出。
(3)選擇window -> open perspective -> Other... , 選擇有大象表徵圖的 Map/Reduce,此時,就開啟了Map/Reduce的開發環境。可以看到,右下角多了一個Map/Reduce Locations的框。如
建立,在開啟的視窗中輸入:
Location Name : 此處為參數設定名稱,可以任意填寫
Map/Reduce Master (此處為Hadoop叢集的Map/Reduce地址,應該和mapred-site.xml中的mapred.job.tracker設定相同)
DFS Master (此處為Hadoop的master伺服器位址,應該和core-site.xml中的 fs.default.name 設定相同)
設定完成後,點擊Finish就應用了該設定。
此時,在最左邊的Project Explorer中就能看到DFS的目錄,如所示。
配置完畢五、測試建立項目:File-->New-->Other-->Map/Reduce Project ,項目名可以隨便取,如hadoop_test_01它會自動添加依賴包,如下:
可以運行hadoop內建的wordcount執行個體/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.jialin.hadoop;import java.io.IOException;import java.util.StringTokenizer;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.Job;import org.apache.hadoop.mapreduce.Mapper;import org.apache.hadoop.mapreduce.Reducer;import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import org.apache.hadoop.util.GenericOptionsParser;public class WordCount { public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable>{ private final static IntWritable one = new IntWritable(1); private Text word = new Text(); public void map(Object key, Text value, Context context ) throws IOException, InterruptedException { StringTokenizer itr = new StringTokenizer(value.toString()); while (itr.hasMoreTokens()) { word.set(itr.nextToken()); context.write(word, one); } } } public static class IntSumReducer 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(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: wordcount <in> <out>"); System.exit(2); } Job job = new Job(conf, "word count"); job.setJarByClass(WordCount.class); job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumReducer.class); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); }}運行時參數設定:右擊wordcount,選擇run as - run configurations
參數根據自己實際情況input目錄下有兩個檔案input1和input2,內容分別為:hello world,hello hadoopoutput目錄不用手動建立。運行:右擊wordcount-run as -run on hadoop運行成功,查看output中的檔案內容hello 2hadoop 1world 1 註:測試中遇到問題的解決方式解決許可權問題1、hadoop許可權如果當前登入windows的使用者名稱和hadoop叢集的使用者名稱不一致,將沒有許可權訪問,會報錯 目前做法是開發時將hadoop服務叢集關閉許可權認證,正式發布時,可以在伺服器建立一個和hadoop叢集使用者名稱一致的使用者,即可不用修改master的permissions策略。詳細參考我的文章:http://blog.csdn.net/shan9liang/article/details/9734693
http://www.jialinblog.com/?p=172 2、windows下0700問題這個問題真是糾結了我好幾天,最後修還hadoop源碼hadoop-core-1.2.0.jar中的FileUtil,重新編譯 hadoop-core-1.2.0.jar ,替換掉原來的。才得以解決詳細參考我的文章:http://blog.csdn.net/shan9liang/article/details/9734677http://www.jialinblog.com/?p=174 七、總結至此高校雲平台的hadoop叢集基本開發環境已經出來了,剩下的就是在此基礎上進行豐富了。如果是簡單的測試,推薦使用單機hadoop方式,或者偽分布式。我之所以不選擇單機或偽分布式,只是想儘可能地類比真實環境。大家按需選擇吧。