运维&部署开源技术ELK文集

Docker部署ELK(四)-构建Logstash镜像

2017-05-07  本文已影响206人  Luomeng

Logstash

修改配置文件:

# 绑定ip
http.host: "0.0.0.0"
# 日志存放路径
path.logs: /opt/product/data/logs

Dockerfile

FROM elkbase:v1.0
MAINTAINER Luomeng
VOLUME [ "/opt/product/data/" ]
ADD ./logstash-5.4.0 /opt/product/logstash-5.4.0
ADD logstash-simple.conf /opt/product/data/elk/
ADD init.sh /root/
RUN chmod +x /root/init.sh
EXPOSE 5044
EXPOSE 4560
EXPOSE 8080
ENTRYPOINT ["/root/init.sh"]
CMD ["/usr/sbin/init"]

init.sh

#!/bin/bash
export JAVA_HOME=/opt/product/tools/jdk1.8.0_131
export PATH=$JAVA_HOME/bin:$PATH
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF8  -Duser.timezone=GMT+08"
# cd /opt/product/logstash-5.4.0/config/
# rm -rf logstash.yml
# cp /opt/product/data/elk/logstash.yml logstash.yml
/opt/product/logstash-5.4.0/bin/logstash -f /opt/product/data/logstash-simple.conf

logstash-simple.conf

input {        
    beats {
        port => "5044"
    }
}
output {
    elasticsearch {
        hosts => ["elasticsearch的ip:9200"]
        index => "logstash-tomcat-accesslog-%{+YYYY.MM.dd}"
    }          
}

文件存放在/Users/Luomeng/DockerProject/Logstash/data目录下。

构建镜像

docker build -t logstash:v1.0 .

启动容器

docker run -ti -p 5044:5044 -p 4560:4560 -p 18080:8080 logstash:v1.0 /bin/bash
查看日志是否成功启动并连接ES。

确认没问题后,用下面命令启动:

docker run --privileged --restart=always -d -ti -v /Users/Luomeng/DockerProject/Logstash/data:/opt/product/data -p 5044:5044 -p 4560:4560 -p 18080:8080 logstash:v1.0 /bin/bash

遇到问题:

上一篇下一篇

猜你喜欢

热点阅读