1.logstash配置
[root@k8s pipeline]# cat test.conf input { file { path => ["/tmp/localhost_access_log.2020-01-04.txt"] type => "nodelog" } } filter { } output { elasticsearch { hosts => ["192.168.1.156:9200"] index => "lovelog-%{+YYY.MM.dd}" } stdout { codec => rubydebug } }
2.sidecar的配置
[root@k8s sidecar]# cat tomcat2logstash.yaml apiVersion: v1 kind: Pod metadata: name: tomcat01 spec: containers: - name: tomcat01 image: k8s.gcr.io/tomcat:centos714 volumeMounts: - name: varlog mountPath: /docker_home/local/tomcat8/logs - name: logstash01 image: k8s.gcr.io/eslogstash:7.5.1 volumeMounts: - name: varlog mountPath: /tmp - name: conffile mountPath: /usr/share/logstash/pipeline/ - name: yamlfile mountPath: /usr/share/logstash/config/ volumes: - name: varlog hostPath: path: /tmp/tomcatlog # emptyDir: {} - name: conffile hostPath: path: /usr/share/logstash/pipeline/ - name: yamlfile hostPath: path: /usr/share/logstash/config/
3.以普通用户起tomcat的Dockerfile
[root@k8s mnt]# cat Dockerfile FROM tomcat:8 #创建目录 RUN useradd -m -d /home/logstash -u 2019 -U logstash RUN mkdir -p /docker_home/local #把当前目录下的jdk文件夹添加到镜像 ADD --chown=logstash tomcat8 /docker_home/local/tomcat8 WORKDIR /docker_home/local/tomcat8/webapps USER logstash ENV CATALINA_HOME /docker_home/local/tomcat8 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin RUN chmod -R 777 /docker_home/local/tomcat8/logs/ EXPOSE 8080 CMD ["/docker_home/local/tomcat8/bin/catalina.sh","run"]