1、版本介绍


Elasticsearch:
版本:2.4.0
 
Logstash:
版本:2.4.0
所需要的安装文件,到官网下载即可。
 
还需要对应的数据库JDBC,这里使用的是mysql-connector-java-5.1.39.jar
 
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.****"  //所有同步elasticsearch的集群信息
    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则会报错。此处应该是可以配置多个数据源。

mysql数据同步到Elasticsearch的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  7. HBase数据同步到ElasticSearch的方案

    ElasticSearch的River机制 ElasticSearch自身提供了一个River机制,用于同步数据. 这里能够找到官方眼下推荐的River: http://www.elasticsear ...

  8. Logstash:把MySQL数据导入到Elasticsearch中

    Logstash:把MySQL数据导入到Elasticsearch中 前提条件 需要安装好Elasticsearch及Kibana. MySQL安装 根据不同的操作系统我们分别对MySQL进行安装.我 ...

  9. 使用Logstash把MySQL数据导入到Elasticsearch中

    总结:这种适合把已有的MySQL数据导入到Elasticsearch中 有一个csv文件,把里面的数据通过Navicat Premium 软件导入到数据表中,共有998条数据 文件下载地址:https ...

随机推荐

  1. linux-解决添加的网卡无法识别的问题

    添加网卡之后,网卡无法被正确的识别和使用排错方法 查看/etc/udev/rules.d/70-persistent-net.rules的内容,该文件中可以查看到新添加的网卡的MAC地址 修改/etc ...

  2. oracle 如何更改密码的hash

    如何迁移oracle user的密码到新的环境,一下列出了方法: select name,spare4||';'||password pwd from sys.user$ where name = ' ...

  3. this._super()

    https://learn.jquery.com/jquery-ui/widget-factory/extending-widgets/ https://api.jqueryui.com/jquery ...

  4. characteristics of competent communicators

    https://www.universalclass.com/articles/business/communication-studies/be-a-competent-communicator.h ...

  5. Android操作系统中11种传感器的介绍【转】

    本文转载自:http://www.oschina.net/question/163910_28354 在Android2.3 gingerbread系统中,google提供了11种传感器供应用层使用. ...

  6. Python编程:从入门到实践—函数

    从函数中修改列表 一家为用户提交的设计制作3D打印模型的公司,需要打印的设计存储在一个列表中,打印后移到另一个列表中. #!/usr/bin/env python # -*- coding:utf-8 ...

  7. leetcode 884. 两句话中的不常见单词 (python)

    给定两个句子 A 和 B . (句子是一串由空格分隔的单词.每个单词仅由小写字母组成.) 如果一个单词在其中一个句子中只出现一次,在另一个句子中却没有出现,那么这个单词就是不常见的. 返回所有不常用单 ...

  8. Week 12 - 673.Number of Longest Increasing Subsequence

    Week 12 - 673.Number of Longest Increasing Subsequence Given an unsorted array of integers, find the ...

  9. git.ZC_命令积累

    1.删除文件 git rm 想要删除的文件的名字及其后缀 git commit -m "对本次提交的描述信息" git push 删除文件夹,执行命令: git rm 想要删除的文 ...

  10. python3爬虫之urllib初探

    urllib主要包含request(请求模块).error(异常处理模块).parse(工具模块).robotparser(识别网站的robots.txt文件,是否允许爬取). request(请求模 ...