{"id":193759,"date":"2020-06-19T11:28:38","date_gmt":"2020-06-19T03:28:38","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=193759"},"modified":"2020-06-15T09:29:40","modified_gmt":"2020-06-15T01:29:40","slug":"log-engine-description","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/log-engine-description.html","title":{"rendered":"docker\u65e5\u5fd7\u5f15\u64ce"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\ndocker\u539f\u751f\u652f\u6301\u4f17\u591a\u7684\u65e5\u5fd7\u5f15\u64ce\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u4e0d\u540c\u7684\u5e94\u7528\u573a\u666f\uff0c\u672c\u7bc7\u6587\u6863\u5bf9\u5176\u4f5c\u4e00\u4e2a\u7b80\u5355\u7684\u8bf4\u660e\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
Docker\u65e5\u5fd7\u5f15\u64ce\u8bf4\u660e<\/strong><\/span><\/div>\n

docker\u652f\u6301\u7684\u65e5\u5fd7\u5f15\u64ce\u5982\u4e0b\uff1a<\/p>\n

none\uff1a\u5173\u95eddocker\u7684\u56de\u663e\u65e5\u5fd7, docker logs \u770b\u4e0d\u5230\u4efb\u4f55\u8f93\u51fa\u3002\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u4e5f\u5c31\u610f\u5473\u7740\u65e0\u6cd5\u67e5\u770b\u4efb\u4f55\u5bb9\u5668\u8f93\u51fa\u7684\u65e5\u5fd7\u3002<\/p>\n

json-file\uff1a\u628a\u6bcf\u4e2a\u5bb9\u5668\u7684\u56de\u663e\u65e5\u5fd7\u6253\u5230\u6bcf\u4e2a\u5bb9\u5668\u7684\u5185\u90e8, \u5f62\u5f0f\u4e3ajson \u6587\u4ef6\u3002\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d, \u6709\u4e9b\u5bb9\u5668\u5728\u542f\u52a8\u540e\u6709\u5927\u91cf\u7684\u56de\u663e\u65e5\u5fd7, \u5c24\u5176\u5728\u7a0b\u5e8f\u5185\u90e8\u62a5\u9519\u65f6\u6253\u51fa\u7684\u65e5\u5fd7\u4fe1\u606f\u5c24\u5176\u5de8\u5927, \u5f88\u53ef\u80fd\u4f1a\u56e0\u4e3a\u67d0\u51e0\u4e2a\u5bb9\u5668\u7684json \u65e5\u5fd7\u8fc7\u5927\u800c\u6491\u7206\u6574\u4e2a\u5bbf\u4e3b\u673a\u7684\u78c1\u76d8\u3002<\/p>\n

syslog\uff1a\u628a\u6240\u6709\u5bb9\u5668\u7684\u56de\u663e\u65e5\u5fd7\u6253\u5230\u7cfb\u7edf\u7684syslog\u4e2d\u3002<\/p>\n

\u76ee\u524dharbor\u79c1\u6709\u955c\u50cf\u4ed3\u5e93\u4f7f\u7528docker-compose\u65b9\u5f0f\u542f\u52a8\u7684\u8bdd\uff0c\u5c31\u9ed8\u8ba4\u4f7f\u7528\u7684\u8fd9\u79cd\u65b9\u5f0f\u3002\u5c06\u6240\u6709\u5bb9\u5668\u7684\u65e5\u5fd7\u90fd\u96c6\u4e2d\u6536\u96c6\u5230\u4e00\u4e2aharbor-log\u7684\u5bb9\u5668\u4e2d\uff0c\u5728\u6267\u884cdocker logs\u7684\u65f6\u5019\u4f1a\u63d0\u793a\"logs\" command is supported only for \"json-file\" and \"journald\" loggin drivers (got: syslog)\u3002<\/p>\n

journald\uff1a\u628a\u6240\u6709\u5bb9\u5668\u7684\u56de\u663e\u65e5\u5fd7\u6253\u5230\u7cfb\u7edf\u7684journald\u670d\u52a1\u4e2d\uff0c\u8fd9\u662f\u63a8\u8350\u7684\u65b9\u5f0f\u3002<\/p>\n

fluentd\uff1a\u628a\u6240\u6709\u5bb9\u5668\u7684\u56de\u663e\u65e5\u5fd7\u6253\u5230fluentd\u670d\u52a1\u4e2d\u3002<\/p>\n

gelf \u628a\u6240\u6709\u5bb9\u5668\u7684\u56de\u663e\u65e5\u5fd7\u6253\u5230\u652f\u6301 GELF(Graylog Extended Log Format) \u683c\u5f0f\u7684\u670d\u52a1\u4e2d, \u6bd4\u5982Graylog\u6216Logstash\u3002<\/p>\n

\u4fee\u6539docker\u65e5\u5fd7\u5f15\u64ce<\/strong><\/span><\/div>\n

\u4fee\u6539docker\u914d\u7f6e\u6587\u4ef6\/etc\/docker\/daemon.json\u5982\u4e0b\uff1a<\/p>\n

\r\n{\r\n    \"log-driver\": \"journald\"\r\n}\r\n<\/pre>\n

\u5728\u5bb9\u5668\u8fd0\u884c\u65f6\u6307\u5b9a\u5176\u65e5\u5fd7\u5f15\u64ce\uff1a<\/p>\n

\r\ndocker run --log-driver=journald alpint \/bin\/sh\r\n<\/pre>\n
journald\u914d\u7f6e\u6587\u4ef6\u8bf4\u660e<\/strong><\/span><\/div>\n

# \/etc\/systemd\/jornald.conf\u793a\u4f8b\uff1a<\/p>\n

\r\n[Journal]\r\n#Storage=auto  \u5b58\u50a8\u4e3a\u81ea\u52a8\u6a21\u5f0f, \u5176\u4ed6\u6a21\u5f0f\u6709\u65e0\u65e5\u5fd7\u6a21\u5f0f, \u7eaf\u5185\u5b58\u6a21\u5f0f\u548c\u7eaf\u78c1\u76d8\u6a21\u5f0f\r\n#Compress=yes  \u9ed8\u8ba4\u542f\u52a8\u538b\u7f29\u529f\u80fd\r\n#Seal=yes   \u9ed8\u8ba4\u52a0\u5bc6, \u65e5\u5fd7\u6587\u4ef6\u4e3a\u4e8c\u8fdb\u5236\u6587\u4ef6, \u65e0\u6cd5 vim\u6216tail \u67e5\u770b\r\n#SplitMode=uid\r\n#SyncIntervalSec=5m\r\n#RateLimitIntervalSec=30s\r\n#RateLimitBurst=1000\r\n#SystemMaxUse=  \u7cbe\u786e\u8bbe\u7f6e\u65e5\u5fd7\u53ef\u4ee5\u5360\u7528\u7684\u6700\u5927\u78c1\u76d8\u7a7a\u95f4\r\n#SystemKeepFree=  \u4fdd\u8bc1\u7cfb\u7edf\u5269\u4f59\u7684\u7a7a\u95f4\u5927\u5c0f\r\n#SystemMaxFileSize=\r\n#SystemMaxFiles=100\r\n#RuntimeMaxUse=\r\n#RuntimeKeepFree=\r\n#RuntimeMaxFileSize=\r\n#RuntimeMaxFiles=100\r\n#MaxRetentionSec=\r\n#MaxFileSec=1month\r\n#ForwardToSyslog=no\r\n#ForwardToKMsg=no\r\n#ForwardToConsole=no\r\n#ForwardToWall=yes\r\n#TTYPath=\/dev\/console\r\n#MaxLevelStore=debug\r\n#MaxLevelSyslog=debug\r\n#MaxLevelKMsg=notice\r\n#MaxLevelConsole=info\r\n#MaxLevelWall=emerg\r\n<\/pre>\n

journald \u9ed8\u8ba4\u914d\u7f6e\u4e0b, \u9ed8\u8ba4\u65e5\u5fd7\u6700\u5927\u9650\u5236\u4e3a\u6240\u5728\u6587\u4ef6\u7cfb\u7edf\u5bb9\u91cf\u7684 10%<\/p>\n

\u9ed8\u8ba4\u914d\u7f6e\u4e0b, journald \u7684\u65e5\u5fd7\u5b58\u653e\u5728 \/var\/log\/journal \u4e0b, \u5982\u679c\u8be5\u76ee\u5f55\u5728\u6839\u5206\u533a\u4e0b, \u4e14\u6839\u5206\u533a\u7a7a\u95f4\u5927\u5c0f\u4e3a10G, \u90a3\u4e48 journald \u5b58\u653e\u65e5\u5fd7\u6700\u5927\u7684\u5927\u5c0f\u4e3a1G, \u8d85\u51fa1G \u540e\u5c06\u5220\u9664\u6700\u65e9\u7684\u65e5\u5fd7<\/p>\n

\u4e5f\u53ef\u4ee5\u7cbe\u786e\u6307\u5b9a\u5360\u7528\u7684\u7a7a\u95f4\u5927\u5c0f\uff1a<\/p>\n

\r\nSystemMaxUse=50M\r\n<\/pre>\n
journalctl\u57fa\u672c\u7528\u6cd5<\/strong><\/span><\/div>\n
\r\njournalctl \u4ece\u5934\u67e5\u770b\u6240\u6709\u65e5\u5fd7\r\n\r\njournalctl -b \u67e5\u770b\u672c\u6b21\u5f00\u673a\u540e\u7684\u6240\u6709\u7cfb\u7edf\u5f15\u5bfc\u65e5\u5fd7\r\n\r\njournalctl -b -1 \u663e\u793a\u4e0a\u6b21\u5f00\u673a\u540e\u7684\u7cfb\u7edf\u5f15\u5bfc\u65e5\u5fd7, \u4ee5\u6b64\u7c7b\u63a8\r\n\r\njournalctl -f \u7c7b\u4f3c\u4e8e tail -f\u6216tailf\r\n\r\njournalctl \/usr\/bin\/dockerd \u540e\u52a0\u7a0b\u5e8f\u7684\u7edd\u5bf9\u8def\u5f84,\u53ef\u4ee5\u663e\u793a\u8be5\u7a0b\u5e8f\u7684\u6240\u6709\u65e5\u5fd7\u4fe1\u606f\r\n\r\njournalctl -xe systemd \u542f\u52a8\u7a0b\u5e8f\u5931\u8d25\u65f6\u4f1a\u63d0\u793a\u4f60\u4f7f\u7528\u8fd9\u4e2a\u547d\u4ee4\u67e5\u770b\u9519\u8bef\u4fe1\u606f, \u5176\u4e2dx \u8868\u793a\u5728\u65e5\u5fd7\u8f93\u51fa\u4e2d\u589e\u52a0\u4e00\u4e9b\u89e3\u91ca\u6027\u7684\u77ed\u6587\u672c, e\u8868\u793a\u7acb\u5373\u8df3\u8f6c\u81f3\u65e5\u5fd7\u7684\u5c3e\u90e8\r\n<\/pre>\n
journald\u6ce8\u610f\u4e8b\u9879<\/strong><\/span><\/div>\n

journald\u914d\u7f6e\u4e2d\uff0c\u6709\u4e24\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u4f18\u5316\u9879\u76ee\uff1a<\/p>\n

\r\nForwardToSyslog=yes\r\nForwardToWall=yes\r\n<\/pre>\n

\u4ee5\u4e0a\u4e24\u4e2a\u53c2\u6570\u9ed8\u8ba4\u90fd\u662f yes \u610f\u5473\u7740 journald \u6536\u96c6\u65e5\u5fd7\u540e\u8fd8\u4f1a\u8f6c\u53d1\u5230 syslog \u4e2d<\/p>\n

\u7531\u6b64\u9020\u6210\u7684\u5f71\u54cd\u662f: journald \u867d\u7136\u53ef\u4ee5\u4e56\u4e56\u7684\u6309\u7167\u4e0a\u9762\u7684\u914d\u7f6e\u8fdb\u884c\u65e5\u5fd7\u7684\u6e05\u7406, \u4f46\u662f syslog \u5374\u4e0d\u5728 journald \u7684\u63a7\u5236\u8303\u56f4\u4e4b\u5185<\/p>\n

\u5728\u65e5\u5fd7\u91cf\u5f88\u5927\u7684\u60c5\u51b5\u4e0b,syslog\u4e2d\u7684\u65e5\u5fd7\u91cf\u4e5f\u53d8\u5f97\u5de8\u5927,\u6240\u4ee5\u6211\u4eec\u9700\u8981\u628a\u4e0a\u9762\u4e24\u4e2a\u53c2\u6570\u7684\u503c\u6539\u4e3ano<\/p>\n

\u91cd\u542fjournald\u670d\u52a1<\/strong><\/span><\/div>\n
\r\nsystemctl restart systemd-journald.service\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

docker\u652f\u6301\u7684\u65e5\u5fd7\u5f15\u64ce\u5982\u4e0b\uff1a none\uff1a\u5173\u95eddocker\u7684\u56de\u663e\u65e5\u5fd7, docker logs \u770b\u4e0d\u5230\u4efb\u4f55\u8f93 […]<\/p>\n","protected":false},"author":668,"featured_media":80702,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-193759","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/193759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=193759"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/193759\/revisions"}],"predecessor-version":[{"id":193762,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/193759\/revisions\/193762"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/80702"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=193759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=193759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=193759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}