??xml version="1.0" encoding="utf-8" standalone="yes"?>首页国产欧美久久,2019中文字幕在线视频,九九视频直播综合网http://www.aygfsteel.com/wangxinsh55/category/53334.htmlzh-cnTue, 16 Sep 2014 21:04:32 GMTTue, 16 Sep 2014 21:04:32 GMT60(?Hadoop 解除 "Name node is in safe mode" http://www.aygfsteel.com/wangxinsh55/archive/2013/03/28/397110.htmlSIMONESIMONEThu, 28 Mar 2013 08:55:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2013/03/28/397110.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/397110.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2013/03/28/397110.html#Feedback0http://www.aygfsteel.com/wangxinsh55/comments/commentRss/397110.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/397110.htmlhttp://39382728.blog.163.com/blog/static/35360069201182710565420/

q行hadoopE序Ӟ 中途我把它l止了,然后再向hdfs加文件或删除文gӞ出现Name node is in safe mode错误Q?br />rmr: org.apache.hadoop.dfs.SafeModeException: Cannot delete /user/hadoop/input. Name node is in safe mode

解决的命令:

bin/hadoop dfsadmin -safemode leave #关闭safe mode


转自Q?nbsp;http://shutiao2008.iteye.com/blog/318950

 

?安全模式 学习Q?/p> safemode模式
NameNode在启动的时候首先进入安全模式,如果datanode丢失的block辑ֈ一定的比例Q?-dfs.safemode.threshold.pctQ,则系l会一直处于安全模式状态即只读状态?br />dfs.safemode.threshold.pctQ缺省?.999fQ表CHDFS启动的时候,如果DataNode上报的block个数辑ֈ了元数据记录的block个数?.999倍才可以d安全模式Q否则一直是q种只读模式。如果设?则HDFS永远是处于SafeMode?br />下面q行摘录自NameNode启动时的日志Qblock上报比例1辑ֈ了阀?.9990Q?br />The ratio of reported blocks 1.0000 has reached the threshold 0.9990. Safe mode will be turned off automatically in 18 seconds.
hadoop dfsadmin -safemode leave
有两个方法离开q种安全模式
1. 修改dfs.safemode.threshold.pctZ个比较小的|~省?.999?br />2. hadoop dfsadmin -safemode leave命o强制d
http://bbs.hadoopor.com/viewthread.php?tid=61&extra=page%3D1
Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q?br />Safe mode is exited when the minimal replication condition is reached, plus an extension
time of 30 seconds. The minimal replication condition is when 99.9% of the blocks in
the whole filesystem meet their minimum replication level (which defaults to one, and
is set by dfs.replication.min).
安全模式的退出前?- 整个文gpȝ中的99.9%Q默认是99.9%Q可以通过dfs.safemode.threshold.pct讄Q的Blocks辑ֈ最备份?默认?Q可以通过dfs.replication.min讄)?br />dfs.safemode.threshold.pct      float       0.999
The proportion of blocks in the system that must meet the minimum
replication level defined by dfs.rep lication.min before the namenode
will exit safe mode. Setting
this value to 0 or less forces the name-node not to start in safe mode.
Setting this value to more than 1 means the namenode never exits safe
mode.
Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q?br />用户可以通过dfsadmin -safemode value  来操作安全模式,参数value的说明如下:
enter - q入安全模式
leave - 强制NameNoded安全模式
get -  q回安全模式是否开启的信息
wait - {待Q一直到安全模式l束?/div>

SIMONE 2013-03-28 16:55 发表评论
]]>hadoop集群处理http://www.aygfsteel.com/wangxinsh55/archive/2013/03/28/397108.htmlSIMONESIMONEThu, 28 Mar 2013 08:29:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2013/03/28/397108.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/397108.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2013/03/28/397108.html#Feedback0http://www.aygfsteel.com/wangxinsh55/comments/commentRss/397108.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/397108.html详细内容查看q个
http://www.cnblogs.com/xia520pi/
q个博客的内?/div>

SIMONE 2013-03-28 16:29 发表评论
]]>
成功~译hadoop eclipse插g。此方式适用于win 7http://www.aygfsteel.com/wangxinsh55/archive/2013/03/28/397107.htmlSIMONESIMONEThu, 28 Mar 2013 08:26:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2013/03/28/397107.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/397107.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2013/03/28/397107.html#Feedback0http://www.aygfsteel.com/wangxinsh55/comments/commentRss/397107.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/397107.html

 

http://www.07net01.com/linux/tongguoeclipsexiangmubianyi_hadoop_1_0_3_eclipse_4_2___juno___plugin_20146_1350034161.html

 


程如下Q?/p>

1.下蝲hadoop 1.0.3 Qhttp://hadoop.apache.org/releases.html#DownloadQ,解压在自定义的一个目录中Q最好全英文路径Q试q中文\径出了问题)?/p>

2.Eclipse导入..\hadoop-1.0.3\src\contrib\eclipse-plugin目Q默认项目是MapReduceTools?/p>

