{"id":81541,"date":"2023-10-29T02:37:07","date_gmt":"2023-10-28T18:37:07","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=81541"},"modified":"2023-10-29T02:37:07","modified_gmt":"2023-10-28T18:37:07","slug":"docker-deploy-elk-filebeat","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/docker-deploy-elk-filebeat.html","title":{"rendered":"\u5728Docker\u4e0a\u642d\u5efaELK+Filebeat\u65e5\u5fd7\u4e2d\u5fc3"},"content":{"rendered":"
1.\u7cfb\u7edf\uff1acentos 7<\/p>\n 2.docker 1.12.1<\/strong><\/p>\n ElasticSearch<\/strong><\/p>\n Elasticsearch \u662f\u4e00\u4e2a\u5b9e\u65f6\u7684\u5206\u5e03\u5f0f\u641c\u7d22\u548c\u5206\u6790\u5f15\u64ce\uff0c\u5b83\u53ef\u4ee5\u7528\u4e8e\u5168\u6587\u641c\u7d22\uff0c\u7ed3\u6784\u5316\u641c\u7d22\u4ee5\u53ca\u5206\u6790\u3002\u5b83\u662f\u4e00\u4e2a\u5efa\u7acb\u5728\u5168\u6587\u641c\u7d22\u5f15\u64ce Apache Lucene \u57fa\u7840\u4e0a\u7684\u641c\u7d22\u5f15\u64ce\uff0c\u4f7f\u7528 Java \u8bed\u8a00\u7f16\u5199\u3002<\/p>\n Logstash<\/strong><\/p>\n Logstash \u662f\u4e00\u4e2a\u5177\u6709\u5b9e\u65f6\u6e20\u9053\u80fd\u529b\u7684\u6570\u636e\u6536\u96c6\u5f15\u64ce\uff0c\u4e3b\u8981\u7528\u4e8e\u65e5\u5fd7\u7684\u6536\u96c6\u4e0e\u89e3\u6790\uff0c\u5e76\u5c06\u5176\u5b58\u5165 ElasticSearch\u4e2d\u3002<\/p>\n Kibana<\/strong><\/p>\n Kibana \u662f\u4e00\u6b3e\u57fa\u4e8e Apache \u5f00\u6e90\u534f\u8bae\uff0c\u4f7f\u7528 JavaScript \u8bed\u8a00\u7f16\u5199\uff0c\u4e3a Elasticsearch \u63d0\u4f9b\u5206\u6790\u548c\u53ef\u89c6\u5316\u7684 Web \u5e73\u53f0\u3002\u5b83\u53ef\u4ee5\u5728 Elasticsearch \u7684\u7d22\u5f15\u4e2d\u67e5\u627e\uff0c\u4ea4\u4e92\u6570\u636e\uff0c\u5e76\u751f\u6210\u5404\u79cd\u7ef4\u5ea6\u7684\u8868\u56fe\u3002<\/p>\n Filebeat<\/strong><\/p>\n \u5f15\u5165Filebeat\u4f5c\u4e3a\u65e5\u5fd7\u641c\u96c6\u5668\uff0c\u4e3b\u8981\u662f\u4e3a\u4e86\u89e3\u51b3Logstash\u5f00\u9500\u5927\u7684\u95ee\u9898\u3002\u76f8\u6bd4Logstash\uff0cFilebeat \u6240\u5360\u7cfb\u7edf\u7684 CPU \u548c\u5185\u5b58\u51e0\u4e4e\u53ef\u4ee5\u5ffd\u7565\u4e0d\u8ba1\u3002<\/p>\n \u4e0d\u5f15\u5165Filebeat<\/strong><\/p>\n <\/p>\n \u5f15\u5165Filebeat<\/strong><\/p>\n <\/p>\n \u542f\u52a8ElasticSearch<\/strong><\/p>\n \u542f\u52a8Logstash<\/strong><\/p>\n \u542f\u52a8Filebeat<\/strong><\/p>\n \u4e0b\u8f7d\u5730\u5740\uff1ahttps:\/\/www.elastic.co\/downloads\/beats\/filebeat<\/p>\n \u542f\u52a8Kibana<\/strong><\/p>\n \u6a21\u62df\u65e5\u5fd7\u6570\u636e<\/strong><\/p>\n \u8bbf\u95ee http:\/\/{$KIBANA_IP}:5601<\/p>\n <\/p>\n <\/p>\n \u672c\u6587\u4e3b\u8981\u8bb2\u8ff0\u4e86\u5982\u4f55\u4e00\u6b65\u6b65\u642d\u5efaELK\u7684\u8fc7\u7a0b\uff0c\u4ee5\u53caFilebeat\u5728\u5176\u4e2d\u6240\u8d77\u7684\u4f5c\u7528\u3002<\/p>\n \u8fd9\u513f\u4ec5\u4ec5\u7ed9\u5927\u5bb6\u505a\u4e86\u4e00\u4e2a\u6f14\u793a\uff0c\u8981\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u90e8\u7f72\u65f6\uff0c\u8fd8\u9700\u4f7f\u7528\u6570\u636e\u5377\u8fdb\u884c\u6570\u636e\u6301\u4e45\u5316\uff0c\u5bb9\u5668\u5185\u5b58\u95ee\u9898\u4e5f\u9700\u8003\u8651\uff0celasticsearch\u4e0elogstash\u90fd\u662f\u76f8\u5bf9\u5403\u5185\u5b58\u7684\uff0c\u5982\u679c\u4e0d\u52a0\u4ee5\u9650\u5236\uff0c\u5f88\u53ef\u80fd\u4f1a\u62d6\u57ae\u4f60\u6574\u4e2a\u670d\u52a1\u5668\u3002<\/p>\n \u5f53\u7136\u5b89\u5168\u56e0\u7d20\u4e5f\u662f\u5927\u5bb6\u4e0d\u80fd\u5ffd\u89c6\u7684\uff0c\u5982\u4f20\u8f93\u7684\u5b89\u5168\u6027\u3001\u7aef\u53e3\u6743\u9650\u7684\u6700\u5c0f\u5316\u66b4\u9732\u7a0b\u5ea6\uff0c\u9632\u706b\u5899\u8bbe\u7f6e\u7b49\u3002<\/p>\n logstash\u89e3\u6790\u65e5\u5fd7\u683c\u5f0f\uff0c\u5982JAVA\u3001nginx\u3001nodejs\u7b49\u65e5\u5fd7\uff1b<\/p>\n elasticsearch\u7684\u5e38\u7528\u641c\u7d22\u8bed\u6cd5\uff1b<\/p>\n \u901a\u8fc7kibana\u5236\u4f5c\u53ef\u89c6\u5316\u56fe\u8868\uff1b<\/p>\n \u539f\u6587\u6765\u81ea\uff1ahttps:\/\/github.com\/jasonGeng88\/blog<\/a><\/p>\ndocker run -d -p 9200:9200 --name elasticsearch elasticsearch<\/pre>\n
\r\n# 1. \u65b0\u5efa\u914d\u7f6e\u6587\u4ef6logstash.conf\r\ninput {\r\nbeats {\r\nport => 5044\r\n}\r\n}\r\n\r\noutput {\r\nstdout {\r\ncodec => rubydebug\r\n}\r\nelasticsearch {\r\n#\u586b\u5199\u5b9e\u9645\u60c5\u51b5elasticsearch\u7684\u8bbf\u95eeIP\uff0c\u56e0\u4e3a\u662f\u8de8\u5bb9\u5668\u95f4\u7684\u8bbf\u95ee\uff0c\u4f7f\u7528\u5185\u7f51\u3001\u516c\u7f51IP\uff0c\u4e0d\u8981\u586b\u5199127.0.0.1|localhost\r\nhosts => [\"{$ELASTIC_IP}:9200\"]\r\n\r\n}\r\n}\r\n\r\n# 2.\u542f\u52a8\u5bb9\u5668\uff0c\u66b4\u9732\u5e76\u6620\u5c04\u7aef\u53e3\uff0c\u6302\u8f7d\u914d\u7f6e\u6587\u4ef6\r\ndocker run -d --expose 5044 -p 5044:5044 --name logstash -v \"$PWD\":\/config-dir logstash -f \/config-dir\/logstash.conf\r\n<\/pre>\n
\r\n# 1.\u4e0b\u8f7dFilebeat\u538b\u7f29\u5305\r\nwget https:\/\/artifacts.elastic.co\/downloads\/beats\/filebeat\/filebeat-5.2.2-linux-x86_64.tar.gz\r\n\r\n# 2.\u89e3\u538b\u6587\u4ef6\r\ntar -xvf filebeat-5.2.2-linux-x86_64.tar.gz\r\n\r\n# 3.\u65b0\u5efa\u914d\u7f6e\u6587\u4ef6filebeat.yml\r\nfilebeat:\r\nprospectors:\r\n- paths:\r\n- \/tmp\/test.log #\u65e5\u5fd7\u6587\u4ef6\u5730\u5740\r\ninput_type: log #\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\r\ntail_files: true #\u4ee5\u6587\u4ef6\u672b\u5c3e\u5f00\u59cb\u8bfb\u53d6\u6570\u636e\r\noutput:\r\nlogstash:\r\nhosts: [\"{$LOGSTASH_IP}:5044\"] #\u586b\u5199logstash\u7684\u8bbf\u95eeIP\r\n\r\n# 4.\u8fd0\u884cfilebeat\r\n.\/filebeat-5.2.2-linux-x86_64\/filebeat -e -c filebeat.yml\r\n<\/pre>\n
docker run -d --name kibana -e ELASTICSEARCH_URL=http:\/\/{$ELASTIC_IP}:9200 -p 5601:5601 kibana<\/pre>\n
\r\n# 1.\u521b\u5efa\u65e5\u5fd7\u6587\u4ef6\r\ntouch \/tmp\/test.log\r\n\r\n# 2.\u5411\u65e5\u5fd7\u6587\u4ef6\u4e2d\u5199\u5165\u4e00\u6761nginx\u8bbf\u95ee\u65e5\u5fd7\r\necho '127.0.0.1 - - [13\/Mar\/2017:22:57:14 +0800] \"GET \/ HTTP\/1.1\" 200 3700 \"-\" \"Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/46.0.2490.86 Safari\/537.36\" \"-\"' >> \/tmp\/test.log\r\n<\/pre>\n
\n