{"id":588,"date":"2018-02-01T16:33:15","date_gmt":"2018-02-01T08:33:15","guid":{"rendered":"https:\/\/blog.jsjs.org\/?p=588"},"modified":"2018-02-01T16:33:15","modified_gmt":"2018-02-01T08:33:15","slug":"%e4%bd%bf%e7%94%a8fluentd%e5%ae%9e%e7%8e%b0%e5%ae%9e%e6%97%b6%e6%94%b6%e9%9b%86%e6%97%a5%e5%bf%97%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=588","title":{"rendered":"\u4f7f\u7528fluentd\u5b9e\u73b0\u5b9e\u65f6\u6536\u96c6\u65e5\u5fd7\u6587\u4ef6"},"content":{"rendered":"<p>\u76ee\u524d\u7ebf\u4e0a\u670d\u52a1\u4f7f\u7528\u4e86k8s\u8fdb\u884c\u90e8\u7f72\uff0c\u4e00\u4e2a\u670d\u52a1\u914d\u7f6e\u4e86\u591a\u4e2a\u526f\u672c\uff0c\u7136\u540e\u65e5\u5fd7\u662f\u6302\u8f7d\u5230\u5bbf\u4e3b\u673a\u5668\u7684\u76ee\u5f55\u7684\uff0c\u6240\u4ee5\u5f53\u670d\u52a1\u90e8\u7f72\u5230\u4e09\u53f0\u673a\u5668\u65f6\uff0c\u8fd9\u65f6\u8981\u67e5\u770b\u4e1a\u52a1\u65e5\u5fd7\uff0c\u5c31\u5fc5\u987b\u4f9d\u6b21\u767b\u5f55\u4e09\u53f0\u670d\u52a1\u5668\u6765\u770b\u65e5\u5fd7\u3002\u663e\u7136\uff0c\u8fd9\u975e\u5e38\u5730\u4e0d\u65b9\u4fbf\u3002\u56e2\u961f\u60f3\u628a\u65e5\u5fd7\u6536\u96c6\u5230\u4e00\u4e2a\u5730\u65b9\u7edf\u4e00\u67e5\u770b\u3002\u4e8e\u662f\u5f00\u59cb\u5c1d\u8bd5\u5404\u79cd\u65b9\u6848\u3002<\/p>\n<h2 id=\"\u5c1d\u8bd5\">\u5c1d\u8bd5<\/h2>\n<p><strong>1. elasticsearch + fluentd + in_tail(input) + fluent-plugin-elasticsearch(output) + kibana<\/strong><\/p>\n<p>\u521a\u5f00\u59cb\u5c31\u6d4b\u8bd5\u4f7f\u7528\u7f51\u7edc\u4e0a\u63a8\u8350\u7684\u65e5\u5fd7\u6536\u96c6\u65b9\u6848\uff0celasticsearch + fluentd + kibana,\u90e8\u7f72\u5b8c\u6210\u540e\uff0c\u7ecf\u8fc7\u4f7f\u7528\uff0c\u5e76\u4e0d\u80fd\u5f88\u65b9\u4fbf\u5730\u5bf9\u65e5\u5fd7\u8fdb\u884c\u68c0\u7d22\uff0c\u56e0\u4e3a\u65e5\u5fd7\u683c\u5f0f\u975e\u5e38\u591a\uff0c\u4e0d\u65b9\u4fbf\u5bf9\u65e5\u5fd7\u8fdb\u884c\u683c\u5f0f\u5316\uff0c\u6240\u4ee5\u6536\u96c6\u8fc7\u6765\u7684\u65e5\u5fd7\u5e76\u4e0d\u662f\u7ed3\u6784\u5316\u7684\u3002\u53e6\u4e00\u4e2a\u539f\u56e0\u662felasticsearch\u5360\u7528\u7684CPU\u5f88\u9ad8\uff0c\u8fd9\u4e2a\u4e0d\u77e5\u9053\u4ec0\u4e48\u539f\u56e0\uff0c\u53ef\u80fd\u7ed9\u7684\u8d44\u6e90\u4e0d\u591f\u6216\u914d\u7f6e\u4e0d\u5f53\u3002\u4e0d\u8fc7\u66f4\u4e3b\u8981\u662f\u56e2\u961f\u6210\u5458\u5e0c\u671b\u6700\u597d\u662f\u76f4\u63a5\u628a\u65e5\u5fd7\u6536\u96c6\u5230\u4e00\u53f0\u670d\u52a1\u5668\uff0c\u7136\u540e\u80fd\u591f\u4f7f\u7528<a href=\"https:\/\/www.centos.bz\/tag\/linux\/\">linux<\/a>\u7684\u5de5\u5177\uff0c\u5982grep,awk,less\u6765\u67e5\u8be2\u65e5\u5fd7\uff0c\u6240\u4ee5\u6700\u7ec8\u653e\u5f03\u6b64\u65b9\u6848\u3002<\/p>\n<p><strong>2. rsyslog + fluentd + in_tail(input) + fluent-plugin-remote_syslog(output)<\/strong><br \/>\n\u7136\u540e\u5f00\u59cb\u5c1d\u8bd5\u4f7f\u7528fluentd\u6765\u6536\u96c6\u65e5\u5fd7\u5e76\u53d1\u9001\u5230rsyslog, rsyslog\u4f7f\u7528fluentd\u53d1\u9001\u8fc7\u6765\u7684tag\u6765\u547d\u4ee4\u6587\u4ef6\u540d\uff0c\u4f46\u7531\u4e8esyslog\u534f\u8bae\u7684\u9650\u5236\uff0ctag\u6700\u5927\u4e3a32\u4e2a\u5b57\u7b26\uff0c\u6700\u7ec8\u65e0\u5948\u653e\u5f03\u6b64\u65b9\u6848\u3002<\/p>\n<p><strong>3. fluentd-agent(input: in_tail, output: forward) fluentd-<a href=\"https:\/\/www.centos.bz\/tag\/server\/\">server<\/a>(input: forward, ouput: fluent-plugin-forest)<\/strong><br \/>\n\u6700\u540e\u91c7\u7528agent\u548cserver\u7aef\u90fd\u4f7f\u7528fluentd\uff0cagent\u7aef\u7684input\u4f7f\u7528in_tail\uff0couput\u4f7f\u7528forward\uff0cserver\u7aef\u7684input\u4f7f\u7528forward\uff0couput\u4f7f\u7528fluent-plugin-forest\uff0c\u627e\u5230fluent-plugin-forest\u8fd9\u4e2a\u63d2\u4ef6\u4e0d\u5bb9\u6613\uff0c\u56e0\u4e3a\u5b83\u652f\u6301\u4ee5tag\u547d\u540d\u6587\u4ef6\u540d\uff0c\u5e76\u975e\u5e38\u7a33\u5b9a\uff0c\u5176\u5b83\u7684\u63d2\u4ef6\u7531\u4e8e\u4e0d\u600e\u4e48\u66f4\u65b0\u4e86\uff0cbug\u633a\u591a\u65e0\u6cd5\u4f7f\u7528\u3002<\/p>\n<h2 id=\"\u90e8\u7f72\">\u90e8\u7f72<\/h2>\n<h3 id=\"server\u7aef\">server\u7aef<\/h3>\n<pre><code class=\"bash\"><a href=\"https:\/\/www.centos.bz\/tag\/docker\/\">docker<\/a> run -d  -p 24224:24224 -p 24224:24224\/udp -v \/var\/log\/worker:\/var\/log\/worker -v \/etc\/localtime:\/etc\/localtime --name fluent-server registry.cn-hangzhou.aliyuncs.com\/shengjing\/fluent-server\n<\/code><\/pre>\n<h3 id=\"agent\u7aef\">agent\u7aef<\/h3>\n<p>\u5728\u6bcf\u4e2aagent\u65b0\u5efa\u4e00\u4e2a\/home\/fluent\u76ee\u5f55\uff0c\u5e76\u8bbe\u7f6e\u6743\u9650\u4e3a777<\/p>\n<pre><code>mkdir -p \/home\/fluent\nchmod 777 \/home\/fluent\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528k8s\u7684damonset\u6765\u90e8\u7f72<\/p>\n<pre><code class=\"bash\">kubectl create -f fluentd-daemonset.yaml\n<\/code><\/pre>\n<p>fluentd-daemonset.yaml:<\/p>\n<pre><code class=\"yaml\">apiVersion: extensions\/v1beta1\nkind: DaemonSet\nmetadata:\n  name: fluentd\n  namespace: kube-system\n  labels:\n    k8s-app: fluentd-logging\n    version: v1\n    kubernetes.io\/cluster-service: \"true\"\nspec:\n  template:\n    metadata:\n      labels:\n        k8s-app: fluentd-logging\n        version: v1\n        kubernetes.io\/cluster-service: \"true\"\n    spec:\n      containers:\n      - name: fluentd\n        <a href=\"https:\/\/www.centos.bz\/tag\/image\/\">image<\/a>: registry.cn-hangzhou.aliyuncs.com\/shengjing\/fluent-client\n        imagePullPolicy: Always\n        env:\n          - name:  RSYSLOG_HOST\n            value: \"10.29.112.24\"\n        resources:\n          limits:\n            memory: 500Mi\n          requests:\n            cpu: 100m\n            memory: 500Mi\n        volumeMounts:\n        - name: datlog\n          mountPath: \/dat\/log\n          readOnly: true\n        - name: fluent\n          mountPath: \/home\/fluent\n        - name: localtime\n          mountPath: \/etc\/localtime\n          readOnly: true\n\n      terminationGracePeriodSeconds: 30\n      volumes:\n      - name: datlog\n        hostPath:\n          path: \/dat\/log\n      - name: fluent\n        hostPath:\n          path: \/home\/fluent\n\n      - name: localtime\n        hostPath:\n          path: \/etc\/localtime\n<\/code><\/pre>\n<ul>\n<li>\u5176\u4e2d192.168.93.201\u4e3afluentd server\u7684ip<\/li>\n<\/ul>\n<h2 id=\"Dockerfile\">Dockerfile<\/h2>\n<h3 id=\"server\u7aef\">server\u7aef<\/h3>\n<p>Dockerfile:<\/p>\n<pre><code>FROM fluent\/fluentd:v0.12-<a href=\"https:\/\/www.centos.bz\/tag\/debian\/\">debian<\/a>\nCOPY entrypoint.sh \/bin\/entrypoint.sh\nRUN  fluent-gem install  fluent-plugin-forest \\\n     &amp;&amp; chmod +x \/bin\/entrypoint.sh\nCOPY fluent.conf \/fluentd\/etc\/\n<\/code><\/pre>\n<p>entrypoint.sh:<\/p>\n<pre><code>#!\/usr\/bin\/dumb-init \/bin\/sh\n\nuid=${FLUENT_UID:-1000}\n\n# check if a old fluent user exists and delete it\ncat \/etc\/passwd | grep fluent\nif [ $? -eq 0 ]; then\n    deluser fluent\nfi\n\n# (re)add the fluent user with $FLUENT_UID\nuseradd -u ${uid} -o -c \"\" -m fluent\n<a href=\"https:\/\/www.centos.bz\/tag\/export\/\">export<\/a> HOME=\/home\/fluent\n\n# chown home and data folder\nchown -R fluent \/home\/fluent\nchown -R fluent \/fluentd\n\ngosu fluent \"$@\"\n<\/code><\/pre>\n<p>fluent.conf:<\/p>\n<pre><code>&lt;<a href=\"https:\/\/www.centos.bz\/tag\/source\/\">source<\/a>&gt;\n  @type forward\n  port 24224\n  bind 0.0.0.0\n&lt;\/source&gt;\n\n&lt;<a href=\"https:\/\/www.centos.bz\/tag\/match\/\">match<\/a> log.**&gt;\n  @type forest\n  subtype file\n  &lt;template&gt;\n    time_slice_format %Y%m%d\n    path \/var\/log\/worker\/${tag_parts[3..-2]}\n    format single_value\n    flush_interval 2s\n    buffer_path \/tmp\/buffer\/${tag_parts[3..-2]}\n    append true\n    num_threads 1\n  &lt;\/template&gt;\n&lt;\/match&gt;\n\n<\/code><\/pre>\n<h3 id=\"agent\u7aef\">agent\u7aef<\/h3>\n<p>Dockerfile:<\/p>\n<pre><code>FROM fluent\/fluentd:v0.12-debian\nCOPY entrypoint.sh \/bin\/entrypoint.sh\nRUN  chmod +x \/bin\/entrypoint.sh\nCOPY fluent.conf \/fluentd\/etc\/\n<\/code><\/pre>\n<p>entrypoint.sh:<\/p>\n<pre><code>#!\/usr\/bin\/dumb-init \/bin\/sh\n\nuid=${FLUENT_UID:-1000}\n\n# check if a old fluent user exists and delete it\ncat \/etc\/passwd | grep fluent\nif [ $? -eq 0 ]; then\n    deluser fluent\nfi\n\n# (re)add the fluent user with $FLUENT_UID\nuseradd -u ${uid} -o -c \"\" -m fluent\nexport HOME=\/home\/fluent\n\n# chown home and data folder\nchown -R fluent \/home\/fluent\nchown -R fluent \/fluentd\n\n# replace FLUENTD_SERVER_HOST\nsed -i \"s\/FLUENTD_SERVER_HOST\/$FLUENTD_SERVER_HOST\/\" \/fluentd\/etc\/fluent.conf\n\ngosu fluent \"$@\"\n<\/code><\/pre>\n<p>fluent.conf:<\/p>\n<pre><code>&lt;source&gt;\n  @type tail\n  path \/dat\/log\/**\/*.log\n  tag log.*\n  format none\n  refresh_interval 5\n  read_from_head true\n  limit_recently_modified 86400\n  pos_file \/home\/fluent\/dat-log.pos\n&lt;\/source&gt;\n&lt;match log.**&gt;\n  @type forward\n  &lt;server&gt;\n    name myserver1\n    host FLUENTD_SERVER_HOST\n    port 24224\n    weight 60\n  &lt;\/server&gt;\n  buffer_type file\n  buffer_path \/tmp\/buffer_file\n  flush_interval 2s\n  buffer_chunk_limit 8m\n  buffer_queue_limit 1000\n  num_threads 4\n&lt;\/match&gt;\n<\/code><\/pre>\n<h2 id=\"\u53c2\u8003\">\u53c2\u8003<\/h2>\n<p><a href=\"https:\/\/www.centos.bz\/tag\/https\/\">https<\/a>:\/\/<a href=\"https:\/\/www.centos.bz\/tag\/github\/\">github<\/a>.com\/tagomoris\/fluent-plugin-forest<br \/>\nhttp:\/\/docs.fluentd.org\/v0.12\/articles\/in_tail<br \/>\nhttp:\/\/docs.fluentd.org\/v0.12\/articles\/out_forward<br \/>\nhttp:\/\/docs.fluentd.org\/v0.12\/articles\/in_forward<br \/>\nhttp:\/\/docs.fluentd.org\/v0.12\/articles\/out_file<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u524d\u7ebf\u4e0a\u670d\u52a1\u4f7f\u7528\u4e86k8s\u8fdb\u884c\u90e8\u7f72\uff0c\u4e00\u4e2a\u670d\u52a1\u914d\u7f6e\u4e86\u591a\u4e2a\u526f\u672c\uff0c\u7136\u540e\u65e5\u5fd7\u662f\u6302\u8f7d\u5230\u5bbf\u4e3b\u673a\u5668\u7684\u76ee\u5f55\u7684\uff0c\u6240\u4ee5\u5f53\u670d\u52a1\u90e8\u7f72\u5230\u4e09\u53f0\u673a\u5668\u65f6\uff0c\u8fd9\u65f6\u8981\u67e5\u770b\u4e1a\u52a1\u65e5\u5fd7\uff0c\u5c31\u5fc5\u987b\u4f9d\u6b21\u767b\u5f55\u4e09\u53f0\u670d\u52a1\u5668\u6765\u770b\u65e5\u5fd7\u3002\u663e\u7136\uff0c\u8fd9\u975e\u5e38\u5730\u4e0d\u65b9\u4fbf\u3002\u56e2\u961f\u60f3\u628a\u65e5\u5fd7\u6536\u96c6\u5230\u4e00\u4e2a\u5730\u65b9\u7edf\u4e00\u67e5\u770b\u3002\u4e8e\u662f\u5f00\u59cb\u5c1d\u8bd5\u5404\u79cd\u65b9\u6848\u3002 \u5c1d\u8bd5 1. elasticsearch + fluentd + in_tail(input) + fluent-plugin-elasticsearch(output) + kibana \u521a\u5f00\u59cb\u5c31\u6d4b\u8bd5\u4f7f\u7528\u7f51\u7edc\u4e0a\u63a8\u8350\u7684\u65e5\u5fd7\u6536\u96c6\u65b9\u6848\uff0celasticsearch + fluentd + kibana,\u90e8\u7f72\u5b8c\u6210\u540e\uff0c\u7ecf\u8fc7\u4f7f\u7528\uff0c\u5e76\u4e0d\u80fd\u5f88\u65b9\u4fbf\u5730\u5bf9\u65e5\u5fd7\u8fdb\u884c\u68c0\u7d22\uff0c\u56e0\u4e3a\u65e5\u5fd7\u683c\u5f0f\u975e\u5e38\u591a\uff0c\u4e0d\u65b9\u4fbf\u5bf9\u65e5\u5fd7\u8fdb\u884c\u683c\u5f0f\u5316\uff0c\u6240\u4ee5\u6536\u96c6\u8fc7\u6765\u7684\u65e5\u5fd7\u5e76\u4e0d\u662f\u7ed3\u6784\u5316\u7684\u3002\u53e6\u4e00\u4e2a\u539f\u56e0\u662felasticsearch\u5360\u7528\u7684CPU\u5f88\u9ad8\uff0c\u8fd9\u4e2a\u4e0d\u77e5\u9053\u4ec0\u4e48\u539f\u56e0\uff0c\u53ef\u80fd\u7ed9\u7684\u8d44\u6e90\u4e0d\u591f\u6216\u914d\u7f6e\u4e0d\u5f53\u3002\u4e0d\u8fc7\u66f4\u4e3b\u8981\u662f\u56e2\u961f\u6210\u5458\u5e0c\u671b\u6700\u597d\u662f\u76f4\u63a5\u628a\u65e5\u5fd7\u6536\u96c6\u5230\u4e00\u53f0\u670d\u52a1\u5668\uff0c\u7136\u540e\u80fd\u591f\u4f7f\u7528linux\u7684\u5de5\u5177\uff0c\u5982grep,awk,less\u6765\u67e5\u8be2\u65e5\u5fd7\uff0c\u6240\u4ee5\u6700\u7ec8\u653e\u5f03\u6b64\u65b9\u6848\u3002 2. rsyslog + [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-588","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=588"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/588\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}