{"id":61527,"date":"2024-10-13T11:46:18","date_gmt":"2024-10-13T03:46:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/61527\/"},"modified":"2024-10-13T11:46:18","modified_gmt":"2024-10-13T03:46:18","slug":"hadoop%e8%88%87%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9a%e5%a4%a7%e6%95%b8%e6%93%9a%e6%99%82%e4%bb%a3%e7%9a%84%e7%b5%90%e5%90%88%e5%88%a9%e5%99%a8-hadoop%e5%92%8c%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/61527\/","title":{"rendered":"Hadoop\u8207\u6578\u64da\u5eab\uff1a\u5927\u6578\u64da\u6642\u4ee3\u7684\u7d50\u5408\u5229\u5668 (hadoop\u548c\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"hadoop%e8%88%87%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9a%e5%a4%a7%e6%95%b8%e6%93%9a%e6%99%82%e4%bb%a3%e7%9a%84%e7%b5%90%e5%90%88%e5%88%a9%e5%99%a8-LnHMJVpSDI\">Hadoop\u8207\u6578\u64da\u5eab\uff1a\u5927\u6578\u64da\u6642\u4ee3\u7684\u7d50\u5408\u5229\u5668<\/h1>\n<p>\u5728\u7576\u4eca\u5927\u6578\u64da\u6642\u4ee3\uff0c\u6578\u64da\u7684\u751f\u6210\u901f\u5ea6\u548c\u6578\u91cf\u90fd\u5728\u4e0d\u65b7\u589e\u52a0\uff0c\u9019\u4f7f\u5f97\u4f01\u696d\u9700\u8981\u5c0b\u627e\u6709\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u8655\u7406\u548c\u5206\u6790\u9019\u4e9b\u6578\u64da\u3002Hadoop\u4f5c\u70ba\u4e00\u500b\u958b\u6e90\u7684\u5206\u4f48\u5f0f\u8a08\u7b97\u6846\u67b6\uff0c\u8207\u50b3\u7d71\u6578\u64da\u5eab\u7684\u7d50\u5408\uff0c\u70ba\u6578\u64da\u8655\u7406\u63d0\u4f9b\u4e86\u65b0\u7684\u53ef\u80fd\u6027\u3002\u672c\u6587\u5c07\u63a2\u8a0eHadoop\u8207\u6578\u64da\u5eab\u7684\u7d50\u5408\u5982\u4f55\u6210\u70ba\u5927\u6578\u64da\u6642\u4ee3\u7684\u5229\u5668\u3002<\/p>\n<h2 id=\"hadoop%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-LnHMJVpSDI\">Hadoop\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>Hadoop\u662f\u4e00\u500b\u7531Apache\u8edf\u4ef6\u57fa\u91d1\u6703\u958b\u767c\u7684\u958b\u6e90\u6846\u67b6\uff0c\u65e8\u5728\u8655\u7406\u5927\u898f\u6a21\u6578\u64da\u96c6\u3002\u5b83\u7684\u6838\u5fc3\u7d44\u4ef6\u5305\u62ecHadoop\u5206\u4f48\u5f0f\u6587\u4ef6\u7cfb\u7d71\uff08HDFS\uff09\u548cMapReduce\u8a08\u7b97\u6a21\u578b\u3002HDFS\u5141\u8a31\u7528\u6236\u5c07\u6578\u64da\u5206\u6563\u5b58\u5132\u5728\u591a\u53f0\u4f3a\u670d\u5668\u4e0a\uff0c\u800cMapReduce\u5247\u63d0\u4f9b\u4e86\u4e00\u7a2e\u9ad8\u6548\u7684\u6578\u64da\u8655\u7406\u65b9\u5f0f\u3002<\/p>\n<h2 id=\"%e5%82%b3%e7%b5%b1%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%b1%80%e9%99%90%e6%80%a7-LnHMJVpSDI\">\u50b3\u7d71\u6578\u64da\u5eab\u7684\u5c40\u9650\u6027<\/h2>\n<p>\u50b3\u7d71\u7684\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff08\u5982MySQL\u3001PostgreSQL\uff09\u5728\u8655\u7406\u7d50\u69cb\u5316\u6578\u64da\u65b9\u9762\u8868\u73fe\u512a\u7570\uff0c\u4f46\u5728\u9762\u5c0d\u5927\u898f\u6a21\u975e\u7d50\u69cb\u5316\u6578\u64da\u6642\uff0c\u5f80\u5f80\u986f\u5f97\u529b\u4e0d\u5f9e\u5fc3\u3002\u9019\u4e9b\u6578\u64da\u5eab\u901a\u5e38\u9700\u8981\u9810\u5148\u5b9a\u7fa9\u6578\u64da\u7d50\u69cb\uff0c\u4e26\u4e14\u5728\u64f4\u5c55\u6027\u548c\u6027\u80fd\u4e0a\u5b58\u5728\u4e00\u5b9a\u7684\u9650\u5236\u3002<\/p>\n<h2 id=\"hadoop%e8%88%87%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e7%b5%90%e5%90%88-LnHMJVpSDI\">Hadoop\u8207\u6578\u64da\u5eab\u7684\u7d50\u5408<\/h2>\n<p>Hadoop\u8207\u6578\u64da\u5eab\u7684\u7d50\u5408\u53ef\u4ee5\u6709\u6548\u5730\u514b\u670d\u50b3\u7d71\u6578\u64da\u5eab\u7684\u5c40\u9650\u6027\u3002\u4ee5\u4e0b\u662f\u5e7e\u7a2e\u5e38\u898b\u7684\u7d50\u5408\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u9810\u8655\u7406\uff1a<\/strong>Hadoop\u53ef\u4ee5\u7528\u4f86\u8655\u7406\u548c\u6e05\u6d17\u539f\u59cb\u6578\u64da\uff0c\u7136\u5f8c\u5c07\u8655\u7406\u5f8c\u7684\u6578\u64da\u5b58\u5132\u5230\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u4e2d\uff0c\u9019\u6a23\u53ef\u4ee5\u63d0\u9ad8\u6578\u64da\u67e5\u8a62\u7684\u6548\u7387\u3002<\/li>\n<li><strong>\u6578\u64da\u5009\u5eab\uff1a<\/strong>\u8a31\u591a\u4f01\u696d\u4f7f\u7528Hadoop\u4f5c\u70ba\u6578\u64da\u5009\u5eab\uff0c\u5c07\u5927\u91cf\u7684\u975e\u7d50\u69cb\u5316\u6578\u64da\u5b58\u5132\u5728HDFS\u4e2d\uff0c\u7136\u5f8c\u4f7f\u7528Hive\u7b49\u5de5\u5177\u9032\u884c\u67e5\u8a62\u548c\u5206\u6790\u3002<\/li>\n<li><strong>\u5be6\u6642\u6578\u64da\u8655\u7406\uff1a<\/strong>\u7d50\u5408Apache Kafka\u7b49\u6d41\u8655\u7406\u6280\u8853\uff0cHadoop\u53ef\u4ee5\u5be6\u73fe\u5be6\u6642\u6578\u64da\u8655\u7406\uff0c\u4e26\u5c07\u7d50\u679c\u5b58\u5132\u5230\u6578\u64da\u5eab\u4e2d\uff0c\u652f\u6301\u5373\u6642\u67e5\u8a62\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%af%a6%e9%9a%9b%e6%87%89%e7%94%a8%e6%a1%88%e4%be%8b-LnHMJVpSDI\">\u5be6\u969b\u61c9\u7528\u6848\u4f8b<\/h2>\n<p>\u8a31\u591a\u4f01\u696d\u5df2\u7d93\u958b\u59cb\u5c07Hadoop\u8207\u6578\u64da\u5eab\u7d50\u5408\u4f7f\u7528\uff0c\u4ee5\u63d0\u9ad8\u6578\u64da\u8655\u7406\u80fd\u529b\u3002\u4f8b\u5982\uff0c\u67d0\u5927\u578b\u96fb\u5546\u5e73\u53f0\u5229\u7528Hadoop\u8655\u7406\u7528\u6236\u884c\u70ba\u6578\u64da\uff0c\u7136\u5f8c\u5c07\u5206\u6790\u7d50\u679c\u5b58\u5132\u5230MySQL\u6578\u64da\u5eab\u4e2d\uff0c\u4ee5\u4fbf\u65bc\u5f8c\u7e8c\u7684\u67e5\u8a62\u548c\u5831\u544a\u751f\u6210\u3002<\/p>\n<h3 id=\"%e4%bb%a3%e7%a2%bc%e7%a4%ba%e4%be%8b-LnHMJVpSDI\">\u4ee3\u78bc\u793a\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684Hadoop MapReduce\u7a0b\u5e8f\u793a\u4f8b\uff0c\u7528\u65bc\u8a08\u7b97\u6587\u672c\u6587\u4ef6\u4e2d\u55ae\u8a5e\u7684\u983b\u7387\uff1a<\/p>\n<pre><code>\nimport org.apache.hadoop.conf.Configuration;\nimport org.apache.hadoop.fs.Path;\nimport org.apache.hadoop.io.IntWritable;\nimport org.apache.hadoop.io.Text;\nimport org.apache.hadoop.mapreduce.Job;\nimport org.apache.hadoop.mapreduce.Mapper;\nimport org.apache.hadoop.mapreduce.Reducer;\n\nimport java.io.IOException;\n\npublic class WordCount {\n    public static class TokenizerMapper extends Mapper&lt;Object, Text, Text, IntWritable&gt; {\n        private final static IntWritable one = new IntWritable(1);\n        private Text word = new Text();\n\n        public void map(Object key, Text value, Context context) throws IOException, InterruptedException {\n            String[] words = value.toString().split(\"\\s+\");\n            for (String w : words) {\n                word.set(w);\n                context.write(word, one);\n            }\n        }\n    }\n\n    public static class IntSumReducer extends Reducer&lt;Text, IntWritable, Text, IntWritable&gt; {\n        private IntWritable result = new IntWritable();\n\n        public void reduce(Text key, Iterable&lt;IntWritable&gt; values, Context context) throws IOException, InterruptedException {\n            int sum = 0;\n            for (IntWritable val : values) {\n                sum += val.get();\n            }\n            result.set(sum);\n            context.write(key, result);\n        }\n    }\n\n    public static void main(String[] args) throws Exception {\n        Configuration conf = new Configuration();\n        Job job = Job.getInstance(conf, \"word count\");\n        job.setJarByClass(WordCount.class);\n        job.setMapperClass(TokenizerMapper.class);\n        job.setCombinerClass(IntSumReducer.class);\n        job.setReducerClass(IntSumReducer.class);\n        job.setOutputKeyClass(Text.class);\n        job.setOutputValueClass(IntWritable.class);\n        FileInputFormat.addInputPath(job, new Path(args[0]));\n        FileOutputFormat.setOutputPath(job, new Path(args[1]));\n        System.exit(job.waitForCompletion(true) ? 0 : 1);\n    }\n}\n<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-LnHMJVpSDI\">\u7d50\u8ad6<\/h2>\n<p>Hadoop\u8207\u6578\u64da\u5eab\u7684\u7d50\u5408\u70ba\u4f01\u696d\u63d0\u4f9b\u4e86\u4e00\u7a2e\u9748\u6d3b\u4e14\u9ad8\u6548\u7684\u6578\u64da\u8655\u7406\u89e3\u6c7a\u65b9\u6848\u3002\u901a\u904e\u5229\u7528Hadoop\u7684\u5206\u4f48\u5f0f\u8a08\u7b97\u80fd\u529b\u548c\u6578\u64da\u5eab\u7684\u67e5\u8a62\u6548\u7387\uff0c\u4f01\u696d\u80fd\u5920\u66f4\u597d\u5730\u61c9\u5c0d\u5927\u6578\u64da\u6311\u6230\uff0c\u5f9e\u800c\u63d0\u5347\u696d\u52d9\u6c7a\u7b56\u7684\u6e96\u78ba\u6027\u548c\u53ca\u6642\u6027\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u95dc\u65bc\u5982\u4f55\u5229\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u652f\u6301\u60a8\u7684Hadoop\u548c\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22Hadoop\u8207\u6578\u64da\u5eab\u7684\u7d50\u5408\uff0c\u63ed\u793a\u5927\u6578\u64da\u6642\u4ee3\u5982\u4f55\u63d0\u5347\u6578\u64da\u8655\u7406\u6548\u7387\u8207\u5206\u6790\u80fd\u529b\uff0c\u52a9\u529b\u4f01\u696d\u6c7a\u7b56\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-61527","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61527","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=61527"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61527\/revisions"}],"predecessor-version":[{"id":61528,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61527\/revisions\/61528"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=61527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=61527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=61527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}