docker安装logstash
一、概述
需要使用docker 安装Logstash,来收集文件/var/log/messages
环境说明
操作系统:centos 7.6
docker版本:19.03.12
ip地址:192.168.31.196
二、安装
下载镜像
docker pull logstash:7.5.1
启动logstash
docker run -d --name=logstash logstash:7.5.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}
拷贝数据,授予权限
docker cp logstash:/usr/share/logstash /data/elk7/ mkdir /data/elk7/logstash/config/conf.d chmod 777 -R /data/elk7/logstash
配置文件
请确保elasticsearch运行正常,关于elasticsearch的安装,请参考连接:
https://www.cnblogs.com/xiao987334176/p/13565468.html
修改配置文件中的elasticsearch地址
vi /data/elk7/logstash/config/logstash.yml
完整内容如下:
http.host: "0.0.0.0" xpack.monitoring.elasticsearch.hosts: [ "http://192.168.31.196:9200" ] path.config: /usr/share/logstash/config/conf.d/*.conf path.logs: /usr/share/logstash/logs
注意:请根据实际情况修改elasticsearch地址
新建文件syslog.conf,用来收集/var/log/messages
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 => ["192.168.31.196:9200"] index => "logstash-system-localhost-%{+YYYY.MM.dd}" } }
注意:请根据实际情况修改elasticsearch地址
设置日志文件读取权限
chmod 644 /var/log/messages
重新启动logstash
docker rm -f 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.5.1
重启完成之后,访问elasticsearch-head
确保创建了索引