利用logstash将mysql数据同步到Elasticsearch
1 准备环节
a 下载logstash到服务器的目录,如:/data/soft/logstash-device
b 安装jdk1.8
c 将mysql-connector-java-5.1.35-bin.jar 放到/data/soft/logstash-device/driver/目录下
2 编写conf文件放到logstash-device目录下,如
input {
jdbc {
#Document url https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html
jdbc_driver_library => "/data/soft/logstash-device/driver/mysql-connector-java-5.1.35-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://xxx:3306/data"
jdbc_user => "user"
jdbc_password => "xxx"
jdbc_validate_connection => true
jdbc_paging_enabled => true
jdbc_page_size => 10000
schedule => "*/59 * * * *"
statement => "SELECT * from t where updatetime >= :sql_last_value"
record_last_run => true
last_run_metadata_path => "last_activelogindate_parameter.txt"
}
}
output {
elasticsearch {
index => "u"
document_type => "t"
document_id => "%{id}"
hosts => "xxx:9200"
}
}
3 启动
setsid /data/soft/logstash-device/bin/logstash --debug -f /data/soft/logstash-device/device-index-logstash.conf&
注:适用于数据同步不是很实时的场景,如果要求对数据同步实时性很高的,此方案就不是很合适
本文介绍如何使用Logstash将MySQL数据库中的数据同步至Elasticsearch,包括配置步骤及注意事项,适合数据同步需求非实时的场景。
469

被折叠的 条评论
为什么被折叠?



