Elasticsearch:将Logstash日志存到elasticsearch中

配置Logstash

TypeScript 复制代码
# cat syslog02.conf
#filename:syslog02.conf #注意这个是要用#号注释掉
input{
    file{
        path => ["/var/log/*.log"]
    }
}
output{
    elasticsearch {
        #建议将搜索引擎不要和应用部署到一台服务器,我们介绍就同台服务器
        hosts => ["192.168.1.1:9200"]  
    }
}

查看配置文件是否有问题:

TypeScript 复制代码
# ../bin/logstash -f syslog02.conf -t
Sending Logstash's logs to /usr/local/logstash/logs which is now configured via log4j2.properties
[2016-12-01T09:54:46,512][FATAL][logstash.runner ] The given configuration is invalid. Reason: Expected one of #, input, filter, output at line 1, column 1 (byte 1) after

在output -> elasticsearch下增加一个index配置:

TypeScript 复制代码
cat syslog02.conf
#filename:syslog02.conf
input{
    file{
        path => ["/var/log/*.log"]
        format => json
    }
}
output{
    elasticsearch {
        hosts => ["192.168.1.1:9200"]
        index => "syslog02_log%{jsonsrt}"
    }
}

再次简测配置文件:

TypeScript 复制代码
# ../bin/logstash -f syslog02.conf -t
Sending Logstash's logs to /usr/local/logstash/logs which is now configured via log4j2.propertiesConfiguration OK
[2016-12-01T11:40:56,791][INFO ][logstash.runner ] Using config.test_and_exit mode. Config Validation Result: OK. Exiting Logstash

启动并在后台执行:

TypeScript 复制代码
# ../bin/logstash -f syslog02.conf &

hosts:["127.0.0.1:9200","127.0.0.2:9200"]

action:指定es的行为,index, delete, create, update

默认为index:index a document(该document就是一个来自于logstash的event)

delete:通过id删除一个document(需要指定document_id)

create:index a document(如果该document已经在index中存在,则失败)

update:通过id更新一个document

cacert:验证server合法性的.cer或.pem文件路径

codec:

document_id

document_type

index:默认值:logstash-%{+YYYY.MM.dd}

便于删除老数据

在语法解析的时候,看到+号开头的,会自动认为后面是时间格式,尝试用时间格式来解析后续字符串。所以,之前处理过程中不要给自定义的字段起一个+号开头的名字

索引名中不能有大写字母

有时也会自定义为:logstash-%{servicename}-%{+YYYY.MM.dd}

user:进入es cluster的用户

password:进入es cluster的密码

timeout:Set the timeout for network operations and requests sent Elasticsearch. If a timeout occurs, the request will be retried.

flush_size:默认500,logstash攒够500条数据再一次性向es发送

idle_flush_time:默认1s,如果1s内没攒够500条还是会一次性将攒的数据发出去给es

相关推荐
jack_xu1 小时前
高频面试题:如何保证数据库和es数据一致性
后端·mysql·elasticsearch
技术项目引流1 小时前
elasticsearch查询中的特殊字符影响分析
大数据·elasticsearch·搜索引擎
yangmf20407 小时前
使用 Logstash 迁移 MongoDB 数据到 Easysearch
java·elasticsearch·搜索引擎
南客先生9 小时前
海量聊天消息处理:ShardingJDBC分库分表、ClickHouse冷热数据分离、ES复合查询方案、Flink实时计算与SpringCloud集成
java·clickhouse·elasticsearch·flink·springcloud·shardingjdbc
MaYuKang11 小时前
「ES数据迁移可视化工具(Python实现)」支持7.x索引数据互传
大数据·数据库·python·mysql·elasticsearch
Elasticsearch14 小时前
使用 AutoGen 与 Elasticsearch
elasticsearch
xmyLydia16 小时前
Kafka + Elasticsearch 构建搜索型审计日志系统实战(含 Kibana 可视化)
elasticsearch·kafka
怒放吧德德1 天前
MySQL篇:MySQL如何实时同步到ES
mysql·elasticsearch·面试
细心的莽夫1 天前
Elasticsearch复习笔记
java·大数据·spring boot·笔记·后端·elasticsearch·docker
码农周1 天前
Elasticsearch 报错 Limit of total fields [1000] has been exceeded
大数据·elasticsearch