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. Spring 使用注解方式进行事务管理

    转载:http://www.cnblogs.com/younggun/archive/2013/07/16/3193800.html 使用步骤: 步骤一.在spring配置文件中引入<tx:&g ...

  2. REVOKE DBA权限要小心

      REVOKE DBA权限要小心 转载:http://blog.csdn.net/lwei_998/article/details/6133557 发现某些用户有DBA权限的时候,为了安全,一般我们 ...

  3. 事务报错 [Exception] 当前 TransactionScope 已完成

    捕获异常的时候 偶尔会碰到这个异常报告 导致原因 //正确代码 using (TransactionScope ts = new TransactionScope(TransactionScopeOp ...

  4. LeetCode Linked List Cycle 单链表环

    题意:给一个单链表,判断其是否出现环! 思路:搞两个指针,每次,一个走两步,另一个走一步.若有环,他们会相遇,若无环,走两步的指针必定会先遇到NULL. /** * Definition for si ...

  5. 我的ECshop二次开发从零开始

    我是一个EC新手,EC就算做再多的模板,肯定也满足不了我们的需要,更何况各行有各行的门道,EC统一做出来的模板也不一定合适于我们这个行业用,因此,只有我们真正掌握了自己做模板,修改模板的功夫,才能真正 ...

  6. 构建属于自己的ORM框架之二--IQueryable的奥秘

    上篇文章标题乱起,被吐槽了,这次学乖了. 上篇文章中介绍了如何解析Expression生成对应的SQL语句,以及IQueryable的一些概念,以及我们所搭建的框架的思想等.但还没把它们结合并应用起来 ...

  7. HDU 1247 Hat’s Words

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. [转] arcgis Engine创建shp图层

    小生 原文 arcgis Engine创建shp图层 以创建点图层为例.首先要得到保存文件的地址. SaveFileDialog saveFileDialog = new SaveFileDialog ...

  9. delphi7在win7系统如何安装spcomm控件

    1.先准备好串口控件SPCOMM,例如把它放在F盘的工具安装文件夹下,等一下加载时需要用到. 2.打开delphi7软件. 3.按下上面的Component>Install  Component ...

  10. MockMvc和Mockito之酷炫使用

    由于项目中需要添加单元测试,所以查询之后发现Mockito非常适合现在的web项目. 首先需要添加pom依赖: <dependency> <groupId>junit</ ...