Logstash :时间和日志管理工具,可以用来收集,解析,存储日志。
Github:https://github.com/elastic/logstash
官网: https://www.elastic.co/products/logstash
原理 :
三个阶段(管道的方式):
输入input--> 处理filter(不是必须的)--> 输出output
配置文件
1. 结构:
input {}
filter {}
output {}
2. 插件
a. 输入插件(Input):stdin, file, tcp,读取syslog,redis
http://udn.yyuap.com/doc/logstash-best-practice-cn/input/index.html
b. 编码插件(Codec) json, multiline
http://udn.yyuap.com/doc/logstash-best-practice-cn/codec/index.html
c. 过滤器插件(Filter)
http://udn.yyuap.com/doc/logstash-best-practice-cn/filter/index.html
d. 输出插件(Output)
http://udn.yyuap.com/doc/logstash-best-practice-cn/output/index.html
下载安装:
预先准备:Java
https://www.elastic.co/guide/en/logstash/current/installing-logstash.html#installing-binary
使用:
启动指定配置文件(-f)或配置字符串(-e)启动
启动:logstash -e "" 控制台输入hello world.
Logstash跨容器收集数据:
1. 构建logstash 容器
Dockerfile 和logstash.conf :./logstash
2. 构建模拟日志输出容器
VOLUME [ “/var/app” ]
运行多个容器,x容器往/var/log/appx/appx.log写入内容
a. loger1向 /var/log/目录下的app1.log 写入 “hello, docker!By logger1”
b. loger2 向/var/log/目录下的app2.log写入 “hello, ghostcloud!By logger2”
运行日志输出的容器
3. 运行logstash容器
docker run –name logstash –volumes-fromlogger1 –volumes-from logger2 logstash
脚本:Dockerfile
FROM ubuntu:14.04
ENV REFRESHED_AT 2014-06-01
RUN apt-get -yqq update
RUN apt-get -yqq install wget
RUN wget -O - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add -
RUN echo 'deb http://packages.elasticsearch.org/logstash/1.4/debian stable main' > /etc/apt/sources.list.d/logstash.list
RUN apt-get -yqq update
RUN apt-get -yqq install logstash
ADD logstash.conf /etc/
WORKDIR /opt/logstash
ENTRYPOINT [ "bin/logstash" ]
CMD [ "--config=/etc/logstash.conf" ]
配置文件
input {
file {
type => "sysem"
path => ["/var/log/app1/app1.log", "/var/log/app2/app2.log"]
}
}
output {
stdout {
codec => rubydebug
}
}