¶¥£¬ÕâÑùµÄÌù×ӷdz£ºÃ£¬ÒªÖö¥¡£¸½¼þÊÇÓÉHadoop¼¼Êõ½»Á÷ȺÖÐÈô±ùµÄͬѧÌṩµÄÏà¹Ø×ÊÁÏ£º
(12.58 KB)
HadoopÌí¼Ó½ÚµãµÄ·½·¨ ×Ô¼ºÊµ¼ÊÌí¼Ó½Úµã¹ý³Ì£º
1. ÏÈÔÚslaveÉÏÅäÖúû·¾³£¬°üÀ¨ssh£¬jdk£¬Ïà¹Øconfig£¬lib£¬binµÈµÄ¿½±´£»
2. ½«ÐµÄdatanodeµÄhost¼Óµ½¼¯Èºnamenode¼°ÆäËûdatanodeÖÐÈ¥£»
3. ½«ÐµÄdatanodeµÄip¼Óµ½masterµÄconf/slavesÖУ»
4. ÖØÆôcluster,ÔÚclusterÖп´µ½ÐµÄdatanode½Úµã£»
5. ÔËÐÐbin/start-balancer.sh£¬Õâ¸ö»áºÜºÄʱ¼ä
±¸×¢£º
1. Èç¹û²»balance£¬ÄÇôcluster»á°ÑеÄÊý¾Ý¶¼´æ·ÅÔÚеÄnodeÉÏ£¬ÕâÑù»á½µµÍmrµÄ¹¤×÷ЧÂÊ£»
2. Ò²¿Éµ÷ÓÃbin/start-balancer.sh ÃüÁîÖ´ÐУ¬Ò²¿É¼Ó²ÎÊý -threshold 5
threshold ÊÇÆ½ºâãÐÖµ£¬Ä¬ÈÏÊÇ10%£¬ÖµÔ½µÍ¸÷½ÚµãԽƽºâ£¬µ«ÏûºÄʱ¼äÒ²¸ü³¤¡£
3. balancerÒ²¿ÉÒÔÔÚÓÐmr jobµÄclusterÉÏÔËÐУ¬Ä¬ÈÏdfs.balance.bandwidthPerSecºÜµÍ£¬Îª1M/s¡£ÔÚûÓÐmr jobʱ£¬¿ÉÒÔÌá¸ß¸ÃÉèÖÃ¼Ó¿ì¸ºÔØ¾ùºâʱ¼ä¡£
ÆäËû±¸×¢£º
1. ±ØÐëÈ·±£slaveµÄfirewallÒѹرÕ;
2. È·±£ÐµÄslaveµÄipÒѾÌí¼Óµ½master¼°ÆäËûslavesµÄ/etc/hostsÖУ¬·´Ö®Ò²Òª½«master¼°ÆäËûslaveµÄipÌí¼Óµ½ÐµÄslaveµÄ/etc/hostsÖÐ
mapper¼°reducer¸öÊý urlµØÖ·£º http://wiki.apache.org/hadoop/HowManyMapsAndReduces
HowManyMapsAndReduces
Partitioning your job into maps and reduces
Picking the appropriate size for the tasks for your job can radically change the performance of Hadoop. Increasing the number of tasks increases the framework overhead, but increases load balancing and lowers the cost of failures. At one extreme is the 1 map/1 reduce case where nothing is distributed. The other extreme is to have 1,000,000 maps/ 1,000,000 reduces where the framework runs out of resources for the overhead.
Number of Maps
The number of maps is usually driven by the number of DFS blocks in the input files. Although that causes people to adjust their DFS block size to adjust the number of maps. The right level of parallelism for maps seems to be around 10-100 maps/node, although we have taken it up to 300 or so for very cpu-light map tasks. Task setup takes awhile, so it is best if the maps take at least a minute to execute.
Actually controlling the number of maps is subtle. The mapred.map.tasks parameter is just a hint to the InputFormat for the number of maps. The default InputFormat behavior is to split the total number of bytes into the right number of fragments. However, in the default case the DFS block size of the input files is treated as an upper bound for input splits. A lower bound on the split size can be set via mapred.min.split.size. Thus, if you expect 10TB of input data and have 128MB DFS blocks, you'll end up with 82k maps, unless your mapred.map.tasks is even larger. Ultimately the [WWW] InputFormat determines the number of maps.
The number of map tasks can also be increased manually using the JobConf's conf.setNumMapTasks(int num). This can be used to increase the number of map tasks, but will not set the number below that which Hadoop determines via splitting the input data.
Number of Reduces
The right number of reduces seems to be 0.95 or 1.75 * (nodes * mapred.tasktracker.tasks.maximum). At 0.95 all of the reduces can launch immediately and start transfering map outputs as the maps finish. At 1.75 the faster nodes will finish their first round of reduces and launch a second round of reduces doing a much better job of load balancing.
Currently the number of reduces is limited to roughly 1000 by the buffer size for the output files (io.buffer.size * 2 * numReduces << heapSize). This will be fixed at some point, but until it is it provides a pretty firm upper bound.
The number of reduces also controls the number of output files in the output directory, but usually that is not important because the next map/reduce step will split them into even smaller splits for the maps.
The number of reduce tasks can also be increased in the same way as the map tasks, via JobConf's conf.setNumReduceTasks(int num).
×Ô¼ºµÄÀí½â£º
mapper¸öÊýµÄÉèÖ㺸úinput file ÓйØÏµ£¬Ò²¸úfilesplitsÓйØÏµ£¬filesplitsµÄÉÏÏßΪdfs.block.size£¬ÏÂÏß¿ÉÒÔͨ¹ýmapred.min.split.sizeÉèÖã¬×îºó»¹ÊÇÓÉInputFormat¾ö¶¨¡£
½ÏºÃµÄ½¨Ò飺
The right number of reduces seems to be 0.95 or 1.75 multiplied by (<no. of nodes> * mapred.tasktracker.reduce.tasks.maximum).increasing the number of reduces increases the framework overhead, but increases load balancing and lowers the cost of failures.
<property>
<name>mapred.tasktracker.reduce.tasks.maximum</name>
<value>2</value>
<description>The maximum number of reduce tasks that will be run
simultaneously by a task tracker.
</description>
</property>
µ¥¸önodeмÓÓ²ÅÌ 1.ÐÞ¸ÄÐèҪмÓÓ²Å̵ÄnodeµÄdfs.data.dir£¬ÓöººÅ·Ö¸ôС¢¾ÉÎļþĿ¼
2.ÖØÆôdfs
ͬ²½hadoop ´úÂë hadoop-env.sh
# host:path where hadoop code should be rsync'd from. Unset by default.
# export HADOOP_MASTER=master:/home/$USER/src/hadoop
ÓÃÃüÁîºÏ²¢HDFSСÎļþ hadoop fs -getmerge <src> <dest>
ÖØÆôreduce job·½·¨ Introduced recovery of jobs when JobTracker restarts. This facility is off by default.
Introduced config parameters "mapred.jobtracker.restart.recover", "mapred.jobtracker.job.history.block.size", and "mapred.jobtracker.job.history.buffer.size".
»¹Î´ÑéÖ¤¹ý¡£
IOд²Ù×÷³öÏÖÎÊÌâ 0-1246359584298, infoPort=50075, ipcPort=50020):Got exception while serving blk_-5911099437886836280_1292 to /172.16.100.165:
java.net.SocketTimeoutException: 480000 millis timeout while waiting for channel to be ready for write. ch : java.nio.channels.SocketChannel[connected local=/
172.16.100.165:50010 remote=/172.16.100.165:50930]
at org.apache.hadoop.net.SocketIOWithTimeout.waitForIO(SocketIOWithTimeout.java:185)
at org.apache.hadoop.net.SocketOutputStream.waitForWritable(SocketOutputStream.java:159)
at org.apache.hadoop.net.SocketOutputStream.transferToFully(SocketOutputStream.java:198)
at org.apache.hadoop.hdfs.server.datanode.BlockSender.sendChunks(BlockSender.java:293)
at org.apache.hadoop.hdfs.server.datanode.BlockSender.sendBlock(BlockSender.java:387)
at org.apache.hadoop.hdfs.server.datanode.DataXceiver.readBlock(DataXceiver.java:179)
at org.apache.hadoop.hdfs.server.datanode.DataXceiver.run(DataXceiver.java:94)
at java.lang.Thread.run(Thread.java:619)
It seems there are many reasons that it can timeout, the example given in
HADOOP-3831 is a slow reading client.
½â¾ö°ì·¨£ºÔÚhadoop-site.xmlÖÐÉèÖÃdfs.datanode.socket.write.timeout=0ÊÔÊÔ£»
My understanding is that this issue should be fixed in Hadoop 0.19.1 so that
we should leave the standard timeout. However until then this can help
resolve issues like the one you're seeing.
HDFSÍË·þ½ÚµãµÄ·½·¨ Ŀǰ°æ±¾µÄdfsadminµÄ°ïÖúÐÅÏ¢ÊÇûдÇå³þµÄ£¬ÒѾfileÁËÒ»¸öbugÁË£¬ÕýÈ·µÄ·½·¨ÈçÏ£º
1. ½« dfs.hosts ÖÃΪµ±Ç°µÄ slaves£¬ÎļþÃûÓÃÍêÕû·¾¶£¬×¢Ò⣬ÁбíÖеĽڵãÖ÷»úÃûÒªÓôóÃû£¬¼´ uname -n ¿ÉÒԵõ½µÄÄǸö¡£
2. ½« slaves ÖÐÒª±»ÍË·þµÄ½ÚµãµÄÈ«ÃûÁбí·ÅÔÚÁíÒ»¸öÎļþÀÈç slaves.ex£¬Ê¹Óà dfs.host.exclude ²ÎÊýÖ¸ÏòÕâ¸öÎļþµÄÍêÕû·¾¶
3. ÔËÐÐÃüÁî bin/hadoop dfsadmin -refreshNodes
4. web½çÃæ»ò bin/hadoop dfsadmin -report ¿ÉÒÔ¿´µ½ÍË·þ½ÚµãµÄ״̬ÊÇ Decomission in progress£¬Ö±µ½ÐèÒª¸´ÖƵÄÊý¾Ý¸´ÖÆÍê³ÉΪֹ
5. Íê³ÉÖ®ºó£¬´Ó slaves Àָ dfs.hosts Ö¸ÏòµÄÎļþ£©È¥µôÒѾÍË·þµÄ½Úµã
¸½´øËµÒ»Ï -refreshNodes ÃüÁîµÄÁíÍâÈýÖÖÓÃ;£º
2. Ìí¼ÓÔÊÐíµÄ½Úµãµ½ÁбíÖУ¨Ìí¼ÓÖ÷»úÃûµ½ dfs.hosts ÀïÀ´£©
3. Ö±½ÓÈ¥µô½Úµã£¬²»×öÊý¾Ý¸±±¾±¸·Ý£¨ÔÚ dfs.hosts ÀïÈ¥µôÖ÷»úÃû£©
4. ÍË·þµÄÄæ²Ù×÷¡ª¡ªÍ£Ö¹ exclude ÀïÃæºÍ dfs.hosts ÀïÃæ¶¼Óеģ¬ÕýÔÚ½øÐÐ decomission µÄ½ÚµãµÄÍË·þ£¬Ò²¾ÍÊÇ°Ñ Decomission in progress µÄ½ÚµãÖØÐ±äΪ Normal £¨ÔÚ web ½çÃæ½Ð in service)
hadoop ѧϰ½è¼ø 1. ½â¾öhadoop OutOfMemoryErrorÎÊÌ⣺
<property>
<name>mapred.child.java.opts</name>
<value>-Xmx800M -server</value>
</property>
With the right JVM size in your hadoop-site.xml , you will have to copy this
to all mapred nodes and restart the cluster.
»òÕߣºhadoop jar jarfile [main class] -D mapred.child.java.opts=-Xmx800M
2. Hadoop java.io.IOException: Job failed! at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:1232) while indexing.
when i use nutch1.0,get this error:
Hadoop java.io.IOException: Job failed! at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:1232) while indexing.
Õâ¸öÒ²ºÜºÃ½â¾ö£º
¿ÉÒÔɾ³ýconf/log4j.properties£¬È»ºó¿ÉÒÔ¿´µ½ÏêϸµÄ´íÎ󱨸æ
ÎÒÕâ¶ù³öÏÖµÄÊÇout of memory
½â¾ö°ì·¨ÊÇÔÚ¸øÔËÐÐÖ÷Ààorg.apache.nutch.crawl.Crawl¼ÓÉϲÎÊý£º-Xms64m -Xmx512m
ÄãµÄ»òÐí²»ÊÇÕâ¸öÎÊÌ⣬µ«ÊÇÄÜ¿´µ½ÏêϸµÄ´íÎ󱨸æÎÊÌâ¾ÍºÃ½â¾öÁË
distribute cacheʹÓà ÀàËÆÒ»¸öÈ«¾Ö±äÁ¿£¬µ«ÊÇÓÉÓÚÕâ¸ö±äÁ¿½Ï´ó£¬ËùÒÔ²»ÄÜÉèÖÃÔÚconfigÎļþÖУ¬×ª¶øÊ¹ÓÃdistribute cache
¾ßÌåʹÓ÷½·¨£º(Ïê¼û¡¶the definitive guide¡·,P240)
1. ÔÚÃüÁîÐе÷ÓÃʱ£ºµ÷ÓÃ-files£¬ÒýÈëÐèÒª²éѯµÄÎļþ(¿ÉÒÔÊÇlocal file, HDFS file(ʹÓÃhdfs://xxx?)), »òÕß -archives (JAR,ZIP, tarµÈ)
% hadoop jar job.jar MaxTemperatureByStationNameUsingDistributedCacheFile \
-files input/ncdc/metadata/stations-fixed-width.txt input/ncdc/all output
2. ³ÌÐòÖе÷Óãº
public void configure(JobConf conf) {
metadata = new NcdcStationMetadata();
try {
metadata.initialize(new File("stations-fixed-width.txt"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
ÁíÍâÒ»ÖÖ¼ä½ÓµÄʹÓ÷½·¨£ºÔÚhadoop-0.19.0ÖкÃÏñûÓÐ
µ÷ÓÃaddCacheFile()»òÕßaddCacheArchive()Ìí¼ÓÎļþ£¬
ʹÓÃgetLocalCacheFiles() »ò getLocalCacheArchives() »ñµÃÎļþ
hadoopµÄjobÏÔʾweb There are web-based interfaces to both the JobTracker (MapReduce master) and NameNode (HDFS master) which display status pages about the state of the entire system. By default, these are located at [WWW] http://job.tracker.addr:50030/ and [WWW] http://name.node.addr:50070/.
hadoop¼à¿Ø OnlyXP(52388483) 131702
ÓÃnagios×÷¸æ¾¯£¬ganglia×÷¼à¿ØÍ¼±í¼´¿É
status of 255 error ´íÎóÀàÐÍ£º
java.io.IOException: Task process exit with nonzero status of 255.
at org.apache.hadoop.mapred.TaskRunner.run(TaskRunner.java:424)
´íÎóÔÒò£º
Set mapred.jobtracker.retirejob.interval and mapred.userlog.retain.hours to higher value. By default, their values are 24 hours. These might be the reason for failure, though I'm not sure
split size FileInputFormat input splits: (Ïê¼û ¡¶the definitive guide¡·P190)
mapred.min.split.size: default=1, the smallest valide size in bytes for a file split.
mapred.max.split.size: default=Long.MAX_VALUE, the largest valid size.
dfs.block.size: default = 64M, ϵͳÖÐÉèÖÃΪ128M¡£
Èç¹ûÉèÖà minimum split size > block size, »áÔö¼Ó¿éµÄÊýÁ¿¡£(²ÂÏë´ÓÆäËû½ÚµãÄÃÈ¥Êý¾ÝµÄʱºò£¬»áºÏ²¢block£¬µ¼ÖÂblockÊýÁ¿Ôö¶à)
Èç¹ûÉèÖÃmaximum split size < block size, »á½øÒ»²½²ð·Öblock¡£
split size = max(minimumSize, min(maximumSize, blockSize));
ÆäÖÐ minimumSize < blockSize < maximumSize.
sort by value hadoop ²»Ìṩֱ½ÓµÄsort by value·½·¨£¬ÒòΪÕâÑù»á½µµÍmapreduceÐÔÄÜ¡£
µ«¿ÉÒÔÓÃ×éºÏµÄ°ì·¨À´ÊµÏÖ£¬¾ßÌåʵÏÖ·½·¨¼û¡¶the definitive guide¡·, P250
»ù±¾Ë¼Ï룺
1. ×éºÏkey/value×÷ΪеÄkey£»
2. ÖØÔØpartitioner£¬¸ù¾Ýold keyÀ´·Ö¸î£»
conf.setPartitionerClass(FirstPartitioner.class);
3. ×Ô¶¨ÒåkeyComparator£ºÏȸù¾Ýold keyÅÅÐò£¬ÔÙ¸ù¾Ýold valueÅÅÐò£»
conf.setOutputKeyComparatorClass(KeyComparator.class);
4. ÖØÔØGroupComparator, Ò²¸ù¾Ýold key À´×éºÏ£» conf.setOutputValueGroupingComparator(GroupComparator.class);
small input filesµÄ´¦Àí ¶ÔÓÚһϵÁеÄsmall files×÷Ϊinput file£¬»á½µµÍhadoopЧÂÊ¡£
ÓÐ3ÖÖ·½·¨¿ÉÒÔ½«small fileºÏ²¢´¦Àí£º
1. ½«Ò»ÏµÁеÄsmall filesºÏ²¢³ÉÒ»¸ösequneceFile£¬¼Ó¿ìmapreduceËÙ¶È¡£
Ïê¼ûWholeFileInputFormat¼°SmallFilesToSequenceFileConverter,¡¶the definitive guide¡·, P194
2. ʹÓÃCombineFileInputFormat¼¯³ÉFileinputFormat£¬µ«ÊÇδʵÏÖ¹ý£»
3. ʹÓÃhadoop archives(ÀàËÆ´ò°ü)£¬¼õÉÙСÎļþÔÚnamenodeÖеÄmetadataÄÚ´æÏûºÄ¡£(Õâ¸ö·½·¨²»Ò»¶¨¿ÉÐУ¬ËùÒÔ²»½¨ÒéʹÓÃ)
·½·¨£º
½«/my/filesĿ¼¼°Æä×ÓĿ¼¹éµµ³Éfiles.har£¬È»ºó·ÅÔÚ/myĿ¼ÏÂ
bin/hadoop archive -archiveName files.har /my/files /my
²é¿´files in the archive:
bin/hadoop fs -lsr har://my/files.har
skip bad records JobConf conf = new JobConf(ProductMR.class);
conf.setJobName("ProductMR");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(Product.class);
conf.setMapperClass(Map.class);
conf.setReducerClass(Reduce.class);
conf.setMapOutputCompressorClass(DefaultCodec.class);
conf.setInputFormat(SequenceFileInputFormat.class);
conf.setOutputFormat(SequenceFileOutputFormat.class);
String objpath = "abc1";
SequenceFileInputFormat.addInputPath(conf, new Path(objpath));
SkipBadRecords.setMapperMaxSkipRecords(conf, Long.MAX_VALUE);
SkipBadRecords.setAttemptsToStartSkipping(conf, 0);
SkipBadRecords.setSkipOutputPath(conf, new Path("data/product/skip/"));
String output = "abc";
SequenceFileOutputFormat.setOutputPath(conf, new Path(output));
JobClient.runJob(conf);
For skipping failed tasks try : mapred.max.map.failures.percent
restart µ¥¸ödatanode Èç¹ûÒ»¸ödatanode ³öÏÖÎÊÌ⣬½â¾öÖ®ºóÐèÒªÖØÐ¼ÓÈëcluster¶ø²»ÖØÆôcluster£¬·½·¨ÈçÏ£º
bin/hadoop-daemon.sh start datanode
bin/hadoop-daemon.sh start jobtracker
reduce exceed 100% "Reduce Task Progress shows > 100% when the total size of map outputs (for a
single reducer) is high "
Ôì³ÉÔÒò£º
ÔÚreduceµÄmerge¹ý³ÌÖУ¬check progressÓÐÎó²î£¬µ¼ÖÂstatus > 100%£¬ÔÚͳ¼Æ¹ý³ÌÖоͻá³öÏÖÒÔÏ´íÎó£ºjava.lang.ArrayIndexOutOfBoundsException: 3
at org.apache.hadoop.mapred.StatusHttpServer$TaskGraphServlet.getReduceAvarageProgresses(StatusHttpServer.java:228)
at org.apache.hadoop.mapred.StatusHttpServer$TaskGraphServlet.doGet(StatusHttpServer.java:159)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:475)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
at org.mortbay.http.HttpServer.service(HttpServer.java:954)
jiraµØÖ·£º
counters 3ÖÐcounters£º
1. built-in counters: Map input bytes, Map output records...
2. enum counters
µ÷Ó÷½Ê½£º
enum Temperature {
MISSING,
MALFORMED
}
reporter.incrCounter(Temperature.MISSING, 1)
½á¹ûÏÔʾ£º
09/04/20 06:33:36 INFO mapred.JobClient: Air Temperature Recor
09/04/20 06:33:36 INFO mapred.JobClient: Malformed=3
09/04/20 06:33:36 INFO mapred.JobClient: Missing=66136856
3. dynamic countes:
µ÷Ó÷½Ê½£º
reporter.incrCounter("TemperatureQuality", parser.getQuality(),1);
½á¹ûÏÔʾ£º
09/04/20 06:33:36 INFO mapred.JobClient: TemperatureQuality
09/04/20 06:33:36 INFO mapred.JobClient: 2=1246032
09/04/20 06:33:36 INFO mapred.JobClient: 1=973422173
09/04/20 06:33:36 INFO mapred.JobClient: 0=1
1¡¢ÖÐÎÄÎÊÌâ
´ÓurlÖнâÎö³öÖÐÎÄ,µ«hadoopÖдòÓ¡³öÀ´ÈÔÊÇÂÒÂë?ÎÒÃÇÔø¾ÒÔΪhadoopÊDz»Ö§³ÖÖÐÎĵģ¬ºóÀ´¾¹ý²é¿´Ô´´úÂ룬·¢ÏÖhadoop½ö½öÊDz»Ö§³ÖÒÔgbk¸ñʽÊä³öÖÐÎĶø¼º¡£
ÕâÊÇTextOutputFormat.classÖеĴúÂ룬hadoopĬÈϵÄÊä³ö¶¼ÊǼ̳Ð×ÔFileOutputFormatÀ´µÄ£¬FileOutputFormatµÄÁ½¸ö×ÓÀàÒ»¸öÊÇ»ùÓÚ¶þ½øÖÆÁ÷µÄÊä³ö£¬Ò»¸ö¾ÍÊÇ»ùÓÚÎı¾µÄÊä³öTextOutputFormat¡£
public class TextOutputFormat<K, V> extends FileOutputFormat<K, V> {
protected static class LineRecordWriter<K, V>
implements RecordWriter<K, V> {
private static final String utf8 = ¡°UTF-8¡å;//ÕâÀﱻдËÀ³ÉÁËutf-8
private static final byte[] newline;
static {
try {
newline = ¡°\n¡±.getBytes(utf8);
} catch (UnsupportedEncodingException uee) {
throw new IllegalArgumentException(¡±can¡¯t find ¡± + utf8 + ¡± encoding¡±);
}
}
¡
public LineRecordWriter(DataOutputStream out, String keyValueSeparator) {
this.out = out;
try {
this.keyValueSeparator = keyValueSeparator.getBytes(utf8);
} catch (UnsupportedEncodingException uee) {
throw new IllegalArgumentException(¡±can¡¯t find ¡± + utf8 + ¡± encoding¡±);
}
}
¡
private void writeObject(Object o) throws IOException {
if (o instanceof Text) {
Text to = (Text) o;
out.write(to.getBytes(), 0, to.getLength());//ÕâÀïÒ²ÐèÒªÐÞ¸Ä
} else {
out.write(o.toString().getBytes(utf8));
}
}
¡
}
¿ÉÒÔ¿´³öhadoopĬÈϵÄÊä³öдËÀΪutf-8£¬Òò´ËÈç¹ûdecodeÖÐÎÄÕýÈ·£¬ÄÇô½«Linux¿Í»§¶ËµÄcharacterÉèΪutf-8ÊÇ¿ÉÒÔ¿´µ½ÖÐÎĵġ£ÒòΪhadoopÓÃutf-8µÄ¸ñʽÊä³öÁËÖÐÎÄ¡£
ÒòΪ´ó¶àÊýÊý¾Ý¿âÊÇÓÃgbkÀ´¶¨Òå×ֶεģ¬Èç¹ûÏëÈÃhadoopÓÃgbk¸ñʽÊä³öÖÐÎÄÒÔ¼æÈÝÊý¾Ý¿âÔõô°ì£¿
ÎÒÃÇ¿ÉÒÔ¶¨ÒåÒ»¸öеÄÀࣺ
public class GbkOutputFormat<K, V> extends FileOutputFormat<K, V> {
protected static class LineRecordWriter<K, V>
implements RecordWriter<K, V> {
//д³Égbk¼´¿É
private static final String gbk = ¡°gbk¡±;
private static final byte[] newline;
static {
try {
newline = ¡°\n¡±.getBytes(gbk);
} catch (UnsupportedEncodingException uee) {
throw new IllegalArgumentException(¡±can¡¯t find ¡± + gbk + ¡± encoding¡±);
}
}
¡
public LineRecordWriter(DataOutputStream out, String keyValueSeparator) {
this.out = out;
try {
this.keyValueSeparator = keyValueSeparator.getBytes(gbk);
} catch (UnsupportedEncodingException uee) {
throw new IllegalArgumentException(¡±can¡¯t find ¡± + gbk + ¡± encoding¡±);
}
}
¡
private void writeObject(Object o) throws IOException {
if (o instanceof Text) {
// Text to = (Text) o;
// out.write(to.getBytes(), 0, to.getLength());
// } else {
out.write(o.toString().getBytes(gbk));
}
}
¡
}
È»ºóÔÚmapreduce´úÂëÖмÓÈëconf1.setOutputFormat(GbkOutputFormat.class)
¼´¿ÉÒÔgbk¸ñʽÊä³öÖÐÎÄ¡£
2¡¢Ä³´ÎÕý³£ÔËÐÐmapreduceʵÀýʱ,Å׳ö´íÎó
java.io.IOException: All datanodes xxx.xxx.xxx.xxx:xxx are bad. Aborting¡
at org.apache.hadoop.dfs.DFSClient$DFSOutputStream.processDatanodeError(DFSClient.java:2158)
at org.apache.hadoop.dfs.DFSClient$DFSOutputStream.access$1400(DFSClient.java:1735)
at org.apache.hadoop.dfs.DFSClient$DFSOutputStream$DataStreamer.run(DFSClient.java:1889)
java.io.IOException: Could not get block locations. Aborting¡
at org.apache.hadoop.dfs.DFSClient$DFSOutputStream.processDatanodeError(DFSClient.java:2143)
at org.apache.hadoop.dfs.DFSClient$DFSOutputStream.access$1400(DFSClient.java:1735)
at org.apache.hadoop.dfs.DFSClient$DFSOutputStream$DataStreamer.run(DFSClient.java:1889)
¾²éÃ÷£¬ÎÊÌâÔÒòÊÇlinux»úÆ÷´ò¿ªÁ˹ý¶àµÄÎļþµ¼Ö¡£ÓÃÃüÁîulimit -n¿ÉÒÔ·¢ÏÖlinuxĬÈϵÄÎļþ´ò¿ªÊýĿΪ1024£¬ÐÞ¸Ä/ect/security/limit.conf£¬Ôö¼Óhadoop soft 65535
ÔÙÖØÐÂÔËÐгÌÐò£¨×îºÃËùÓеÄdatanode¶¼Ð޸ģ©£¬ÎÊÌâ½â¾ö
3¡¢ÔËÐÐÒ»¶Îʱ¼äºóhadoop²»ÄÜstop-all.shµÄÎÊÌ⣬ÏÔʾ±¨´í
no tasktracker to stop £¬no datanode to stop
ÎÊÌâµÄÔÒòÊÇhadoopÔÚstopµÄʱºòÒÀ¾ÝµÄÊÇdatanodeÉϵÄmapredºÍdfs½ø³ÌºÅ¡£¶øÄ¬ÈϵĽø³ÌºÅ±£´æÔÚ/tmpÏ£¬linuxĬÈÏ»áÿ¸ôÒ»¶Îʱ¼ä£¨Ò»°ãÊÇÒ»¸öÔ»òÕß7Ìì×óÓÒ£©È¥É¾³ýÕâ¸öĿ¼ÏµÄÎļþ¡£Òò´Ëɾµôhadoop-hadoop-jobtracker.pidºÍhadoop- hadoop-namenode.pidÁ½¸öÎļþºó£¬namenode×ÔÈ»¾ÍÕÒ²»µ½datanodeÉϵÄÕâÁ½¸ö½ø³ÌÁË¡£
ÔÚÅäÖÃÎļþÖеÄexport HADOOP_PID_DIR¿ÉÒÔ½â¾öÕâ¸öÎÊÌâ