3. 在项目MapReduceTools中新建lib目录Qƈ把hadoop的hadoop-coreQ由hadoop根目录的hadoop-*.jar改名 获得Q、commons-cli-1.2.jar、commons-lang-2.4.jar、commons-configuration- 1.6.jar、jackson-mapper-asl-1.8.8.jar、jackson-core-asl-1.8.8.jar、commons- httpclient-3.0.1.jar拯到该目录?/p>

4.修改上目录中的build-contrib.xmlQ?/p>

扑ֈ<property name="hadoop.root" location="${root}/../../../"/>修改location为hadoop1.0.3实际解压目录Q在其下d

<property name="eclipse.home" location="D:/Program Files/eclipse"/>

<property name="version" value="http://x-goder.iteye.com/blog/1.0.3"/>

5.修改目目录下的build.xmlQ?/p>

<target name="jar" depends="compile" unless="skip.contrib">

<mkdir dir="${build.dir}/lib"/>

<copy file="${hadoop.root}/hadoop-core-${version}.jar" tofile="${build.dir}/lib/hadoop-core.jar" verbose="true"/>

<copy file="${hadoop.root}/lib/commons-cli-1.2.jar" todir="${build.dir}/lib" verbose="true"/>

<copy file="${hadoop.root}/lib/commons-lang-2.4.jar" todir="${build.dir}/lib" verbose="true"/>

<copy file="${hadoop.root}/lib/commons-configuration-1.6.jar" todir="${build.dir}/lib" verbose="true"/>

<copy file="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar" todir="${build.dir}/lib" verbose="true"/>

<copy file="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar" todir="${build.dir}/lib" verbose="true"/>

<copy file="${hadoop.root}/lib/commons-httpclient-3.0.1.jar" todir="${build.dir}/lib" verbose="true"/>

<jar

jarfile="${build.dir}/hadoop-${name}-${version}.jar"

manifest="${root}/META-INF/MANIFEST.MF">

<fileset dir="${build.dir}" includes="classes/ lib/"/>

<fileset dir="${root}" includes="resources/ plugin.xml"/>

</jar>

</target>

6.右键eclipse里的build.xml选择run as - ant build?/p>

如果出现Q?#8220;软g包org.apache.hadoop.fs 不存?#8221;的错误则修改build.xmlQ?/p>

<path id="hadoop-jars">

<fileset dir="${hadoop.root}/">

<include name="hadoop-*.jar"/>

</fileset>

</path>

?lt;path id="classpath">中添加:<path refid="hadoop-jars"/>

7.{Ant~译完毕后。编译后的文件在Q\build\contrib 中的 hadoop-eclipse-plugin-1.0.3.jar?/p>

8.查看~译好的jar包下META-INF/MANIFEST.MF 下的配置属性是否完_如果不完_补充完整?/p>

Bundle-ClassPath: classes/,lib/hadoop-core.jar,lib/commons-cli-1.2.jar
 ,lib/commons-lang-2.4.jar,lib/commons-configuration-1.6.jar,lib/jacks
 on-mapper-asl-1.8.8.jar,lib/jackson-core-asl-1.8.8.jar,lib/commons-ht
 tpclient-3.0.1.jar

9.攑օeclipse/plugins下,重启eclipseQ查看是否安装成功?/p>



SIMONE 2013-03-28 16:26 发表评论
]]>
在HBase里用MapReduce例子http://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395572.htmlSIMONESIMONEFri, 22 Feb 2013 06:12:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395572.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/395572.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395572.html#Feedback0http://www.aygfsteel.com/wangxinsh55/comments/commentRss/395572.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/395572.htmlhttp://jeffxie.blog.51cto.com/1365360/305538
我在Hadoop的用户邮件列表中看到一些国内的?户在讯问一些关于如何操作的HBase?span >问题Q还看到了HBase中没有Example。觉得有 必要跟大?span >分n自己的经验?br /> 在下面的例子中我们分?span >Apache的logq把q些logq行分析q把分析?的结果按用户IP为ROWQ把log中用L讉K旉Q请求方法,用户h的协议,用户的浏览器Q服务状态等写到HBase的表中?br />

首先我们要在HBase中徏立我们的一个表来存?span >数据?nbsp; 
  1. public static void creatTable(String table) throws IOException{
  2.             HConnection conn = HConnectionManager.getConnection(conf);
  3.             HBaseAdmin admin = new HBaseAdmin(conf);
  4.             if(!admin.tableExists(new Text(table))){
  5.               System.out.println("1. " + table + " table creating ... please wait");
  6.               HTableDescriptor tableDesc = new HTableDescriptor(table);
  7.               tableDesc.addFamily(new HColumnDescriptor("http:"));
  8.               tableDesc.addFamily(new HColumnDescriptor("url:"));
  9.               tableDesc.addFamily(new HColumnDescriptor("referrer:"));
  10.               admin.createTable(tableDesc);
  11.             } else {
  12.               System.out.println("1. " + table + " table already exists.");
  13.             }
  14.             System.out.println("2. access_log files fetching using map/reduce");
  15.   }
