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. Charles抓取手机https请求

    1.下载Charles工具,3.92破解版:http://pan.baidu.com/s/1cko2L4 密码:chmy 2.安装SSL证书,默认安装就可以 3.证书安装成功后,点击详细信息--> ...

  2. [CF1054C]Candies Distribution

    题目:Candies Distribution 传送门:http://codeforces.com/problemset/problem/1054/C 分析: 方法一: 1)类似拓扑排序的做法. 2) ...

  3. [CSP-S模拟测试]:小P的2048(模拟)

    题目描述 最近,小$P$迷上了一款叫做$2048$的游戏.这块游戏在一个$n\times n$的棋盘中进行,棋盘的每个格子中可能有一个形如$2^k(k\in N^*)$的数,也可能是空的.游戏规则介绍 ...

  4. CSS札记(一):CSS选择器

    一.语法规则 选择器{ 属性1:属性值1; 属性2:属性值2; ...... } /*注释*/ 二.如何在html中应用CSS 1. 外部引用css文件 css文件:css/layout.css(cs ...

  5. InfluxDB安装使用

    influxdb简介   启动步骤 服务启停:sudo service influxdb start/stop/restart 安装过程: 1.增加yum源 cat <<EOF | sud ...

  6. docker-compose部署kafka

    docker-compose.yml version: '2' services: zookeeper: image: develop-harbor.geostar.com.cn/3rd/zookee ...

  7. 永久关闭Linux的防火墙

    重启网络服务,加载网卡配置文件systemctl restart network 清空防火墙规则iptables -F 关闭selinux防火墙vi /etc/selinux/config修改如下配置 ...

  8. Log4net记录日志到本地或数据库

    OperatorLog /****** Object: Table [dbo].[OperatorLog] Script Date: SET ANSI_NULLS ON GO SET QUOTED_I ...

  9. redux源码浅入浅出

    运用redux有一段时间了,包括redux-thunk和redux-saga处理异步action都有一定的涉及,现在技术栈转向阿里的dva+antd,好用得不要不要的,但是需要知己知彼要对react家 ...

  10. (转)grep命令

    1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全局 ...