{"id":4243,"date":"2014-12-05T10:26:04","date_gmt":"2014-12-05T02:26:04","guid":{"rendered":"https:\/\/www.hmouse.tk\/?p=4243"},"modified":"2014-12-05T10:26:04","modified_gmt":"2014-12-05T02:26:04","slug":"%e5%b0%8f%e6%95%b0%e6%8d%ae%e7%9a%84%e9%87%87%e9%9b%86%e4%b8%8e%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.hmouse.cn\/?p=4243","title":{"rendered":"\u5c0f\u6570\u636e\u7684\u91c7\u96c6\u4e0e\u5206\u6790"},"content":{"rendered":"<p>\u4e0a\u6b21\u8bf4\u4e86\u5927\u6570\u636e\u7684\u5b9e\u65f6\u5206\u6790\u7684\u67b6\u6784\uff0c\u4f46\u662f\u53ef\u80fd\u4f60\u5728\u7684\u516c\u53f8\u6ca1\u6709\u90a3\u4e48\u5927\u7684\u9700\u6c42\uff0c\u5927\u6570\u636e\u7684\u67b6\u6784\u5206\u6790\u81f3\u5c11\u9700\u89813\u53f0\u673a\u5668\u3002\u800c\u4e14\u4e0a\u9762\u8fd8\u8dd1\u4e86N\u4e2a\u5e94\u7528\uff0c\u90a3\u4e48\u5c0f\u6570\u636e\u7684\u8bdd\uff0c\u67b6\u6784\u53ef\u4e0d\u53ef\u4ee5\u4f18\u5316\u5462\uff1f\u901a\u8fc7\u6700\u8fd1\u7684\u7814\u7a76\u53d1\u73b0\uff0cflume+mongo\u662f\u4e2a\u4e0d\u9519\u7684\u7ec4\u5408\u3002\u670d\u52a1\u5668\u53ea\u9700\u8981\u4e00\u53f0\u3002<\/p>\n<p>\u4e4b\u524d\u4e00\u76f4\u60f3\u628a\u6570\u636e\u5b58\u5728mysql\u4e0a\uff0c\u56e0\u4e3a\u4e4b\u524d\u81ea\u5df1\u505a\u65e5\u5fd7\u5206\u6790\u7684\u65f6\u5019\u5c31\u662f\u8fd9\u4e48\u505a\u7684\uff0c\u540e\u6765\u53d1\u73b0\u8fd9\u4e2a\u771f\u662f\u592a\u843d\u4f0d\u4e86\u3002\u770b\u5230\u7f51\u4e0a\u6709flume-mongo\u53bb\u5904\u7406json\u683c\u5f0f\u7684\u6d88\u606f\u3002\u77ac\u95f4\u770b\u5230\u4e86\u5e0c\u671b\uff0cmongo\u5728\u5904\u7406json\u683c\u5f0f\u7684\u6570\u636e\u592a\u5f3a\u5927\u4e86\u3002\u800c\u4e14\u4ee5\u540e\u6240\u6709\u7684\u65e5\u5fd7\u53ef\u4ee5\u5b9a\u4e49\u6210json\u683c\u5f0f\uff0c\u65b9\u4fbf\u4e86\u65e5\u5fd7\u7684\u7ba1\u7406\u548c\u7edf\u4e00\u3002\u8ba9\u6211\u770b\u5230\u5e0c\u671b\uff0c\u95ee\u9898\u53ef\u80fd\u5c31\u662f\u4ee5\u540emongo\u4e0a\u6570\u636e\u5927\u4e86\uff0c\u4f1a\u4e0d\u4f1a\u6709\u95ee\u9898\uff0c\u8fd9\u4e2a\u6709\u5f85\u6d4b\u8bd5\uff0c\u4e0b\u9762\u7b80\u5355\u4ecb\u7ecd\u4e0b\u5b89\u88c5\u65b9\u6cd5\u628a\u3002<\/p>\n<p>1\uff1a\u5b89\u88c5flume<\/p>\n<p><a title=\"http:\/\/flume.apache.org\/download.html\" href=\"http:\/\/flume.apache.org\/download.html\">http:\/\/flume.apache.org\/download.html<\/a>&nbsp; \u4e0b\u8f7d\u6700\u65b0\u7248\uff0c\u6211\u4e00\u822c\u5c31\u76f4\u63a5\u5b89\u88c5bin\u7248\u672c\uff0c\u89e3\u538b\uff0c\u5373\u53ef\u4f7f\u7528<\/p>\n<p>\u8fd8\u8981\u5b89\u88c5java\uff0c\u5426\u5219\u65e0\u6cd5\u4f7f\u7528\uff0c\u5728 \/etc\/profile\u914d\u7f6e\u4e0b\u73af\u5883\u53d8\u91cf<\/p>\n<p>export JAVA_HOME=\/home\/jdk6\/<br \/>export FLUME_HOME=\/usr\/local\/flume<br \/>export PATH=.:$PATH::$FLUME_HOME\/bin<\/p>\n<p>2\uff1a\u5b89\u88c5flume-mongo<\/p>\n<p>\u4e0b\u8f7d <a title=\"https:\/\/github.com\/leonlee\/flume-ng-mongodb-sink\" href=\"https:\/\/github.com\/leonlee\/flume-ng-mongodb-sink\">https:\/\/github.com\/leonlee\/flume-ng-mongodb-sink<\/a><\/p>\n<p>\u7136\u540e\u9700\u8981\u5b89\u88c5\u4e2aApache-meavn\u3002\u8981\u7f16\u8bd1\u5b89\u88c5\u4e0b\uff0c\u751f\u6210jar\u5305\u3002\u7136\u540ecopy\u5230flume\u7684lib\u4e0b<\/p>\n<p>\u8fd8\u6709\u8981\u8bb0\u4f4f\u5b89\u88c5\u4e0bjava-mongo\u7684\u9a71\u52a8\u5305\uff0c\u6211\u4e4b\u524d\u6ca1\u5b89\u88c5\uff0c\u4e00\u76f4\u542f\u52a8\u4e0d\u8d77\u6765\u3002<\/p>\n<p><a title=\"http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/\" href=\"http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/\">http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/<\/a><\/p>\n<p>\u627e\u4e2a<a title=\"http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/2.9.3\/mongo-java-driver-2.9.3.jar\" href=\"http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/2.9.3\/mongo-java-driver-2.9.3.jar\">http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/2.9.3\/mongo-java-driver-2.9.3.jar<\/a> \u5373\u53ef\uff0c\u653e\u5728flume\u7684lib\u4e0b\u3002<\/p>\n<p>3\uff1a\u914d\u7f6e<\/p>\n<p>flume\u7684\u914d\u7f6e<\/p>\n<p>[root@localhost ~]# cat \/usr\/local\/flume\/conf\/flume.conf<br \/>a1.sources&nbsp; = r1<\/p>\n<p>a1.sinks =&nbsp; k1 k2<\/p>\n<p>a1.channels&nbsp; = c1 c2<br \/>#&nbsp; Describe\/configure the source<\/p>\n<p>a1.sources.r1.type&nbsp; = exec<\/p>\n<p>a1.sources.r1.command&nbsp; = tail -F \/root\/host.access.log <\/p>\n<p># Describe&nbsp; the sink<br \/>a1.sinks.k1.type = logger<br \/><font style=\"background-color: #ff0000\">a1.sinks.k2.type = org.riderzen.flume.sink.MongoSink<br \/>a1.sinks.k2.host = localhost<br \/>a1.sinks.k2.port = 27017<br \/>a1.sinks.k2.model = single<br \/>a1.sinks.k2.collection = test<br \/>a1.sinks.k2.db = test<\/font><br \/>a1.sinks.k2.batch = 100<\/p>\n<p># Use a&nbsp; channel which buffers events in memory<\/p>\n<p>a1.channels.c1.type&nbsp; = memory<\/p>\n<p>a1.channels.c1.capacity&nbsp; = 100000<\/p>\n<p>a1.channels.c1.transactionCapacity&nbsp; = 1000<\/p>\n<p>a1.channels.c2.type&nbsp; = memory<\/p>\n<p>a1.channels.c2.capacity&nbsp; = 100000<\/p>\n<p>a1.channels.c2.transactionCapacity&nbsp; = 1000<\/p>\n<p># Bind the&nbsp; source and sink to the channel<\/p>\n<p>a1.sources.r1.channels&nbsp; = c1 c2<br \/>a1.sinks.k1.channel&nbsp; = c1<\/p>\n<p>a1.sinks.k2.channel&nbsp; = c2<\/p>\n<p>&nbsp;<\/p>\n<p>\u8fd9\u91cc\u9762\u7684\u914d\u7f6e\u53ef\u4ee5\u6309\u7167flume\u7684\u5b98\u7f51\u548cflume-mongo\u7684\u8bf4\u660e\u914d\u7f6e\u3002\u7136\u540e\u901a\u8fc7<\/p>\n<p>flume-ng agent -c conf -f flume.conf&nbsp; -n a1&nbsp; -Dflume.root.logger=INFO,console \u542f\u52a8\u5373\u53ef\u3002<\/p>\n<p>\u9057\u7559\u7684\u95ee\u9898\uff1a<\/p>\n<p>1\uff1atail \u2013f \u7684\u5f62\u5f0f\u8bfb\u53d6\u597d\u50cf\u5b98\u7f51\u8bf4\u4f1a\u6709\u4e22\u5931\u7684\u53ef\u80fd\u3002\u6709\u5176\u4ed6\u66f4\u4fdd\u9669\u7684\u65b9\u6cd5\u4e48\uff1f<\/p>\n<p>2\uff1amongo\u5b58\u50a8\u7684\u65e5\u5fd7\u80fd\u4e0d\u80fd\u6309\u65e5\u671f\u5206\u5272\u53ef\u4ee5\u518d\u4f18\u5316\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u6b21\u8bf4\u4e86\u5927\u6570\u636e\u7684\u5b9e\u65f6\u5206\u6790\u7684\u67b6\u6784\uff0c\u4f46\u662f\u53ef\u80fd\u4f60\u5728\u7684\u516c\u53f8\u6ca1\u6709\u90a3\u4e48\u5927\u7684\u9700\u6c42\uff0c\u5927\u6570\u636e\u7684\u67b6\u6784\u5206\u6790\u81f3\u5c11\u9700\u89813\u53f0\u673a\u5668\u3002\u800c\u4e14\u4e0a\u9762\u8fd8\u8dd1\u4e86N\u4e2a\u5e94\u7528\uff0c\u90a3\u4e48\u5c0f\u6570\u636e\u7684\u8bdd\uff0c\u67b6\u6784\u53ef\u4e0d\u53ef\u4ee5\u4f18\u5316\u5462\uff1f\u901a\u8fc7\u6700\u8fd1\u7684\u7814\u7a76\u53d1\u73b0\uff0cflume+mongo\u662f\u4e2a\u4e0d\u9519\u7684\u7ec4\u5408\u3002\u670d\u52a1\u5668\u53ea\u9700\u8981\u4e00\u53f0\u3002<\/p>\n<p>\u4e4b\u524d\u4e00\u76f4\u60f3\u628a\u6570\u636e\u5b58\u5728mysql\u4e0a\uff0c\u56e0\u4e3a\u4e4b\u524d\u81ea\u5df1\u505a\u65e5\u5fd7\u5206\u6790\u7684\u65f6\u5019\u5c31\u662f\u8fd9\u4e48\u505a\u7684\uff0c\u540e\u6765\u53d1\u73b0\u8fd9\u4e2a\u771f\u662f\u592a\u843d\u4f0d\u4e86\u3002\u770b\u5230\u7f51\u4e0a\u6709flume-mongo\u53bb\u5904\u7406json\u683c\u5f0f\u7684\u6d88\u606f\u3002\u77ac\u95f4\u770b\u5230\u4e86\u5e0c\u671b\uff0cmongo\u5728\u5904\u7406json\u683c\u5f0f\u7684\u6570\u636e\u592a\u5f3a\u5927\u4e86\u3002\u800c\u4e14\u4ee5\u540e\u6240\u6709\u7684\u65e5\u5fd7\u53ef\u4ee5\u5b9a\u4e49\u6210json\u683c\u5f0f\uff0c\u65b9\u4fbf\u4e86\u65e5\u5fd7\u7684\u7ba1\u7406\u548c\u7edf\u4e00\u3002\u8ba9\u6211\u770b\u5230\u5e0c\u671b\uff0c\u95ee\u9898\u53ef\u80fd\u5c31\u662f\u4ee5\u540emongo\u4e0a\u6570\u636e\u5927\u4e86\uff0c\u4f1a\u4e0d\u4f1a\u6709\u95ee\u9898\uff0c\u8fd9\u4e2a\u6709\u5f85\u6d4b\u8bd5\uff0c\u4e0b\u9762\u7b80\u5355\u4ecb\u7ecd\u4e0b\u5b89\u88c5\u65b9\u6cd5\u628a\u3002<\/p>\n<p>1\uff1a\u5b89\u88c5flume<\/p>\n<p><a title=\"http:\/\/flume.apache.org\/download.html\" href=\"http:\/\/flume.apache.org\/download.html\">http:\/\/flume.apache.org\/download.html<\/a>&nbsp; \u4e0b\u8f7d\u6700\u65b0\u7248\uff0c\u6211\u4e00\u822c\u5c31\u76f4\u63a5\u5b89\u88c5bin\u7248\u672c\uff0c\u89e3\u538b\uff0c\u5373\u53ef\u4f7f\u7528<\/p>\n<p>\u8fd8\u8981\u5b89\u88c5java\uff0c\u5426\u5219\u65e0\u6cd5\u4f7f\u7528\uff0c\u5728 \/etc\/profile\u914d\u7f6e\u4e0b\u73af\u5883\u53d8\u91cf<\/p>\n<p>export JAVA_HOME=\/home\/jdk6\/<br \/>export FLUME_HOME=\/usr\/local\/flume<br \/>export PATH=.:$PATH::$FLUME_HOME\/bin<\/p>\n<p>2\uff1a\u5b89\u88c5flume-mongo<\/p>\n<p>\u4e0b\u8f7d <a title=\"https:\/\/github.com\/leonlee\/flume-ng-mongodb-sink\" href=\"https:\/\/github.com\/leonlee\/flume-ng-mongodb-sink\">https:\/\/github.com\/leonlee\/flume-ng-mongodb-sink<\/a><\/p>\n<p>\u7136\u540e\u9700\u8981\u5b89\u88c5\u4e2aApache-meavn\u3002\u8981\u7f16\u8bd1\u5b89\u88c5\u4e0b\uff0c\u751f\u6210jar\u5305\u3002\u7136\u540ecopy\u5230flume\u7684lib\u4e0b<\/p>\n<p>\u8fd8\u6709\u8981\u8bb0\u4f4f\u5b89\u88c5\u4e0bjava-mongo\u7684\u9a71\u52a8\u5305\uff0c\u6211\u4e4b\u524d\u6ca1\u5b89\u88c5\uff0c\u4e00\u76f4\u542f\u52a8\u4e0d\u8d77\u6765\u3002<\/p>\n<p><a title=\"http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/\" href=\"http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/\">http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/<\/a><\/p>\n<p>\u627e\u4e2a<a title=\"http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/2.9.3\/mongo-java-driver-2.9.3.jar\" href=\"http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/2.9.3\/mongo-java-driver-2.9.3.jar\">http:\/\/central.maven.org\/maven2\/org\/mongodb\/mongo-java-driver\/2.9.3\/mongo-java-driver-2.9.3.jar<\/a> \u5373\u53ef\uff0c\u653e\u5728flume\u7684lib\u4e0b\u3002<\/p>\n<p>3\uff1a\u914d\u7f6e<\/p>\n<p>flume\u7684\u914d\u7f6e<\/p>\n<p>[root@localhost ~]# cat \/usr\/local\/flume\/conf\/flume.conf<br \/>a1.sources&nbsp; = r1<\/p>\n<p>a1.sinks =&nbsp; k1 k2<\/p>\n<p>a1.channels&nbsp; = c1 c2<br \/>#&nbsp; Describe\/configure the source<\/p>\n<p>a1.sources.r1.type&nbsp; = exec<\/p>\n<p>a1.sources.r1.command&nbsp; = tail -F \/root\/host.access.log <\/p>\n<p># Describe&nbsp; the sink<br \/>a1.sinks.k1.type = logger<br \/><font style=\"background-color: #ff0000\">a1.sinks.k2.type = org.riderzen.flume.sink.MongoSink<br \/>a1.sinks.k2.host = localhost<br \/>a1.sinks.k2.port = 27017<br \/>a1.sinks.k2.model = single<br \/>a1.sinks.k2.collection = test<br \/>a1.sinks.k2.db = test<\/font><br \/>a1.sinks.k2.batch = 100<\/p>\n<p># Use a&nbsp; channel which buffers events in memory<\/p>\n<p>a1.channels.c1.type&nbsp; = memory<\/p>\n<p>a1.channels.c1.capacity&nbsp; = 100000<\/p>\n<p>a1.channels.c1.transactionCapacity&nbsp; = 1000<\/p>\n<p>a1.channels.c2.type&nbsp; = memory<\/p>\n<p>a1.channels.c2.capacity&nbsp; = 100000<\/p>\n<p>a1.channels.c2.transactionCapacity&nbsp; = 1000<\/p>\n<p># Bind the&nbsp; source and sink to the channel<\/p>\n<p>a1.sources.r1.channels&nbsp; = c1 c2<br \/>a1.sinks.k1.channel&nbsp; = c1<\/p>\n<p>a1.sinks.k2.channel&nbsp; = c2<\/p>\n<p>&nbsp;<\/p>\n<p>\u8fd9\u91cc\u9762\u7684\u914d\u7f6e\u53ef\u4ee5\u6309\u7167flume\u7684\u5b98\u7f51\u548cflume-mongo\u7684\u8bf4\u660e\u914d\u7f6e\u3002\u7136\u540e\u901a\u8fc7<\/p>\n<p>flume-ng agent -c conf -f flume.conf&nbsp; -n a1&nbsp; -Dflume.root.logger=INFO,console \u542f\u52a8\u5373\u53ef\u3002<\/p>\n<p>\u9057\u7559\u7684\u95ee\u9898\uff1a<\/p>\n<p>1\uff1atail \u2013f \u7684\u5f62\u5f0f\u8bfb\u53d6\u597d\u50cf\u5b98\u7f51\u8bf4\u4f1a\u6709\u4e22\u5931\u7684\u53ef\u80fd\u3002\u6709\u5176\u4ed6\u66f4\u4fdd\u9669\u7684\u65b9\u6cd5\u4e48\uff1f<\/p>\n<p>2\uff1amongo\u5b58\u50a8\u7684\u65e5\u5fd7\u80fd\u4e0d\u80fd\u6309\u65e5\u671f\u5206\u5272\u53ef\u4ee5\u518d\u4f18\u5316\uff1f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[66],"class_list":["post-4243","post","type-post","status-publish","format-standard","hentry","category-5","tag-66","category-5-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hmouse.cn\/index.php?rest_route=\/wp\/v2\/posts\/4243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hmouse.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hmouse.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hmouse.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hmouse.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4243"}],"version-history":[{"count":1,"href":"https:\/\/www.hmouse.cn\/index.php?rest_route=\/wp\/v2\/posts\/4243\/revisions"}],"predecessor-version":[{"id":4244,"href":"https:\/\/www.hmouse.cn\/index.php?rest_route=\/wp\/v2\/posts\/4243\/revisions\/4244"}],"wp:attachment":[{"href":"https:\/\/www.hmouse.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hmouse.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hmouse.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}