项目须要,使用logstash定时读取log文件,并插入mysql数据库中,output使用logstash-output-jdbc插件。该插件不是默认安装的,须要使用命令:bin/logstash-plugin install logstash-output-jdbc去官方拉取。在不联网的电脑上,这种方法就不可行了,解决:在可联网的电脑安装完这个插件后,把整个logstash文件夹拷贝到没法联网的电脑。html
jdbc插件依赖mysql-connector-java-5.1.41-bin.jar包,下载后放到任一目录下,并在output里写明java
output{mysql
jabc{git
driver_jar_path => "jar报完整路径"github
driver_class => "com.mysql.jdbc.Driver"sql
connection_string => "jdbc:mysql://ip:3306//DBName?autoReconnect=true&usrSSL=true&user=username&password=pwd"数据库
statement => ["insert into table(column1,column2) values(?,?)","%{[message][1]}","%{[message][2]}"]ide
}ui
}插件
(拷贝后,运行bin/logstash -f test.conf时可能提示注册插件失败,再次运行bin/logstash-plugin install --no-verify logstash-output-jdbc偶尔能够解决该问题,暂不明缘由)
注:logstash版本为5.2.2,须要jdk1.8。
参考
https://github.com/theangryangel/logstash-output-jdbc
https://www.elastic.co/guide/en/logstash/current/index.html