logstash收集日志到es

配置文件地址:/home/elk/work/logstash-6.2.3/config

vim nginx.conf

input {

file { # 指定一个文件作为输入源

path => "/usr/local/nginx/logs/access.log" # 指定文件的路径

start_position => "beginning" # 指定何时开始收集

type => "nginx-access" # 定义日志类型,可自定义

}

 

file { # 指定一个文件作为输入源

path => "/usr/local/nginx/logs/error.log" # 指定文件的路径

start_position => "beginning" # 指定何时开始收集

type => "nginx-error" # 定义日志类型,可自定义

}

 

}

filter { # 配置过滤器

grok {

match => { "message" => "%{IPORHOST:http_host} %{IPORHOST:clientip} - %{USERNAME:remote_user} \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:http_verb} %{NOTSPACE:http_request}(?: HTTP/%{NUMBER:http_version})?|%{DATA:raw_http_request})\" %{NUMBER:response} (?:%{NUMBER:bytes_read}|-) %{QS:referrer} %{QS:agent} %{QS:xforwardedfor} %{NUMBER:request_time:float}"} # 定义日志的输出格式

}

geoip {

source => "clientip"

}

}

output {

if [type] == "nginx-access" {

stdout { codec => rubydebug }

elasticsearch {

hosts => ["192.168.1.135:9200"]

user => elastic

password => elastic

index => "nginx-access-%{+YYYY.MM.dd}"

}

}

if [type] == "nginx-error" {

stdout { codec => rubydebug }

elasticsearch {

hosts => ["192.168.1.135:9200"]

user => elastic

password => elastic

index => "nginx-error-%{+YYYY.MM.dd}"

}

}

}

 

启动:

nohup /home/elk/work/logstash-6.2.3/bin/logstash -f /home/elk/work/logstash-6.2.3/config/nginx.conf >/home/elk/work/logstash-6.2.3/logs/start.log &

#-f 指定文件

也可以将配置文件信息写入/home/elk/work/logstash-6.2.3/config/pipelines.yml中(多个文件就写多行)

- pipeline.id: nginx

path.config: "/home/elk/work/logstash-6.2.3/config/nginx.conf"

- pipeline.id: 123

path.config: "/home/elk/work/logstash-6.2.3/config/123.conf"

不指定文件启动默认以pipelines.yml文件启动。

 

自动重新加载配置

为了可以自动检测配置文件的变动和自动重新加载配置文件,需要在启动的时候使用以下命令:

./bin/lagstash -f configfile.conf --config.reload.automatic

1

默认,检测配置文件的间隔时间是3秒,可以通过以下命令改变

--config.reload.interval <second>

1

如果已经运行了没有提供自动重启的logstash,可以发送一个挂起命令给logstash重新加载配置文件:

kill -1 <pid>

1

配置文件自动重载工作原理

检测到配置文件变化

通过停止所有输入停止当前pipline

用新的配置创建一个新的管道

检查配置文件语法是否正确

检查所有的输入和输出是否可以初始化

检查成功使用新的pipeline替换当前的pipeline,

检查失败,使用旧的继续工作.

在重载过程中,jvm没有重启.

注意事项

stdin输入插件不支持自动重启.

syslog作为输入源,当重载配置文件时,会崩溃.请看: https://github.com/logstash-plugins/logstash-input-syslog/issues/40

 

./bin/logstash  --path.settings ./bak.config/ 自己设定config目录

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值