复制代码

然后我们q行一个MapReduced来取得log中的每一?数据。因为我们只要取得数据而不需要对l果q行规约Q我们只要编写一个MapE序卛_?nbsp;  
  1. public static class MapClass extends MapReduceBase implements
  2.       Mapper<WritableComparable, Text, Text, Writable> {

  3.     @Override
  4.     public void configure(JobConf job) {
  5.       tableName = job.get(TABLE, "");
  6.     }

  7.     public void map(WritableComparable key, Text value,
  8.         OutputCollector<Text, Writable> output, Reporter reporter)
  9.         throws IOException {
  10.       try {
  11.              AccessLogParser log = new AccessLogParser(value.toString());
  12.         if(table==null)
  13.                 table = new HTable(conf, new Text(tableName));
  14.         long lockId = table.startUpdate(new Text(log.getIp()));
  15.         table.put(lockId, new Text("http:protocol"), log.getProtocol().getBytes());
  16.         table.put(lockId, new Text("http:method"), log.getMethod().getBytes());
  17.         table.put(lockId, new Text("http:code"), log.getCode().getBytes());
  18.         table.put(lockId, new Text("http:bytesize"), log.getByteSize().getBytes());
  19.         table.put(lockId, new Text("http:agent"), log.getAgent().getBytes());
  20.         table.put(lockId, new Text("url:" + log.getUrl()), log.getReferrer().getBytes());
  21.         table.put(lockId, new Text("referrer:" + log.getReferrer()), log.getUrl().getBytes());

  22.         table.commit(lockId, log.getTimestamp());
  23.       } catch (ParseException e) {
  24.         e.printStackTrace();
  25.       } catch (Exception e) {
  26.         e.printStackTrace();
  27.       }
  28.     }
  29.   }
复制代码

我们在MapE序中对于传q来的每一行先交给AccessLogParserd理在AccessLogParserh造器中用一个正则表辑ּ"([^ ]*) ([^ ]*) ([^ ]*) \\[([^]]*)\\] \"([^\"]*)\" " ([^ ]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\".*"来匹配每一行的log。接下来我们把这些AccessLogParser处理出来的结果更新到HBase的表中去Q好的, 我们的程序写完了。我们要启动一个MapReduce的话我们要对工作q行配置?nbsp;  
  1. public static void runMapReduce(String table,String dir) throws IOException{
  2.           Path tempDir = new Path("log/temp");
  3.           Path InputDir = new Path(dir);
  4.           FileSystem fs = FileSystem.get(conf);
  5.           JobConf jobConf = new JobConf(conf, LogFetcher.class);
  6.           jobConf.setJobName("apache log fetcher");
  7.           jobConf.set(TABLE, table);
  8.           Path[] in = fs.listPaths(InputDir);
  9.           if (fs.isFile(InputDir)) {
  10.               jobConf.setInputPath(InputDir);
  11.           } else {
  12.               for (int i = 0; i < in.length; i++) {
  13.                 if (fs.isFile(in[i])) {
  14.                   jobConf.addInputPath(in[i]);
  15.                 } else {
  16.                   Path[] sub = fs.listPaths(in[i]);
  17.                   for (int j = 0; j < sub.length; j++) {
  18.                     if (fs.isFile(sub[j])) {
  19.                       jobConf.addInputPath(sub[j]);
  20.                     }
  21.                   }
  22.                 }
  23.               }
  24.             }
  25.             jobConf.setOutputPath(tempDir);
  26.             jobConf.setMapperClass(MapClass.class);

  27.             JobClient client = new JobClient(jobConf);
  28.             ClusterStatus cluster = client.getClusterStatus();
  29.             jobConf.setNumMapTasks(cluster.getMapTasks());
  30.             jobConf.setNumReduceTasks(0);

  31.             JobClient.runJob(jobConf);
  32.             fs.delete(tempDir);
  33.             fs.close();
  34.   }
复制代码

在上面的代码中我们先产生一个jobConf对象Q然后设定我们的InputPath和OutputPathQ告诉MapReduce我们的Mapc,?定我们用多少个Mapd和ReducedQ然后我们不d提交lJobClientQ关于MapReduce跟详l的资料?a target="_blank">Hadoop Wiki上?br /> 下蝲Q源码和已编译好?span >jar文gexample-src.tgz
例子的运行命令是Q?br />
bin/hadoop jar examples.jar logfetcher <access_log file or directory> <table_name>

如何q行上面的应用程序呢Q我们假定解压羃完Hadoop分发包的目录?HADOOP%
拯%HADOOP%\contrib\hbase\bin下的文g?HADOOP%\bin?拯%HADOOP%\contrib\hbase \conf的文件到%HADOOP%\conf?拯%HADOOP%\src\contrib\hbase\lib的文件到%HADOOP%\lib ?拯%HADOOP%\src\contrib\hbase\hadoop-*-hbase.jar的文件到%HADOOP%\lib?然后~辑?|文件hbase-site.xml讑֮你的hbase.master例子Q?92.168.2.92:60000。把q些文g分发到运行Hadoop?机器上去。在regionservers文gd上这些已分发q的地址。运行bin/start-hbase.sh命o启动HBaseQ把你的 apache log文g拯到HDFS的apache-log目录下,{启动完成后q行下面的命令?br />
bin/hadoop jar examples.jar logfetcher apache-log apache

讉Khttp://localhost:50030/?看到你的MapReduced的运行情况,讉Khttp://localhost:60010/?看到HBase的运行情c?br />
hbaseguiinterface.jpg

{Q务MapReduce完成后访?a href="http://localhost:60010/hql.jsp" target="_blank">http://localhost:60010/hql.jsp,在Query输入框中输入 SELECT * FROM apache limit=50;。将会看到已l插入表中的数据? hqlguiinterface.jpg


SIMONE 2013-02-22 14:12 发表评论
]]>
Hadoop学习W记之在Eclipse中远E调试Hadoophttp://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395570.htmlSIMONESIMONEFri, 22 Feb 2013 06:06:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395570.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/395570.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395570.html#Feedback1http://www.aygfsteel.com/wangxinsh55/comments/commentRss/395570.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/395570.htmlhttp://www.aygfsteel.com/yongboy/archive/2012/04/26/376486.html

插g

话说Hadoop 1.0.2/src/contrib/eclipse-plugin只有插g的源代码Q这里给Z个我打包好的对应的Eclipse插gQ?br />下蝲地址

下蝲后扔到eclipse/dropins目录下即可,当然eclipse/plugins也是可以的,前者更便,推荐Q重启EclipseQ即可在透视?Perspective)中看到Map/Reduce?/p>

