首先上传logstash-7.3.0.tar.gz和mysql-connector-java-5.1.6.jar到服务器(这里我使用的个人的版本,大家可以换成自己的版本)然后解压缩tar -zxvf logstash-7.3.0.tar.gzcd 到 logstash-7.3.0执行./bin/logstash-plugin install logstash-input-jdbc执行./bin/logstash-plugin install logstash-output-elasticsearchcd到bin目录,并且创建config-mysql目录,然后在config-mysql目录中创建myslq.conf文件在myslq.conf文件中配置一下内容
input
{
jdbc
{
jdbc_driver_library
=> "/usr/local/soft/logstash-7.3.0/mysql-connector-java-5.1.6.jar"
jdbc_driver_class
=> "com.mysql.jdbc.Driver"
jdbc_connection_string
=> "jdbc:mysql://ip地址:3306/数据库名?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC"
jdbc_user
=> "用户名"
jdbc_password
=> "密码"
schedule
=> "* * * * *"
statement
=> "select * from 要同步的表"
}
}
output
{
elasticsearch
{
hosts
=> "127.0.0.1" #连接es的ip
index
=> "mysqlindex" #索引
document_id
=> "%{id}" # 与sql语句查出来的id一样
document_type
=> "type"
}
stdout
{ codec
=> rubydebug
}
}
./bin/logstash -f ./config-mysql/mysql.conf 启动