修改配置文件 logstash-sample.conf :
# input{ } ,elasticsearch{ }不需要修改 output{ }需要添加自己配置的服务
input {
redis {
data_type =>"list"
key =>"default_list"
host =>"10.253.100.121"
port => 6379
threads => "8"
batch_count => "1"
password => "cjkj2020"
db => 1
codec => json
}
}
设置索引:
output {
# log_type和之前配置的自定义字段对应
if [fields][log_type] == "action" {
elasticsearch {
hosts => ["http://10.253.96.81:9200","http://10.253.96.123:9200","http://10.253.96.124:9200"]
index => "action " #定义一个索引的名称
}
}
if [fields][log_type] == "gateway" {
elasticsearch {
hosts => ["http://10.253.96.81:9200","http://10.253.96.123:9200","http://10.253.96.124:9200"]
index => "gateway "
}
}
修改完之后,服务会自动加载配置,一般情况下不需要重启
如需重启:./logstash -f ../config/logstash-sample.conf --config.reload.automatic &
如果服务都重启好了 可以在es-head观察是否创建好了刚刚设置的索引: