1.上传logstash-6.4.3.tar.gz到服务中
2.tar –zxvf logstash-6.4.3.tar.gz
3.cd logstash-6.4.3
4. bin/logstash-plugin install logstash-input-jdbc
5. bin/logstash-plugin install logstash-output-elasticsearch
新写一个mysql.conf 放到 logstash-6.4.3 这个里头
input {
jdbc {
jdbc_driver_library => "/Users/liyaochu/important/mysql-connector-java-5.1.46.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/test?serverTimezone=Asia/Shanghai&useSSL=true&useUnicode=true&characterEncoding=UTF-8"
jdbc_user => "root"
jdbc_password => "root"
schedule => "* * * * *"
statement => "SELECT * FROM user WHERE update_time >= :sql_last_value"
use_column_value => true
tracking_column_type => "timestamp"
tracking_column => "update_time"
last_run_metadata_path => "syncpoint_table"
type => "jdbc"
}
}
output {
elasticsearch {
# ES的IP地址及端口
hosts => ["localhost:9200"]
# 索引名称 可自定义
index => "user"
# 需要关联的数据库中有有一个id字段,对应类型中的id
document_id => "%{id}"
document_type => "user"
}
stdout {
# JSON格式输出
codec => json_lines
}
}
最后
上传/Users/liyaochu/important/mysql-connector-java-5.1.46.jar" 需要这个jia包
./bin/logstash -f mysql.conf 启动
二.多文件方式同步ES数据
一个 logstash 实例可以借助 pipelines 机制同步多个表,只需要写多个配置文件就可以了,假设我们有两个表 table1 和 table2,对应两个配置文件 sync_table1.cfg 和 sync_table2.cfg
在 config/pipelines.yml 中配置
- pipeline.id: table1 path.config: "config/mysql.conf" - pipeline.id: table2 path.config: "config/mysql.2conf" |
./bin/logstash