V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
rqxiao
V2EX  ›  程序员

请教 es 同步 mysql 数据的实现方法

  •  
  •   rqxiao · 2019-11-25 16:51:49 +08:00 · 4513 次点击
    这是一个创建于 1585 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近项目里用了 es 代替对数据库的查询

    q:(但看了下 基本都是对表字段精确查询 如 activityid= and pid= 这种精确查询用 es 是不是不是很必要?)

    看了下 代码里可以用 ElasticsearchRepository 这种简单的 crud 同步数据库操作 logstash 也可以实现,但试了下 table_01 的 id 与 es 中的 index/type 的 id 要有对应关系,

    q:(且如果是删除库里的一条操作,使用 logstash 来让 es 同步的话 ,那库里的删除操作要设为逻辑操作才行吗?)

    q:(如果 mysql 中的表与 es 没有主键的对应关系,logstash 能同步吗)

    大家实际在项目中使用 es 是怎么处理同步数据库操作的

    9 条回复    2019-11-26 13:44:34 +08:00
    nyjy997
        1
    nyjy997  
       2019-11-25 17:11:42 +08:00
    logstash 数据同步还不错.
    gz911122
        2
    gz911122  
       2019-11-25 17:16:40 +08:00
    我们直接读的 mysql binlog 来同步的
    tsl0922
        3
    tsl0922  
       2019-11-25 17:36:26 +08:00
    binlog 方式同步的可以用: https://github.com/siddontang/go-mysql-elasticsearch
    cocacola99
        4
    cocacola99  
       2019-11-25 17:48:34 +08:00
    业务逻辑 -> 消息队列 -> 脚本处理
    ziiber
        5
    ziiber  
       2019-11-25 18:31:18 +08:00
    自建 Mysql 的话一般是用 binlog 监听,如果是阿里云 RDS 的话推荐使用阿里云的 DTS 数据订阅服务。

    Binlog 方案:
    监听 binlog 日志 > 消息队列 > 消费客户端

    ## PHP
    https://github.com/krowinski/php-mysql-replication
    https://github.com/telanflow/laravel-binlog

    ## Go
    https://github.com/siddontang/go-mysql-elasticsearch

    ## Java
    https://github.com/shyiko/mysql-binlog-connector-java
    vikeria
        6
    vikeria  
       2019-11-26 08:52:55 +08:00
    canal ?
    cion
        7
    cion  
       2019-11-26 09:08:49 +08:00
    如果要自己做的话就用 Canal 吧,想做什么处理都容易
    kiddingU
        8
    kiddingU  
       2019-11-26 09:26:06 +08:00
    1、logstash jdbc plugin 2、唐刘写的 go-mysql-elasticsearch,不过这玩意不稳定,自己生产环境使用时,发生过意外 3、基于 canal 自己开发
    capljf
        9
    capljf  
       2019-11-26 13:44:34 +08:00
    同上,logstash jdbc plugin
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3930 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 10:27 · PVG 18:27 · LAX 03:27 · JFK 06:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.