【问题标题】:Logstash multiple inputs multiple outputsLogstash 多输入多输出
【发布时间】:2018-11-22 18:53:10
【问题描述】:

我正在尝试使用 Logstash 在 MySQL 和 Elasticsearch 之间同步数据。

我将多个 jdbc 输入和多个输出设置为不同的弹性搜索索引......我做错了,因为一切都进入 else 块。

这是我的配置:

 input {
    jdbc {
        jdbc_connection_string => "jdbc:mysql:127.0.0.1:3306/whatever"
        jdbc_user => "xxx"
        jdbc_password => "yyy"
        jdbc_driver_library => "mysql-connector-java-5.1.41.jar"
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        schedule => "* * * * *"
        statement => "SELECT * from table1 WHERE updated_at > :sql_last_value order by updated_at"
        use_column_value => true
        tracking_column => updated_at
        type => "table1"
        last_run_metadata_path => "/opt/logstash-5.4.0/sql-last-values/table1"
    }
      jdbc {
        jdbc_connection_string => "jdbc:mysql:127.0.0.1:3306/whatever"
        jdbc_user => "xxx"
        jdbc_password => "yyy"
        jdbc_driver_library => "mysql-connector-java-5.1.41.jar"
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        schedule => "* * * * *"
        statement => "SELECT * from table2 WHERE updated_at > :sql_last_value order by updated_at"
        use_column_value => true
        tracking_column => updated_at
        type => "table2"
        last_run_metadata_path => "/opt/logstash-5.4.0/sql-last-values/table2"
    }
}
output {
    if [type] == "table1" {
           elasticsearch {
                hosts => ["localhost:9200"]
                index => "table1"
                document_type => "table1"
                document_id => "%{id}"
        }
        file {
                codec => json_lines
                path => "/opt/logstash-5.4.0/logs/table1.log"
        }

    } else if [type] == "table2" {
           elasticsearch {
                hosts => ["localhost:9200"]
                index => "table2"
                document_type => "table2"
                document_id => "%{id}"
        }
    } else {
         file {
                codec => json_lines
                path => "/opt/logstash-5.4.0/logs/unknown.log"
            }

    }
}

我做错了什么?一切都将进入 else 块,进入 /opt/logstash-5.4.0/logs/unknown.log

我的方法错了吗?我应该有多个文件吗?

提前谢谢你

【问题讨论】:

    标签: logstash


    【解决方案1】:

    找到解决方案!

    我用tags代替type

    input {
    jdbc { 
    ...
    tags => "table1"
    ...
    }
    jdbc { 
    ...
    tags => "table2"
    ...
    }
    }
    output {
      if "table1" in [tags] {
    
    }
    

    https://discuss.elastic.co/t/solved-multiple-logstash-config-file/51692/10

    【讨论】:

    • 我遇到了类似的问题并使用标签修复了它。似乎“类型”可以在日志字段中使用,并将覆盖输入的值,例如使用 winlogbeat,其中“type”可能是日志的偶数类型。
    • 如果您不想在输出的文档中有标签字段,也可以考虑添加元数据并删除标签。例如,您可以添加与每个标签对应的元数据,然后删除标签,然后使用这些元数据字段将不同的文档驱动到不同的输出。我写了一篇博文,在alexmarquardt.com/2018/08/31/… 上演示了这种方法。免责声明:我是 Elastic 的一名咨询工程师。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-14
    相关资源
    最近更新 更多