goreplay 輸出流量捕獲數據到 elasticsearch


goreplay 是一個很不錯的流量拷貝,復制工具,小巧,支持一些擴展,當然也提供了企業版,企業版
功能更強大,支持二進制協議的分析 。
為了方便數據的存儲,我們可以使用es 進行存儲

環境准備

docker-compose

 
version: "3"
services:
    nginx:
      build: ./
      ports:
      - "8080:80"
    app:
      image: openresty/openresty:alpine-fat
      ports:
      - "8090:80"
    app2:
      image: openresty/openresty:alpine-fat
      ports:
      - "8091:80"
    es:
      image: elasticsearch:5.6.3
      ports:
      - "9200:9200"
      - "9300:9300"
      environment:
       - http.host=0.0.0.0
       - transport.host=localhost
       - network.host=0.0.0.0
      # Disable X-Pack security: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/security-settings.html#general-security-settings
       - xpack.security.enabled=false
       - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      ulimits:
       memlock:
         soft: -1
         hard: -1
 

包含goreplay 的docker 配置

  • dockerfile
    使用了一個tini 的工具,方便后台任務運行,同時因為wget 二進制包太慢,所以直接下載add 了
 
FROM openresty/openresty:alpine-fat
LABEL author="1141591465@qq.com"
COPY gor_0.16.1_x64.tar.gz .
RUN apk add --update && apk add --no-cache tini \
    && tar xzf gor_0.16.1_x64.tar.gz -C /usr/local/bin \
    && rm gor_0.16.1_x64.tar.gz 
ENV PATH=$PATH:/usr/local/bin
ADD entrypoint.sh /entrypoint.sh
ADD goreplay.sh /goreplay.sh
ENTRYPOINT ["/sbin/tini","-s", "--", "/entrypoint.sh"]
 
 
  • entryppint.sh
#!/bin/sh
sh goreplay.sh
exec /usr/local/openresty/bin/openresty -g "daemon off;"
  • goreplay.sh
    goreplay 的運行命令,主要是進行流量的拷貝
 
#!/bin/sh
#!/bin/sh
nohup goreplay --input-raw :80 --output-http "http://app" --output-http "http://app2" --output-http-elasticsearch es:9200/gor &

啟動&測試

啟動

docker-compose up -d
 

效果

訪問 http://localhost:8080

  • docker log 信息
  • es 信息

參考資料

https://github.com/buger/goreplay/wiki/Exporting-to-ElasticSearch
https://github.com/rongfengliang/goreplay-openresty-demo.git


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM