1、版本介绍


Elasticsearch:
版本:2.4.0
 
Logstash:
版本:2.4.0
所需要的安装文件,到官网下载即可。
 
还需要对应的数据库JDBC,这里使用的是mysql-connector-java-5.1.39.jar
 
Elasticsearch配置请参照之前的博客,不在这里介绍了。
 
2、Logstash安装配置
 
Logstash直接下载后解压即可,主要是配置文件的内容编写。
 
安装logstash-input-jdbc的Logstash插件,用来进行mysql、oracle等的数据同步。
 
[zsz@VS-zsz logstash-2.4.0]$ bin/plugin install logstash-input-jdbc

The use of bin/plugin is deprecated and will be removed in a feature release. Please use bin/logstash-plugin.

Validating logstash-input-jdbc

Installing logstash-input-jdbc

Installation successful
 
配置文件(自行指定文件名,这里命名为logstash-mysql.conf ):
[zsz@VS-zsz conf]$ vi logstash-mysql.conf 
input {

  jdbc {

    jdbc_driver_library => "/usr/local/logstash-2.4.0/mysql-connector-java-5.1.39.jar"

    jdbc_driver_class => "com.mysql.jdbc.Driver"

    jdbc_connection_string => "jdbc:mysql://192.168.****:3306/******?characterEncoding=UTF-8&useSSL=false"

    jdbc_user => "*****"

    jdbc_password => "*********"

    statement => "SELECT * FROM news limit 0,1"

    jdbc_paging_enabled => "true"

    jdbc_page_size => "50000"

    schedule => "* * * * *"

  }

}

filter {

   json {

        source => "message"

        remove_field => ["message"]

    }

}

