V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
monway
V2EX  ›  数据库

关于 logstash 配置问题

  •  
  •   monway · Dec 26, 2017 · 1706 views
    This topic created in 3044 days ago, the information mentioned may be changed or developed.

    我想从本地的文件中使用 logstash 导入 ElasticSearch 中,文件格式如下

    [email protected]	aaaaaaa
    [email protected]	aaaaaaa
    [email protected]	bbbbbbbb
    [email protected]	bbbbbbb
    

    我想根据每行两个字段,一行一条数据。请问该如何写 logstash 的 filter 呢?

    5 replies    2017-12-27 10:52:12 +08:00
    wayne1007
        1
    wayne1007  
       Dec 26, 2017
    logstash 的 filter 支持正则表达式
    mason961125
        2
    mason961125  
       Dec 26, 2017
    下面三个 QQ 都试了下,都是存在的。
    badttt
        3
    badttt  
       Dec 26, 2017
    这种类型数据建议使用 dissect,不要用 gork
    Terenc3
        4
    Terenc3  
       Dec 27, 2017
    1. 用 filebeat 读取文件,然后丢给 logstash 处理:

    ```

    - input_type: log
    paths:
    - [your file path here]
    tags: email_analysis

    output.logstash:
    hosts: ["your logstash host here"]

    ```


    2. logstash 用 grok 处理完成后存到 elasticsearch 或其他地方:

    ```

    filter {
    if "email_analysis" in [tags] {
    grok {
    match => { "message" => "%{NOTSPACE:username}\@%{NOTSPACE:mail_host}%{SPACE}%{NOTSPACE:your_patterns}" }
    }
    }
    }

    ```


    3. 这是 elasticsearch 的配置:

    ```

    output {
    if "email_analysis" in [tags] {
    elasticsearch {
    hosts => ["es6-node1.t.com:9200"]
    manage_template => false
    index => "your-index"
    }
    }
    }

    ```
    monway
        5
    monway  
    OP
       Dec 27, 2017
    @Terenc3 非常感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3911 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 00:47 · PVG 08:47 · LAX 17:47 · JFK 20:47
    ♥ Do have faith in what you're doing.