配置

点击蓝色的小象图标,新徏一个Hadoopq接Q?/p>

2

注意Q一定要填写正确Q修改了某些端口Q以及默认运行的用户名等

具体的设|,可见

正常情况下,可以在项目区域可以看?/p>

image

q样可以正常的进行HDFS分布式文件系l的理Q上传,删除{操作?/p>

Z面测试做准备Q需要先Z一个目?user/root/input2Q然后上传两个txt文g到此目录Q?/p>

intput1.txt 对应内容QHello Hadoop Goodbye Hadoop

intput2.txt 对应内容QHello World Bye World

HDFS的准备工作好了,下面可以开始测试了?/p>

Hadoop工程

新徏一个Map/Reduce Project工程Q设定好本地的hadoop目录

1

新徏一个测试类WordCountTestQ?/p>

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
package com.hadoop.learn.test;
 
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;
import org.apache.log4j.Logger;
 
/**
* q行试E序
*
* @author yongboy
* @date 2012-04-16
*/
public class WordCountTest {
private static final Logger log = Logger.getLogger(WordCountTest.class);
 
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 {
log.info("Map key : " + key);
log.info("Map value : " + value);
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
String wordStr = itr.nextToken();
word.set(wordStr);
log.info("Map word : " + wordStr);
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 {
log.info("Reduce key : " + key);
log.info("Reduce value : " + values);
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
log.info("Reduce sum : " + 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: WordCountTest <in> <out>");
System.exit(2);
}
 
Job job = new Job(conf, "word count");
job.setJarByClass(WordCountTest.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);
}
}

右键Q选择“Run Configurations”,弹出H口Q点?#8220;Arguments”选项??#8220;Program argumetns”处预先输入参?

hdfs://master:9000/user/root/input2 dfs://master:9000/user/root/output2

备注Q参Cؓ了在本地调试使用Q而非真实环境?/p>

然后Q点?#8220;Apply”Q然?#8220;Close”。现在可以右键,选择“Run on Hadoop”Q运行?/p>

但此时会出现cM异常信息Q?/p>

12/04/24 15:32:44 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
12/04/24 15:32:44 ERROR security.UserGroupInformation: PriviledgedActionException as:Administrator cause:java.io.IOException: Failed to set permissions of path: \tmp\hadoop-Administrator\mapred\staging\Administrator-519341271\.staging to 0700
Exception in thread "main" java.io.IOException: Failed to set permissions of path: \tmp\hadoop-Administrator\mapred\staging\Administrator-519341271\.staging to 0700
    at org.apache.hadoop.fs.FileUtil.checkReturnValue(FileUtil.java:682)
    at org.apache.hadoop.fs.FileUtil.setPermission(FileUtil.java:655)
    at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:509)
    at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:344)
    at org.apache.hadoop.fs.FilterFileSystem.mkdirs(FilterFileSystem.java:189)
    at org.apache.hadoop.mapreduce.JobSubmissionFiles.getStagingDir(JobSubmissionFiles.java:116)
    at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:856)
    at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:850)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:396)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1093)
    at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:850)
    at org.apache.hadoop.mapreduce.Job.submit(Job.java:500)
    at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:530)
    at com.hadoop.learn.test.WordCountTest.main(WordCountTest.java:85)

q个是Windows下文件权限问题,在Linux下可以正常运行,不存在这L问题?/p>

