您的位置:首页 > 运维架构 > Linux

Centos7安装Logstash及基本配置

2017-04-15 20:53 232 查看
安装可以直接用yum安装

配置在/etc/logstash/conf.d

写任何配置文件,任何名都行,比如

vi log_file.conf

然后可以service logstash start了

先说Input:

读取文件基本格式如下:

input

{

    file {

        path => ["/var/log/*.log", "/var/log/message"]

        type => "system"

        start_position => "beginning"

    }
}

这里实用字段如下:

discover_interval:每隔多久去检查一次被监听的 path 下是否有新文件。默认值是 15 秒。

exclude:不想被监听的文件可以排除出去,这里跟 path 一样支持 glob 展开。

sincedb_path:如果你不想用默认的 $HOME/.sincedb(Windows 平台上在 C:\Windows\System32\config\systemprofile\.sincedb),可以通过这个配置定义 sincedb 文件到其他位置。

sincedb_write_interval:logstash 每隔多久写一次 sincedb 文件,默认是 15 秒。

stat_interval:logstash 每隔多久检查一次被监听文件状态(是否有更新),默认是 1 秒。

start_position:logstash 从什么位置开始读取文件数据,默认是结束位置,也就是说 logstash 进程会以类似 tail -F 的形式运行。如果你是要导入原有数据,把这个设定改成 "beginning",logstash 进程就从头开始读取,有点类似 cat,但是读到最后一行不会终止,而是继续变成 tail -F。

数据处理案例:

filter {

    grok {

        match => {

            "message" => "\s+(?<request_time>\d+(?:\.\d+)?)\s+"

        }

    }

}

如果用json:

filter {

    json {

        source => "message"

    }

   grok {

        overwrite => ["@timestamp"]

    }

}

Output配置(输出到elasticsearch):

output {

  # For detail config for elasticsearch as output,

  # See: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html
  elasticsearch {

    action => "index"          #The operation on ES

    hosts  => "192.168.6.11:9200"   #ElasticSearch host, can be array.

    index  => "log"         #The index to write data to.

  }

}

如果想以某个字段为唯一索引,后面有相同数据就更新:

output {

    elasticsearch {

        hosts => ["192.168.6.11:9200"]

        index => "log"

        workers => 1

        flush_size => 1

        idle_flush_time => 1

        document_id => "%{od_id}"

        doc_as_upsert => true

        action => "update"

    }

}

具体配置:
http://udn.yyuap.com/doc/logstash-best-practice-cn/index.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: