基础环境 需要安装一下软件
1.docker
2.docker-compose
一.搭建elasticsearch
创建:elasticsearch.yml文件
version: '2'
services:
elasticsearch:
image: elasticsearch:2.2.0
container_name: elasticsearch
restart: always
network_mode: "bridge"
ports:
- "9200:9200"
- "9300:9300"
volumes:
- ./data:/usr/share/elasticsearch/datadocker-file
直接运行docker-compose -f elasticsearch.yml up -d 访问 http://123.206.135.41:9200/_search/
二.搭建 logstash
创建 logstash.yml 文件
version: '2'
services:
logstash:
image: logstash:2.2.0-1
container_name: logstash
restart: always
network_mode: "bridge"
ports:
- "5044:5044"
# - "4560:4560"
- "8080:8080"
volumes:
- ./conf:/config-dir
- ./patterns:/opt/logstash/patterns
external_links:
- elasticsearch:elasticsearch
command: logstash -f /config-dir
当前目录创建 conf 目录,
创建logstash-es-simple.conf配置文件用于测试
input {
stdin {}
}
output {
elasticsearch {
hosts => ["elasticsearch:9200"]
}
stdout {
codec => rubydebug
}
}
运行 docker-compose -f logstash.yml up -d
进入容器执行命令
docker exec -it 容器名称或id /bin/bash
进入config-dir目录执行命令
logstash agent -f logstash-es-simple.conf
看到有几条数据。
三 搭建 filebeat
查看logstash 的ip
docker inspect –format ‘{{ .NetworkSettings.IPAddress }}’ logstash
后面要用到。
创建 filebeat文件
version: '2'
services:
filebeat:
image: olinicola/filebeat:1.0.1
container_name: filebeat
restart: always
network_mode: "bridge"
extra_hosts:
- "logstash:192.168.0.102" //这里的IP要是真实的IP,不能是127.0.0.1
volumes:
- ./conf/filebeat.yml:/etc/filebeat/filebeat.yml
- ./registry:/etc/registry
- /tmp:/tmp
在config文件夹添加filebeat.yml文件
filebeat:
prospectors:
-
paths:
- /tmp/test.log
input_type: log
tail_files: true
registry_file: /etc/registry/mark
output:
logstash:
hosts: ["logstash:5044"]
shipper:
name: n31
logging:
files:
rotateeverybytes: 10485760 # = 10MB
运行docker-compose -f filebeat.yml up -d
测试Filebeat,Logstash,Elasticsearch的连通性
touch /tmp/test.log
echo ‘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
如果正常的话,稍过一会,查看 IP:9200/_search?pretty里面应该就会多出一条我们刚刚添加的日志记录了。
安装Kibana
创建kibana.yml文件
version: '2'
services:
kibana:
image: kibana:4.4.0
container_name: kibana
restart: always
network_mode: "bridge"
ports:
- "5601:5601"
external_links:
- elasticsearch:elasticsearch
运行 docker-compose -f kibana.yml up -d
访问 http://IP:5601 (这里的IP是布署的机子的IP),点击create建立索引,然后查看Discover,可以看到我们的Elasticsearch存储的全部数据(Kibana会默认显示15分钟内的日志数据,在页面 排右上角可以调整这个时长)。
http://123.206.135.41:5601/app/kibana
参考链接
https://blog.csdn.net/sysushui/article/details/78461498