一、安装
安装版本跟es保持一致,使用7.10.1版本
下载镜像
docker pull logstash:7.10.1
启动logstash
docker run -d --name=logstash logstash:7.10.1
等待30秒,查看日志
docker logs -f logstash
如果出现以下信息,说明启动成功。
[2020-08-26T08:12:01,224][INFO ][org.logstash.beats.Server] Starting server on port: 5044
[2020-08-26T08:12:01,722][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
如果日志出现
t::Pool::HostUnreachableError, :error=>“Elasticsearch Unreachable: [http://elasticsearch:9200/][Manticore::ConnectTimeout] connect timed out”}
和kibana一样,配置连接
(查看ip)
docker inspect -f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ es的容器id
进入logstash的容器
docker exec -it 容器id /bin/bash
修改config/logstash.yml
[http://elasticsearch:9200 改成 (查看ip) 的地址
exit
docker restart logstash
这样日志就不会有报错了
下面进行logstash收集日志配置 拷贝数据,授予权限
容器外操作
mkdir -p /data/elk7/logstash/config/conf.d
docker cp logstash:/usr/share/logstash /data/elk7/
chmod 777 -R /data/elk7/logstash
vi /data/elk7/logstash/config/logstash.yml
http.host: "0.0.0.0"
xpack.monitoring.elasticsearch.hosts: [ "http://172.17.0.2:9200" ]
path.config: /usr/share/logstash/config/conf.d/*.conf
path.logs: /usr/share/logstash/logs
vi /data/elk7/logstash/config/conf.d/syslog.conf
下面是采集系统日志文件的配置
input {
file {
#标签
type => "systemlog-localhost"
#采集点
path => "/var/log/messages"
#开始收集点
start_position => "beginning"
#扫描间隔时间,默认是1s,建议5s
stat_interval => "5"
}
}
output {
elasticsearch {
hosts => ["172.17.0.3:9200"]
index => "logstash-system-localhost-%{+YYYY.MM.dd}"
}
}
//收集一种日志,使用一个文件
// logstash 服务收集的日志
-- 172.17.0.3:9200 是es的服务端口,docker查看es容器的ip和 启动端口
--9600 是logstash的端口
input{
tcp {
mode => "server"
host => "0.0.0.0"
port => 9600
codec => json_lines
}
}
output{
elasticsearch{
hosts=>["172.17.0.3:9200"]
index => "user-%{+YYYY.MM.dd}"
}
stdout{codec => rubydebug}
}
// springboot项目 收集日志配置
input {
tcp {
port => 5044
mode => "server"
tags => ["tags"]
codec => json_lines
}
}
output {
elasticsearch {
hosts => "172.17.0.3:9200"
index => "boot-demo-%{+YYYY.MM.dd}"
}
}
chmod 644 /var/log/messages
使用本地配置文件(代替了docker容器内的文件)启动logstash
docker run -d \
--name=logstash \
--restart=always \
-p 5044:5044 \
-v /data/elk7/logstash:/usr/share/logstash \
-v /var/log/messages:/var/log/messages \
logstash:7.10.1
--------------------------下面的命令不要动(使用下面的命令)-----------------------------------
docker run -d \
--name=logstash \
--restart=always \
-p 9600:9600 \
-p 5044:5044 -v /data/elk7/logstash:/usr/share/logstash \
-v /var/log/messages:/var/log/messages \
logstash:7.10.1
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-A9WIHNui-1624329268625)(C:\Users\74098\AppData\Roaming\Typora\typora-user-images\image-20210621094039396.png)]
springboot集成logstash配置
https://blog.csdn.net/weixin_42741805/article/details/118101817