【十次方基础教程(后台)】安装并使用Logstash实现elasticsearch与数据库数据同步

解压安装包

进入bin文件夹下面,打开cmd

logstash-5.6.8bin

测试Logstash是否可用

logstash -e 'input { stdin { } } output { stdout {} }'

能把输入的东西照样输出来说明OK

创建模板文件(conf文件),放在任意地方

模板内容:

input {
jdbc {
# mysql jdbc connection string to our backup databse
jdbc_connection_string => "jdbc:mysql://192.168.79.130:3306/tensquare_article?characterEncoding=UTF8"
# the user we wish to excute our statement as
jdbc_user => "root"
jdbc_password => "root"
# the path to our downloaded jdbc driver
jdbc_driver_library => "E: ensquarelogstash-5.6.8mysqletcmysql-connector-java-5.1.46.jar"
# the name of the driver class for mysql
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_paging_enabled => "true"
jdbc_page_size => "20"
#以下对应着要执行的sql的绝对路径。
#statement_filepath => ""
statement => "SELECT id,title,content,state FROM tb_article"
#定时字段 各字段含义(由左至右)分、时、天、月、年,全部为*默认含义为每分钟都更新(测试结果,不同的话请留言指出)
schedule => "* * * * *"
}
}

output {
elasticsearch {
#ESIP地址与端口
hosts => "localhost:9200"
#ES索引名称(自己定义的)
index => "tensquare_article"
#自增ID编号
document_id => "%{id}"
document_type => "article"
}
stdout {
#以JSON格式输出
codec => json_lines
}
}

启动并更新

logstash -f 文件路径

如logstash -f ../mysqletc/mysql.conf

原文地址:https://www.cnblogs.com/IceBlueBrother/p/10857479.html