解决Ҏ是,修改/hadoop-1.0.2/src/core/org/apache/hadoop/fs/FileUtil.java里面的checkReturnValueQ注释掉卛_Q有些粗_在Window下,可以不用查)Q?/p>

1 2 3 4 5 6 7 8 9 10 11 12 13
......
private static void checkReturnValue(boolean rv, File p,
FsPermission permission
) throws IOException {
/**
if (!rv) {
throw new IOException("Failed to set permissions of path: " + p +
" to " +
String.format("%04o", permission.toShort()));
}
**/
}
......
view raw FileUtil.java This Gist brought to you by GitHub.

重新~译打包hadoop-core-1.0.2.jarQ替换掉hadoop-1.0.2根目录下的hadoop-core-1.0.2.jar卛_?/p>

q里提供一份修改版?a target="_blank">hadoop-core-1.0.2-modified.jar文gQ替换原hadoop-core-1.0.2.jar卛_?/p>

替换之后Q刷新项目,讄好正的jar包依赖,现在再运行WordCountTestQ即可?/p>

成功之后Q在Eclipse下刷新HDFS目录Q可以看到生成了ouput2目录Q?/p>

image

点击“ part-r-00000”文gQ可以看到排序结果:

Bye    1
Goodbye    1
Hadoop    2
Hello    2
World    2

嗯,一样可以正常Debug调试该程序,讄断点Q右?–> Debug As – > Java ApplicationQ,卛_Q每ơ运行之前,都需要收到删除输出目录)?/p>

另外Q该插g会在eclipse对应的workspace\.metadata\.plugins\org.apache.hadoop.eclipse下,自动生成jar文gQ以及其他文Ӟ包括Haoop的一些具体配|等?/p>

嗯,更多l节Q慢慢体验吧?/p>

遇到的异?/strong>

org.apache.hadoop.ipc.RemoteException: org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot create directory /user/root/output2/_temporary. Name node is in safe mode.
The ratio of reported blocks 0.5000 has not reached the threshold 0.9990. Safe mode will be turned off automatically.
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.mkdirsInternal(FSNamesystem.java:2055)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.mkdirs(FSNamesystem.java:2029)
    at org.apache.hadoop.hdfs.server.namenode.NameNode.mkdirs(NameNode.java:817)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:563)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1388)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1384)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:396)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1093)
    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:1382)

在主节点处,关闭掉安全模式:

#bin/hadoop dfsadmin –safemode leave

如何打包

创建的Map/Reduce目打包成jar包,很简单的事情Q无需多言。保证jar文g的META-INF/MANIFEST.MF文g中存在Main-Class映射Q?/p>

Main-Class: com.hadoop.learn.test.TestDriver

若用到W三方jar包,那么在MANIFEST.MF中增加Class-Path好了?/p>

另外可用插件提供的MapReduce Driver向导Q可以帮忙我们在Hadoop中运行,直接指定别名Q尤其是包含多个Map/Reduce作业Ӟ很有用?/p>

一个MapReduce Driver只要包含一个main函数Q指定别名:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
package com.hadoop.learn.test;
 
import org.apache.hadoop.util.ProgramDriver;
 
/**
*
* @author yongboy
* @time 2012-4-24
* @version 1.0
*/
public class TestDriver {
 
public static void main(String[] args) {
int exitCode = -1;
ProgramDriver pgd = new ProgramDriver();
try {
pgd.addClass("testcount", WordCountTest.class,
"A test map/reduce program that counts the words in the input files.");
pgd.driver(args);
 
exitCode = 0;
} catch (Throwable e) {
e.printStackTrace();
}
 
System.exit(exitCode);
}
}

q里有一个小技巧,MapReduce DrivercM面,右键q行QRun on HadoopQ会在Eclipse的workspace\.metadata\.plugins\org.apache.hadoop.eclipse?录下自动生成jar包,上传到HDFSQ或者远Ehadoop根目录下Q运行它:

# bin/hadoop jar LearnHadoop_TestDriver.java-460881982912511899.jar testcount input2 output3

OKQ本文结束?/p>



