• sidecar收集Tomcat日志-普通用户


    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"]
  • 相关阅读:
    延迟任务
    xxl-job 执行器调度
    Linux查看日志定位问题
    docker 远程连接
    sqlserver的备份和恢复 命令非计划任务
    创建带包含列的索引 sqlserver
    exec sp_executesql (sqlsugar使用中的坑)的坑。执行sql非常慢
    vue elementui的表单设计器
    将docker容器的配置导出为docker-compose.yml
    异步通信,rpc通信的笔记
  • 原文地址:https://www.cnblogs.com/hixiaowei/p/12148891.html
Copyright © 2020-2023  润新知