企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
1、制作docker镜像 ``` mkdir /data/dockerfile/filebeat cd /data/dockerfile/filebeat ``` 准备Dockerfile [root@hdss7-200 7.4.0]# cat Dockerfile ``` FROM debian:jessie ENV FILEBEAT_VERSION=7.4.0 \ FILEBEAT_SHA1=c63bb1e16f7f85f71568041c78f11b57de58d497ba733e398fa4b2d071270a86dbab19d5cb35da5d3579f35cb5b5f3c46e6e08cdf840afb7c347777aae5c4e11 RUN set -x && \ apt-get update && \ apt-get install -y wget && \ wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-${FILEBEAT_VERSION}-linux-x86_64.tar.gz -O /opt/filebeat.tar.gz && \ cd /opt && \ echo "${FILEBEAT_SHA1} filebeat.tar.gz" | sha512sum -c - && \ tar xzvf filebeat.tar.gz && \ cd filebeat-* && \ cp filebeat /bin && \ cd /opt && \ rm -rf filebeat* && \ apt-get purge -y wget && \ apt-get autoremove -y && \ apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* COPY docker-entrypoint.sh / ENTRYPOINT ["/docker-entrypoint.sh"] ``` 准备filebeat配置文件 [root@hdss7-200 7.4.0]# cat docker-entrypoint.sh ``` #!/bin/bash ENV=${ENV:-"test"} PROJ_NAME=${PROJ_NAME:-"no-define"} MULTILINE=${MULTILINE:-"^\d{2}"} cat > /etc/filebeat.yaml << EOF filebeat.inputs: - type: log fields_under_root: true fields: topic: logm-${PROJ_NAME} paths: - /logm/*.log - /logm/*/*.log - /logm/*/*/*.log - /logm/*/*/*/*.log - /logm/*/*/*/*/*.log scan_frequency: 120s max_bytes: 10485760 multiline.pattern: '$MULTILINE' multiline.negate: true multiline.match: after multiline.max_lines: 100 - type: log fields_under_root: true fields: topic: logu-${PROJ_NAME} paths: - /logu/*.log - /logu/*/*.log - /logu/*/*/*.log - /logu/*/*/*/*.log - /logu/*/*/*/*/*.log - /logu/*/*/*/*/*/*.log output.kafka: hosts: ["10.4.7.11:9092"] topic: k8s-fb-$ENV-%{[topic]} version: 2.0.0 required_acks: 0 max_message_bytes: 10485760 EOF set -xe # If user don't provide any command # Run filebeat if [[ "$1" == "" ]]; then exec filebeat -c /etc/filebeat.yaml else # Else allow the user to run arbitrarily commands like bash exec "$@" fi ``` 构建镜像 ``` chmod +x docker-entrypoint.sh docker build . -t harbor.od.com/infra/filebeat:v7.4.0 docker push harbor.od.com/infra/filebeat:v7.4.0 ``` 使用dubbo-demo-consumer的镜像,以边车模式运行filebeat [root@hdss7-200 7.4.0]# cat /data/k8s-yaml/dubbo-server/deployment.yaml ``` kind: Deployment apiVersion: extensions/v1beta1 metadata: name: dubbo-demo-consumer namespace: app labels: name: dubbo-demo-consumer spec: replicas: 1 selector: matchLabels: name: dubbo-demo-consumer template: metadata: labels: app: dubbo-demo-consumer name: dubbo-demo-consumer annotations: blackbox_path: "/hello?name=health" blackbox_port: "8080" blackbox_scheme: "http" prometheus_io_scrape: "true" prometheus_io_port: "12346" prometheus_io_path: "/" spec: containers: - name: dubbo-demo-consumer image: harbor.od.com/app/web:master_201230_1520 ports: - containerPort: 8080 protocol: TCP - containerPort: 20880 protocol: TCP env: - name: JAR_BALL value: web_learn-0.0.1-SNAPSHOT.jar # - name: C_OPTS # value: -Denv=fat -Dapollo.meta=http://config-test.zq.com imagePullPolicy: IfNotPresent #---------------- volumeMounts: - mountPath: /logm name: logm - name: filebeat #image: harbor.od.com/public/filebeat:v7.8.0 image: harbor.od.com/infra/filebeat:v7.4.0 imagePullPolicy: IfNotPresent env: - name: ENV value: test - name: PROJ_NAME value: dubbo-demo-web volumeMounts: - mountPath: /logm name: logm volumes: - emptyDir: {} name: logm #---------------- imagePullSecrets: - name: harbor restartPolicy: Always terminationGracePeriodSeconds: 30 securityContext: runAsUser: 0 schedulerName: default-scheduler strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 1 revisionHistoryLimit: 7 progressDeadlineSeconds: 600 ``` 任意node节点 kubectl apply -f http://k8s-yaml.od.com/dubbo-server/deployment.yaml 查看kafaka结果,topic打进来,即为成功 ![](https://img.kancloud.cn/bd/fe/bdfe963f27277ac833a934c32dc2e417_1138x538.png)