发布时间:2020-09-23 15:40:41编辑:admin阅读(2810)
需要使用docker 安装Logstash,来收集文件/var/log/messages
操作系统:centos 7.6
docker版本:19.03.12
ip地址:192.168.31.196
docker pull logstash:7.5.1
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}" } }
重新启动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
确保创建了索引
上一篇: docker安装elasticsearch和head插件
下一篇: docker安装kibana
47737
46227
37095
34616
29219
25877
24733
19855
19408
17898
5708°
6305°
5826°
5879°
6973°
5820°
5838°
6351°
6305°
7668°