1、下载Logstash
logstash下载地址
环境为 windows
2、将Logstash压缩包进行解压
将 mysql 驱动文件放在文件夹内
在Logstash根目录下创建 mysql-es.conf文件
input {
jdbc {
jdbc_driver_library => "E:\linshi\mysql-connector-java-8.0.11\mysql-connector-java-8.0.11.jar" # MySQL JDBC connector路径
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://localhost:3306/database?serverTimezone=Asia/Shanghai" # 替换为你的数据库URL
jdbc_user => "root" #数据库账号
jdbc_password => "root" #数据库密码
statement => "select 字段 from 表名 where id >:sql_last_value limit 300000" # 替换为你的表名 300000条插入es一次
schedule =>"* * * * *"
use_column_value => true
tracking_column => id
tracking_column_type => numeric
record_last_run => true
last_run_metadata_path =>"E:\linshi\last_run"
}
}
filter {
mutate {
convert => {
"release_time" => "string"
}
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "index1" #索引名
#user => "elastic"
#password => "changeme"
}
}
使用命令执行conf文件
E:\linshi\logstash-8.14.3\bin\logstash -f e:\linshi\logstash-8.14.3\mysql-es.conf
执行完,出现黑窗口,等待数据入库完即可
如果想重新入es,需要删除E:\linshi\last_run文件,last_run文件中存储的条数