output {

  stdout {

    codec => rubydebug

  }

  elasticsearch {

    hosts => "192.168.****"

    index => "myindex"

  }        

 
启动Logstash
[zsz@VS-zsz conf]$ /usr/local/logstash-2.4.0/bin/logstash -f /usr/local/logstash-2.4.0/conf/logstash-mysql.conf 
Settings: Default pipeline workers: 2

Pipeline main started

{

                  "pk" => 8,

             "user_pk" => 11,

            "media_pk" => 5,

            "topic_pk" => 0

}

{

                  "pk" => 8,

             "user_pk" => 11,

            "media_pk" => 5,

            "topic_pk" => 0

}
........
 
这个进程会一直执行下去,因为设置的schedule => "* * * * *"(每分钟执行一次),如果想结束进程需要kill掉进程。
 
 
查看elasticsearch是否同步数据成功
[root@VS-zsz conf]# curl '192.168.31.79:9200/_cat/indices?v'

health status index   pri rep docs.count docs.deleted store.size pri.store.size

green  open   test      5   1          0            0      1.5kb           795b

green  open   myindex   5   1        494            0    924.7kb        457.6kb
[root@VS-zsz conf]# curl '192.168.31.78:9200/_cat/indices?v'

health status index   pri rep docs.count docs.deleted store.size pri.store.size

green  open   test      5   1          0            0      1.5kb           795b

green  open   myindex   5   1        494            0      925kb        457.8kb
[root@VS-zsz conf]# curl '192.168.31.79:9200/_cat/indices?v'

health status index   pri rep docs.count docs.deleted store.size pri.store.size

green  open   test      5   1          0            0      1.5kb           795b

green  open   myindex   5   1        494            0      925kb        457.8kb 
 
说明数据成功导入,而且在设置了定时任务的情况下, myindex索引的容量不断增加。
 
5、常见错误:
(1)Pipeline aborted due to error {:exception=>"LogStash::ConfigurationError", :backtrace=>..................stopping pipeline {:id=>"main"}
原因:logstash-mysql.conf 文件配置错误,对于>=2.*的版本, elasticsearch 的参数名应为hosts,如果设置为host则会报错。此处应该是可以配置多个数据源。
 
 
 

Elasticsearch和mysql数据同步(logstash)的更多相关文章

  1. Elasticsearch和mysql数据同步(elasticsearch-jdbc)

    1.介绍 对mysql.oracle等数据库数据进行同步到ES有三种做法:一个是通过elasticsearch提供的API进行增删改查,一个就是通过中间件进行数据全量.增量的数据同步,另一个是通过收集 ...

  2. 几篇关于MySQL数据同步到Elasticsearch的文章---第一篇:Debezium实现Mysql到Elasticsearch高效实时同步

    文章转载自: https://mp.weixin.qq.com/s?__biz=MzI2NDY1MTA3OQ==&mid=2247484358&idx=1&sn=3a78347 ...

  3. Mysql数据同步Elasticsearch方案总结

    Mysql数据同步Elasticsearch方案总结 https://my.oschina.net/u/4000872/blog/2252620

  4. ElasticSearch5+logstash的logstash-input-jdbc实现mysql数据同步

    在实现的路上遇到了各种坑,再次验证官方文档只能产考不能全信! ElasticSearch安装就不说了上一篇有说! 安装logstash 官方:https://www.elastic.co/guide/ ...

  5. mysql数据同步到Elasticsearch

    1.版本介绍 Elasticsearch: https://www.elastic.co/products/elasticsearch 版本:2.4.0   Logstash: https://www ...

  6. 几篇关于MySQL数据同步到Elasticsearch的文章---第五篇:logstash-input-jdbc实现mysql 与elasticsearch实时同步深入详解

    文章转载自: https://blog.csdn.net/laoyang360/article/details/51747266 引言: elasticsearch 的出现使得我们的存储.检索数据更快 ...

  7. 几篇关于MySQL数据同步到Elasticsearch的文章---第三篇:logstash_output_kafka:Mysql同步Kafka深入详解

    文章转载自: https://mp.weixin.qq.com/s?__biz=MzI2NDY1MTA3OQ==&mid=2247484411&idx=1&sn=1f5a371 ...

  8. 几篇关于MySQL数据同步到Elasticsearch的文章---第二篇:canal 实现Mysql到Elasticsearch实时增量同步

    文章转载自: https://mp.weixin.qq.com/s?__biz=MzI2NDY1MTA3OQ==&mid=2247484377&idx=1&sn=199bc88 ...

  9. 几篇关于MySQL数据同步到Elasticsearch的文章---第四篇:使用go-mysql-elasticsearch同步mysql数据库信息到ElasticSearch

    文章转载自: https://www.cnblogs.com/dalaoyang/p/11018541.html 1.go-mysql-elasticsearch简介 go-mysql-elastic ...

随机推荐

  1. UVa 1152 4 Values whose Sum is 0

    题意:给出n,四个集合a,b,c,d每个集合分别有n个数,分别从a,b,c,d中选取一个数相加,问使得a+b+c+d=0的选法有多少种 看的紫书,先试着用hash写了一下, 是用hash[]记录下来a ...

  2. NoSQL 数据库系统对比

    虽然SQL数据库是非常有用的工具,但经历了15年的一支独秀之后垄断即将被打破.这只是时间问题:被迫使用关系数据库,但最终发现不能适应需求的情况不胜枚举. 但是NoSQL数据库之间的不同,远超过两 SQ ...

  3. Java [Leetcode 228]Summary Ranges

    题目描述: Given a sorted integer array without duplicates, return the summary of its ranges. For example ...

  4. Android精美的日历控件

    网上看到的精美日历控件,谨以此文记录一下,用到的时候再来翻翻 源码地址 : http://download.csdn.net/detail/abc13939746593/7265459

  5. 多线程程序设计学习(5)balking模式和timed模式

    Balking[返回模式]timed[超时模式]一:balking pattern的参与者--->GuardedObject(被警戒的对象) --->该模式的角色:模拟修改警戒对象的线程, ...

  6. MySQL基础之第8章 视图

    8.1.视图简介 视图由数据库中的一个表,视图或多个表,视图导出的虚拟表.其作用是方便用户对数据的操作. 8.2.创建视图必须要有CREATE VIEW 和 SELECT 权限SELECT selec ...

  7. Delphi 2010

    Delphi 2010已早由Embarcadero公司发布.作者Kim Madsen作为一名资深的Delphi开发者,在他的博客中谈到了Delphi 2010的新性能.它的使用感受以及对Delphi语 ...

  8. 国外主流PHP框架比较

    最近简单的使用了目前在国内用的比较多的几个主流国外PHP框架(不包括国内框架),大致对这些框架有个直观上的感受,简单分享一下,对于哪些做框架选型的时候,权当一个参考. 主要参考的框架包括:CodeIg ...

  9. RecordWriter接口解析

    RecordWriter是将Map/Reduce结果(Key-Value)输出到文件系统中. /** * <code>RecordWriter</code> writes th ...

  10. Object类介绍

    一.Object类介绍