SIMONE 2013-02-22 14:06 发表评论
]]>
Hadoop作业提交分析Q五Q?/title><link>http://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395569.html</link><dc:creator>SIMONE</dc:creator><author>SIMONE</author><pubDate>Fri, 22 Feb 2013 06:05:00 GMT</pubDate><guid>http://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395569.html</guid><wfw:comment>http://www.aygfsteel.com/wangxinsh55/comments/395569.html</wfw:comment><comments>http://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395569.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wangxinsh55/comments/commentRss/395569.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wangxinsh55/services/trackbacks/395569.html</trackback:ping><description><![CDATA[<div>http://www.cnblogs.com/spork/archive/2010/04/21/1717592.html</div><br /><div><div class="wmqeeuq" id="cnblogs_post_body"><p>  l过上一的分析Q我们知道了Hadoop的作业提交目标是Clusterq是LocalQ与conf文g夹内的配|文件参数有着密切关系Q不仅如此,其它的很多类都跟conf有关Q所以提交作业时切记把conf攑ֈ你的classpath中?/p> <p>  因ؓConfiguration是利用当前线E上下文的类加蝲器来加蝲资源和文件的Q所以这里我们采用动态蝲入的方式Q先d好对应的依赖库和资源Q然后再构徏一个URLClassLoader作ؓ当前U程上下文的cd载器?/p> <div><div><a title="复制代码"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" /></a></div> <pre><div> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span><span style="color: #000000;"> ClassLoader getClassLoader() {<br /> ClassLoader parent </span><span style="color: #000000;">=</span><span style="color: #000000;"> Thread.currentThread().getContextClassLoader();<br /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (parent </span><span style="color: #000000;">==</span> <span style="color: #0000ff;">null</span><span style="color: #000000;">) {<br /> parent </span><span style="color: #000000;">=</span><span style="color: #000000;"> EJob.</span><span style="color: #0000ff;">class</span><span style="color: #000000;">.getClassLoader();<br /> }<br /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (parent </span><span style="color: #000000;">==</span> <span style="color: #0000ff;">null</span><span style="color: #000000;">) {<br /> parent </span><span style="color: #000000;">=</span><span style="color: #000000;"> ClassLoader.getSystemClassLoader();<br /> }<br /> </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> URLClassLoader(classPath.toArray(</span><span style="color: #0000ff;">new</span><span style="color: #000000;"> URL[</span><span style="color: #000000;">0</span><span style="color: #000000;">]), parent);<br /> }</span></div></pre> <div><a title="复制代码"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" /></a></div></div> <p>  代码很简单,废话׃多说了。调用例子如下:</p> <div> <pre><div><span style="color: #000000;"> EJob.addClasspath(</span><span style="color: #000000;">"</span><span style="color: #000000;">/usr/lib/hadoop-0.20/conf</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br /> ClassLoader classLoader </span><span style="color: #000000;">=</span><span style="color: #000000;"> EJob.getClassLoader();<br /> Thread.currentThread().setContextClassLoader(classLoader);</span></div></pre> </div> <p>  讄好了cd载器Q下面还有一步就是要打包Jar文gQ就是让Project自打包自qclassZ个Jar包,我这里以标准Eclipse工程文g夹布局ZQ打包的是bin文g多w的class?/p> <div><div><a title="复制代码"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" /></a></div> <div class="wmqeeuq" id="cnblogs_code_open_e5d79072-c219-44a1-9025-8122614a7142"> <pre><div><span style="color: #0000ff;"> public</span> <span style="color: #0000ff;">static</span><span style="color: #000000;"> File createTempJar(String root) </span><span style="color: #0000ff;">throws</span><span style="color: #000000;"> IOException {<br /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #0000ff;">new</span><span style="color: #000000;"> File(root).exists()) {<br /> </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span><span style="color: #000000;">;<br /> }<br /> Manifest manifest </span><span style="color: #000000;">=</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> Manifest();<br /> manifest.getMainAttributes().putValue(</span><span style="color: #000000;">"</span><span style="color: #000000;">Manifest-Version</span><span style="color: #000000;">"</span><span style="color: #000000;">, </span><span style="color: #000000;">"</span><span style="color: #000000;">1.0</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br /> </span><span style="color: #0000ff;">final</span><span style="color: #000000;"> File jarFile </span><span style="color: #000000;">=</span><span style="color: #000000;"> File.createTempFile(</span><span style="color: #000000;">"</span><span style="color: #000000;">EJob-</span><span style="color: #000000;">"</span><span style="color: #000000;">, </span><span style="color: #000000;">"</span><span style="color: #000000;">.jar</span><span style="color: #000000;">"</span><span style="color: #000000;">, </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> File(System<br /> .getProperty(</span><span style="color: #000000;">"</span><span style="color: #000000;">java.io.tmpdir</span><span style="color: #000000;">"</span><span style="color: #000000;">)));<br /><br /> Runtime.getRuntime().addShutdownHook(</span><span style="color: #0000ff;">new</span><span style="color: #000000;"> Thread() {<br /> </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> run() {<br /> jarFile.delete();<br /> }<br /> });<br /><br /> JarOutputStream out </span><span style="color: #000000;">=</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> JarOutputStream(</span><span style="color: #0000ff;">new</span><span style="color: #000000;"> FileOutputStream(jarFile),<br /> manifest);<br /> createTempJarInner(out, </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> File(root), </span><span style="color: #000000;">""</span><span style="color: #000000;">);<br /> out.flush();<br /> out.close();<br /> </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> jarFile;<br /> }<br /><br /> </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> createTempJarInner(JarOutputStream out, File f,<br /> String base) </span><span style="color: #0000ff;">throws</span><span style="color: #000000;"> IOException {<br /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (f.isDirectory()) {<br /> File[] fl </span><span style="color: #000000;">=</span><span style="color: #000000;"> f.listFiles();<br /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (base.length() </span><span style="color: #000000;">></span> <span style="color: #000000;">0</span><span style="color: #000000;">) {<br /> base </span><span style="color: #000000;">=</span><span style="color: #000000;"> base </span><span style="color: #000000;">+</span> <span style="color: #000000;">"</span><span style="color: #000000;">/</span><span style="color: #000000;">"</span><span style="color: #000000;">;<br /> }<br /> </span><span style="color: #0000ff;">for</span><span style="color: #000000;"> (</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> i </span><span style="color: #000000;">=</span> <span style="color: #000000;">0</span><span style="color: #000000;">; i </span><span style="color: #000000;"><</span><span style="color: #000000;"> fl.length; i</span><span style="color: #000000;">++</span><span style="color: #000000;">) {<br /> createTempJarInner(out, fl[i], base </span><span style="color: #000000;">+</span><span style="color: #000000;"> fl[i].getName());<br /> }<br /> } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {<br /> out.putNextEntry(</span><span style="color: #0000ff;">new</span><span style="color: #000000;"> JarEntry(base));<br /> FileInputStream in </span><span style="color: #000000;">=</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> FileInputStream(f);<br /> </span><span style="color: #0000ff;">byte</span><span style="color: #000000;">[] buffer </span><span style="color: #000000;">=</span> <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">byte</span><span style="color: #000000;">[</span><span style="color: #000000;">1024</span><span style="color: #000000;">];<br /> </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> n </span><span style="color: #000000;">=</span><span style="color: #000000;"> in.read(buffer);<br /> </span><span style="color: #0000ff;">while</span><span style="color: #000000;"> (n </span><span style="color: #000000;">!=</span> <span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">) {<br /> out.write(buffer, </span><span style="color: #000000;">0</span><span style="color: #000000;">, n);<br /> n </span><span style="color: #000000;">=</span><span style="color: #000000;"> in.read(buffer);<br /> }<br /> in.close();<br /> }<br /> }</span></div></pre> </div> <div><a title="复制代码"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" /></a></div></div> <p>  q里的对外接口是createTempJarQ接收参Cؓ需要打包的文gҎ路径Q支持子文gҎ包。用递归处理法,依次把文件夹里的l构?文g打包到Jar里。很单,是基本的文件流操作Q陌生一点的是Manifest和JarOutputStreamQ查查API明了?/p> <p>  好,万事具备Q只Ơ东风了Q我们来实践一下试试。还是拿WordCount来D例:</p> <div><div><a title="复制代码"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" /></a></div> <div class="wmqeeuq" id="cnblogs_code_open_fc92678b-77e8-420b-abab-e1994c50d7ac"> <pre><div> <span style="color: #008000;">//</span><span style="color: #008000;"> Add these statements. XXX</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> <span style="color: #3366ff;">File jarFile </span></span><span style="color: #3366ff;">= EJob.createTempJar("bin");<br /> EJob.addClasspath("/usr/lib/hadoop-0.20/conf");<br /> ClassLoader classLoader =</span><span style="color: #000000;"><span style="color: #3366ff;"> EJob.getClassLoader();<br /> Thread.currentThread().setContextClassLoader(classLoader);</span><br /><br /> Configuration conf </span><span style="color: #000000;">=</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> Configuration();<br /> String[] otherArgs </span><span style="color: #000000;">=</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> GenericOptionsParser(conf, args)<br /> .getRemainingArgs();<br /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (otherArgs.length </span><span style="color: #000000;">!=</span> <span style="color: #000000;">2</span><span style="color: #000000;">) {<br /> System.err.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">Usage: wordcount <in> <out></span><span style="color: #000000;">"</span><span style="color: #000000;">);<br /> System.exit(</span><span style="color: #000000;">2</span><span style="color: #000000;">);<br /> }<br /><br /> Job job </span><span style="color: #000000;">=</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> Job(conf, </span><span style="color: #000000;">"</span><span style="color: #000000;">word count</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> job.setJarByClass(WordCountTest.</span><span style="color: #0000ff;">class</span><span style="color: #000000;">);<br /> job.setMapperClass(TokenizerMapper.</span><span style="color: #0000ff;">class</span><span style="color: #000000;">);<br /> job.setCombinerClass(IntSumReducer.</span><span style="color: #0000ff;">class</span><span style="color: #000000;">);<br /> job.setReducerClass(IntSumReducer.</span><span style="color: #0000ff;">class</span><span style="color: #000000;">);<br /> job.setOutputKeyClass(Text.</span><span style="color: #0000ff;">class</span><span style="color: #000000;">);<br /> job.setOutputValueClass(IntWritable.</span><span style="color: #0000ff;">class</span><span style="color: #000000;">);<br /> FileInputFormat.addInputPath(job, </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> Path(otherArgs[</span><span style="color: #000000;">0</span><span style="color: #000000;">]));<br /> FileOutputFormat.setOutputPath(job, </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> Path(otherArgs[</span><span style="color: #000000;">1</span><span style="color: #000000;">]));<br /> System.exit(job.waitForCompletion(</span><span style="color: #0000ff;">true</span><span style="color: #000000;">) </span><span style="color: #000000;">?</span> <span style="color: #000000;">0</span><span style="color: #000000;"> : </span><span style="color: #000000;">1</span><span style="color: #000000;">);</span></div></pre> </div> <div><a title="复制代码"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" /></a></div></div> <p>  Run as Java Application。。?span style="color: #ff0000;">Q!Q?/span><span style="color: #ff0000;">No job jar file set...<span style="color: #000000;"><span style="color: #ff0000;">异常</span>Q看?/span></span>job.setJarByClass(WordCountTest.class)q个语句讄作业Jar包没有成功。这是ؓ什么呢Q?/p> <p>因ؓq个Ҏ使用了WordCount.class的类加蝲器来L包含该类的Jar包,然后讄该Jar包ؓ作业所用的Jar包。但是我们的作业 Jar包是在程序运行时才打包的Q而WordCount.class的类加蝲器是AppClassLoaderQ运行后我们无法改变它的搜烦路径Q所以 用setJarByClass是无法设|作业Jar包的。我们必M用JobConf里的setJar来直接设|作业Jar包,像下面一P </p> <div> <pre><div><span style="color: #000000;">((JobConf)job.getConfiguration()).setJar(jarFile);</span></div></pre> </div> <p>   好,我们对上面的例子再做下修改,加上上面q条语句?/p> <div> <pre><div><span style="color: #000000;">Job job </span><span style="color: #000000;">=</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> Job(conf, </span><span style="color: #000000;">"</span><span style="color: #000000;">word count</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br /></span><span style="color: #008000;">//</span><span style="color: #008000;"> And add this statement. XXX</span><span style="color: #008000;"><br /></span><span style="color: #3366ff;">((JobConf) job.getConfiguration()).setJar(jarFile.toString());</span></div></pre> </div> <p>   再Run as Java ApplicationQ终于OK了~~</p> <p>  该种Ҏ的Run on Hadoop使用单,兼容性好Q推荐一试。:Q?/p> <p>  本例子由于时间关p,只在Ubuntu上做了伪分布式测试,但理Z是可以用到真实分布式上去的?/p> <p>     <a >>>Ҏ下蝲<<</a></p> <p> </p> <p>  The end.</p></div></div><img src ="http://www.aygfsteel.com/wangxinsh55/aggbug/395569.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wangxinsh55/" target="_blank">SIMONE</a> 2013-02-22 14:05 <a href="http://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395569.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HBASE的MAPREDUCEdq行异常解决办法Q无需CYGWINQ纯WINDOWS环境http://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395568.htmlSIMONESIMONEFri, 22 Feb 2013 06:03:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395568.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/395568.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2013/02/22/395568.html#Feedback0http://www.aygfsteel.com/wangxinsh55/comments/commentRss/395568.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/395568.htmlhttp://www.aygfsteel.com/paulwong/archive/2012/10/03/388977.html
如果是在WINDOWS的ECLIPSE中,q行HBASE的MAPREDUCEQ会出现异常Q这是由于默认运行MAPREDUCEd是在本地q行Q而由于会建立文g赋权限是按照UNIX的方式进行,因此会报错:

