侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

使用go-mysql-elasticsearch包实现将mysql数据同步elasticsearch的流程步骤

Go  /  管理员 发布于 3星期前   67

go-mysql-elasticsearch是一项将MySQL数据自动同步到 Elasticsearch 的服务。

它首先使用mysqldump获取原始数据,然后使用 binlog 逐步同步数据。


github:

https://github.com/go-mysql-org/go-mysql-elasticsearch


注意事项

1.当前环境需要 mysqldump 工具取导出数据

2.阿里云的数据库需要 skip_master_data = true

3.源代码里 是使用 update 方法取修改文档数据,而不是 index 方法

4.master 节点 binglog 日志设长点 不然的话 等 dump 完 之前的同步位点的 log 日志就会丢失


使用步骤:

配置文件

# MySQL address, user and password
# user must have replication privilege in MySQL.
my_addr = "localhost"
my_user = "root"
my_pass = "root"
my_charset = "utf8mb4"
# Set true when elasticsearch use https
#es_https = false
# Elasticsearch address
es_addr = "elasticsearch.addr"
# Elasticsearch user and password, maybe set by shield, nginx, or x-pack
es_user = ""
es_pass = ""
# Path to store data, like master.info, if not set or empty,
# we must use this to support breakpoint resume syncing. 
# TODO: support other storage, like etcd. 
data_dir = "./postion"
# Inner Http status address
stat_addr = "127.0.0.1:12800"
stat_path = "/metrics"
# pseudo server id like a slave 
server_id = 1
# mysql or mariadb
flavor = "mysql"
# mysqldump execution path
# if not set or empty, ignore mysqldump.
mysqldump = "mysqldump"
# if we have no privilege to use mysqldump with --master-data,
# we must skip it.
skip_master_data = false
# minimal items to be inserted in one bulk
bulk_size = 128
# force flush the pending requests if we don't have enough items >= bulk_size
flush_bulk_time = "200ms"
# Ignore table without primary key
skip_no_pk_table = true
# MySQL data source
[[source]]
schema = "a"
tables = ["b"]
# Below is for special rule mapping
[[rule]]
schema = "a"
table = "b"
index = "es_index_v1"
type = "_doc"
id = ["id"]
filter = ["id","refine_timestamp"]
[rule.field]
# Map column `id` to ES field `es_id`
refine_timestamp = "refineTimestamp"

它主要是用 go 去请求 es 提供的 rest-api实现同步的。


  • 上一条:
    Laravel Pail扩展包 - 跟踪日志文件的最简单方法
    下一条:
    如何构建 Laravel + MongoDB 后端服务
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在go语言中实现原子操作示例代码(0个评论)
    • 在go语言中实现蒙提霍尔(三门问题)示例代码(0个评论)
    • 在go语言种获取进程ID后面的可执行文件名示例代码(0个评论)
    • 在go语言如何确定时间变量是否具有相同的日历日?(0个评论)
    • 在go语言中使用PGX CopyFrom扩展包实现向Postgres数据库插入数据示例(1个评论)
    • 近期文章
    • 在ubuntu系统中实现mysql数据存储目录迁移流程步骤(0个评论)
    • 在mysql中使用存储过程批量新增测试数据流程步骤(0个评论)
    • docker + gitea搭建一个git服务器流程步骤(0个评论)
    • Laravel 10.34版本发布(0个评论)
    • PHP8中的JIT编译器可以将代码性能提高20%以上(0个评论)
    • 在php语言中实现网站ssl证书过期时间检查功能示例代码(0个评论)
    • 在php语言中实现谷歌登陆功能:google授权api示例代码(0个评论)
    • 在php语言中实现文件加密功能示例(0个评论)
    • 以优雅的方式编写应用程序接口集成和 SDK(0个评论)
    • 在php+laravel项目中使用Saloon扩展包编写API集成(0个评论)
    • 近期评论
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 路人 在

      php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..
    • 博主 在

      科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 @ mashrdn 多切换几个节点测试,免费ssr是没那么稳..
    • mashrdn 在

      科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 V2rayn免费节点添加上去了,youtobe无法打开网页,是怎么回事..
    • 2016-10
    • 2017-09
    • 2020-03
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-12
    • 2021-01
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-04
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-11
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客