Logstash 7.9.1 写数据到MySQL

个人学习笔记,谢绝转载!!!

原文:https://www.cnblogs.com/wshenjin/p/13714983.html


MySQL表结构

(root@localhost) [testdb]> show create table logstash\G
*************************** 1. row ***************************
       Table: logstash
Create Table: CREATE TABLE `logstash` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  `address` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8

MySQL官方JDBC驱动程序

[root@ ]# wget https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-5.1.49.zip
[root@ ]# unzip mysql-connector-java-5.1.49.zip
[root@ ]# cp mysql-connector-java-5.1.49/mysql-connector-java-5.1.49-bin.jar  /etc/logstash/jdbc/

安装jdbc插件

[root@ ]# bin/logstash-plugin install logstash-output-jdbc 

logstash配置

input {
  stdin{}
}
 
filter{
    grok {
        match => {
            "message" => "%{WORD:name} %{NUMBER:age} %{WORD:address}"
        }
   }
}
 
output {
  jdbc {
      driver_jar_path => "/etc/logstash/jdbc/mysql-connector-java-5.1.49-bin.jar"
      driver_class => "com.mysql.jdbc.Driver"
      connection_string => "jdbc:mysql://127.0.0.1:3306/testdb?user=root&password=20c0dc7315fe8db65cbab532818e0e7a"
      statement => [ "INSERT INTO logstash (name, age, address) VALUES(?, ?, ?)", "name", "age", "address" ]
  }
}
posted @ 2020-09-22 21:24  wshenJin  阅读(383)  评论(0编辑  收藏  举报