logstash输出到mysql
logstash版本:6.5.3,确保 JDK 的版本是 1.8
1 安装logstash-output-jdbc
/usr/share/logstash/bin/logstash-plugin install logstash-output-jdbc
2 JDBC插件依赖mysql-connector-java-5.1.47
下载
https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-5.1.47.zip
解压安装
mkdir /etc/logstash/jdbc
cd /etc/logstash/jdbc
解压到/etc/logstash/jdbc目录
unzip mysql-connector-java-5.1.47.zip
3 数据库服务器创建的表结构
CREATE TABLE test(
ID INT NOT NULL AUTO_INCREMENT,
TIME VARCHAR(25) NOT NULL,
IP VARCHAR(20) NOT NULL,
MESSAGES VARCHAR(255) NOT NULL,
PRIMARY KEY (ID)
);
4 配置logstash的output
output {
jdbc {
driver_jar_path => "/etc/logstash/jdbc/mysql-connector-java-5.1.47/mysql-connector-java-5.1.47-bin.jar"
driver_class => "com.mysql.jdbc.Driver"
connection_string => "jdbc:mysql://mysql服务器ip:端口/数据库?user=数据库用户名&password=数据库密码"
statement => [ "insert into 数据表 (TIME ,IP,MESSAGES) values (?,?,?)","%{@timestamp}" ,"%{host}","%{message}" ]
}
}
原文地址:https://www.cnblogs.com/longBlogs/p/10340252.html