介绍
本章使用sebp/elk
镜像直接启动elk环境,使用rtoma/logspout-redis-logstash
镜像收集改镜像运行主机的所有容器日志。
搭建步骤
主机环境:
- elk+redis:192.168.40.100
- eureka+logspout:192.168.40.102
整体架构:eureka
日志源–>logspout-redis-logstash
收集日志–>redis
存储日志–>elk
处理,存储,展示日志
- 安装
sebp/elk
镜像,并修改logstash配置
- 安装redis镜像
- 安装
rtoma/logspout-redis-logstash
镜像
- 安装eureka
- 登录kibana查看es索引,并创建kibana日志索引
sebp/elk安装
1 2 3 4 5
| mkdir -p /data/elk/{elasticsearch,logstash}
cd /data/elk/logstash
|
1 2
| vim 02-beats-input.conf
|
1 2 3 4 5 6 7 8 9
| input { redis { host => "192.168.40.100" port => "6379" data_type => "list" key => "logspout" codec => "json" } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| filter { if [docker][image] =~ /acs\// or [docker][image] =~ /logstash/ or [docker][image] =~ /zookeeper/ { drop {} } multiline { pattern => "(^\s)|(^Caused by)" negate => false what => "previous" } if [message] =~ "Xmemcached is stopped at" or [message] =~ "Unable to read additional data from client sessionid" { drop {} } mutate { remove_field => [ '[docker][labels]' ] } grok { match => [ "message", "Exception" ] add_tag => ["exception-log"] tag_on_failure => [] add_field => { "Levels" => "Errs" } } grok { match => [ "message", "ERROR" ] add_tag => ["exception-log"] tag_on_failure => [] add_field => { "Levels" => "Errs" } } }
output { if "exception-log" in [tags] { elasticsearch { hosts => ["localhost"] manage_template => false index => "err-dockerlogs-%{+YYYY.MM.dd}" document_type => "%{[@metadata][type]}" codec => rubydebug } } else { elasticsearch { hosts => ["localhost"] manage_template => false index => "dockerlogs-%{+YYYY.MM.dd}" document_type => "%{[@metadata][type]}" codec => rubydebug } } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| docker run --restart always -p 5601:5601 -p 9200:9200 -p 5044:5044 -e ES_MIN_MEM=128m -e ES_MAX_MEM=2048m -v /data/elk/logstash/:/etc/logstash/conf.d/ -v /data/elk/elasticsearch/:/var/lib/elasticsearch/ -v /etc/localtime:/etc/localtime -it --name elk -d sebp/elk
docker logs -f elk
docker exec -it elk bash
/opt/logstash/bin/logstash-plugin install logstash-filter-multiline
exit
docker restart elk
|
redis安装
1
| docker run --restart always --name redis-elk -p 6379:6379 -d redis
|
rtoma/logspout-redis-logstash安装
1 2 3 4 5
| docker run --restart -d --name "elk-logspout-redis" --publish=127.0.0.1:8123:80 -v /var/run/docker.sock:/var/run/docker.sock:ro rtoma/logspout-redis-logstash 'redis://192.168.40.100:6379'
curl http://127.0.0.1:8123/logs
|
eureka安装
1 2 3 4 5
| docker run --name eureka -p 8761:8761 -d springcloud/eureka
docker logs -f eureka
|
kibana设置索引
- 浏览器登录kibana:http://192.168.40.100:5601
- 查看elasticsearch索引
- 创建kibana索引