Logstash (7.16)官方文档路径
Logstash Reference [7.16] | Elastic
本文以Mysql数据库同步至ElasticSearch为例,进行同步。
input配置参数解释:
https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html
input {
jdbc {
#布尔类型。默认false(增量同步), 判读是否增量同步数据。true:将忽略增量,进行全量同步。
clean_up => false
#字段(列)的编码格式
columns_charset => { "column0" => "ISO-8859-1" }
#重连次数,默认1
connection_retry_attempts => 1
#重连等待时长
connection_retry_attempts => 1000
#数据库连接地址
#jdbc_connect_string =>"jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true"
# jdbc_defaulst_timezone 时区设置
#Cron表达式,执行周期
schedule => "* * * * *"
#执行的sql语句
statement => "SELECt * FROM operation_log WHERe update_time >= :sql_last_value"
#以下为组合使用,use_column_value true表示使用表中的某字段作为增量标识。tracking 指指定字段的字段名和字段类型。last_run_metadata_path 中存储最后一次同步后的值。
use_column_value => true
#追踪的值类型 支持 numeric 和 timestamp 两种类型
tracking_column_type => "timestamp"
tracking_column => "update_time"
last_run_metadata_path => "syncpoint_table"
}
output配置基础配置如下:(基础版本,不需要先创建index。logstash直接读取后插入到es中。)
https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-cloud_auth
output {
elasticsearch {
# ES的IP地址及端口
hosts => ["127.0.0.1:9200"]
# 索引名称 可自定义
index => ""
# 需要关联的数据库中有有一个id字段,对应类型中的id
document_id => "%{id}"
}
stdout {
# JSON格式输出
codec => json_lines
}
}



