MySQL-ElasticSearch-数据同步
优质
小牛编辑
137浏览
2023-12-01
安装 logstash
ElasticSearch中 logstash安装和logstash-input-jdbc插件
安装 logstash-input-jdbc插件
logstash-plugin install logstash-input-jdbc
# 在有网点环境下安装,将安装插件后的 logstash 拷贝到内网环境即可使用。
编辑 jdbc.conf 和 jdbc.sql 文件
- jdbc.conf 注意不同版本参数可能不同,mysql 的 test 数据库中含有 user 表 ``` input { stdin { } jdbc {
} }# mysql jdbc connection string to our backup databse jdbc_connection_string => "jdbc:mysql://localhost:3306/test" # the user we wish to excute our statement as jdbc_user => "root" jdbc_password => "123456" # the path to our downloaded jdbc driver jdbc_driver_library => "/Users/dreamaker/.m2/repository/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar" # the name of the driver class for mysql jdbc_driver_class => "com.mysql.jdbc.Driver" jdbc_paging_enabled => "true" jdbc_page_size => "50000" statement_filepath => "jdbc.sql" schedule => "* * * * *" type => "jdbc"
filter { json { source => "message" remove_field => ["message"] } }
output { elasticsearch { hosts=> "localhost:9200"
#port => "9200"
#protocol => "http"
index => "mysql01"
document_id => "%{id}"
#cluster => "logstash-elasticsearch"
}
stdout {
codec => json_lines
}
}
* jdbc.sql
select * from user
# 启动 logstash 服务
./bin/logstash -f jdbc.conf
# 在 ES 中检索数据