java.lang.RuntimeException: Error while running command to get file permissions : java.io.IOException: Cannot run program "ls": CreateProcess error=2,


解决办法是将d发到q程LQ通常是LINUX上运行,在hbase-site.xml中加入:

<property>
   
<name>mapred.job.tracker</name>
   
<value>master:9001</value>
</property>

同时需把HDFS的权限机制关掉:

<property>
   
<name>dfs.permissions</name>
   
<value>false</value>
</property>


另外׃是在q程上执行Q务,自定义的cLӞ如Maper/Reducer{需打包成jar文g上传Q具体见ҎQ?br />Hadoop作业提交分析Q五Q?a target="_blank">http://www.cnblogs.com/spork/archive/2010/04/21/1717592.html


研究了好几天Q终于搞清楚QCONFIGUARATION是JOB的配|信息,q程JOBTRACKER是以此为参数构建JOBL行,׃q程Lq没有自定义的MAPREDUCEc,需打成JAR包后Q上传到L处,但无需每次都手动传Q可以代码设|:

conf.set("tmpjars", "d:/aaa.jar");


另注意,如果在WINDOWSpȝ中,文g分隔h“Q?#8221;Q生成的JAR包信息是?#8220;Q?#8221;间隔的,在远E主机的LINUX上是无法辨别Q需改ؓQ?br />
System.setProperty("path.separator", ":");


参考文章:
http://www.cnblogs.com/xia520pi/archive/2012/05/20/2510723.html


使用hadoop eclipse plugin提交Jobq添加多个第三方jarQ完版Q?br />http://heipark.iteye.com/blog/1171923 


SIMONE 2013-02-22 14:03 发表评论
]]>
վ֩ģ壺 ƽ| | ֿ| | ʡ| ƶ| | ԭ| | | | | | | ͭ| | | ĵ| ƽ| | ɽ| | ʯ| | | | ϳ| ϰ| | | | ɽ| | ױ| | | ΢ɽ| Խ| ʻ| | ɽ|