由于自己搭建ELK还是挺麻烦的,我们直接使用docker 来搭建就方便多了
1. 下载镜像(时间很久,耐心要足):
- docker pull sebp/elk
2. 创建Docker容器(只用在第一次使用的时候才创建)
- docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -e ES_MIN_MEM=128m -e ES_MAX_MEM=1024m -it -name elk sebp/elk // 如果报已存在 需要删除elk docker rm elk 再次启动就好了
- docker run elk
3. 进入docker容器:
- docker exec -it elk /bin/bash //使用 id前几位方式进入容器
- docker exec -it f8d32 /bin/bash
4. 修改配置文件 配置文件的位置:
- /etc/logstash/conf.d/02-beats-input.conf 将其中的内容都删掉,替换成下面的配置
input {
tcp {
port => 5044 codec => json_lines
}
}
output{
elasticsearch
{
hosts => ["localhost:9200"
]
}
}
5. 重启docker容器(大概等5-10分钟,等待服务重启)
- docker restart elk
6. 访问Kibana http://localhost:5601/
7. 安装filebeat 日志文件收集
官网地址:www.elastic.co/cn/download…
修改收集日志的地址
# ============================== Filebeat inputs ===============================
filebeat.inputs:
# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.
# filestream is an input for collecting log messages from files.
# - type: filestream
- type: log
# Change to true to enable this input configuration.
# 开启日志收集配置
enabled: true
# Paths that should be crawled and fetched. Glob based paths.
paths:
- D:\logs\*.log
修改收集日志的输出到地址
# ---------------------------- Elasticsearch Output ----------------------------
# 配置索引模板的名字和索引模式的格式
setup.template.enabled: false
setup.template.name: "admin"
setup.template.pattern: "admin-*"
# 索引的生命周期,需要禁用,否则可能无法使用自定义的索引名字
setup.ilm.enabled: false
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["127.0.0.1:9200"]
# 输出到那个索引,因为我们这个地方自定义了索引的名字,所以需要上面配置的setup.template.[name|pattern]的配置
index: "kvf-admin-%{+yyyy.MM.dd}"
enable: true