go-mysql-elasticsearch 使用

2023-05-16

文档

github 链接:GitHub - go-mysql-org/go-mysql-elasticsearch: Sync MySQL data into elasticsearch

参考博客

注意事项

  1. go-mysql-elasticsearch启动以后不能进行修改表结构
  2. 使用go-mysql-elasticsearch的必需要添加就是先开启binlog模式
  3. 记得先创建索引
  4. 提前先同步数据,不然binlog日志之前的数据无法同步。
  5. 可以支持es7 和mysql8版本 不知道为啥官方文档没写可以用

优点

  • 无需三方工具直接监听 mysql binlog 即可同步数据到 es

  • 所占内存小 cpu 水位不会飙升(相对使用logstash)

监控

服务器配置 2 核 4g 代码,mysql和es在同一台服务器上

开启时间 11:00 后

测试数据1万

安装


  

Git clone https://github.com/go-mysql-org/go-mysql-elasticsearch.git
[root@hecs-202871 go-mysql-elasticsearch]# pwd
/home/golang/gopath/go-mysql-elasticsearch
#安装
go install 
#编译
make
[root@hecs-202871 go-mysql-elasticsearch]# ls
bin              cmd         elastic  go.mod  LICENSE   README.md  var
clear_vendor.sh  Dockerfile  etc      go.sum  Makefile  river
#进行配置,配置比较重要,在下边将详细去将
vim /home/golang/gopath/go-mysql-elasticsearch/etc/river.toml
#启动
 ./bin/go-mysql-elasticsearch -config=./etc/river.toml

配置river

# MySQL 的相关配置
# 指定用户必须具备复制权限
my_addr = "127.0.0.1:3306"
my_user = "canal"
my_pass = "123456"
my_charset = "utf8"

# ES 相关配置
es_addr = "127.0.0.1:9200"
es_user = ""
es_pass = ""

# Inner Http status address 不加会报错
stat_addr = "127.0.0.1:12800"
stat_path = "/metrics"

# 数据源配置
# 以 Slave 模式工作
server_id = 10001
# mysql/mariadb
flavor = "mysql"

# mysqldump 路径,如果为空或者未设置,会跳过这一环节。
mysqldump = "mysqldump"
bulk_size = 128
flush_bulk_time = "200ms"
skip_no_pk_table = false

[[source]]
# 数据库名称
schema = "canal"
# 数据表同步范围,支持通配符
tables = ["uuid"]

# 规则定义
[[rule]]
# 数据库名称
schema = "canal"
# 规则对应的数据表,支持通配符
table = "uuid"
# 目标 ES 索引
index = "uuid"
# 该规则在 ES 中生成的文档类型
type = "_doc"

其他参数

# 规则对应的数据表,支持通配符 table = "uuid*"

多表配置

# MySQL address, user and password
# user must have replication privilege in MySQL.
my_addr = "127.0.0.1:3306"
my_user = "root"
my_pass = ""
my_charset = "utf8"

# Set true when elasticsearch use https
#es_https = false
# Elasticsearch address
es_addr = "127.0.0.1:9200"
# 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 = "./var"

# Inner Http status address
stat_addr = "127.0.0.1:12800"
stat_path = "/metrics"

# pseudo server id like a slave
server_id = 1001

# 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 = false

# MySQL data source
[[source]]
schema = "test"

# Only below tables will be synced into Elasticsearch.
# "t_[0-9]{4}" is a wildcard table format, you can use it if you have many sub tables, like table_0000 - table_1023
# I don't think it is necessary to sync all tables in a database.
tables = ["t", "t_[0-9]{4}", "tfield", "tfilter"]

# Below is for special rule mapping

# Very simple example
#
# desc t;
# +-------+--------------+------+-----+---------+-------+
# | Field | Type         | Null | Key | Default | Extra |
# +-------+--------------+------+-----+---------+-------+
# | id    | int(11)      | NO   | PRI | NULL    |       |
# | name  | varchar(256) | YES  |     | NULL    |       |
# +-------+--------------+------+-----+---------+-------+
#
# The table `t` will be synced to ES index `test` and type `t`.
[[rule]]
schema = "test"
table = "t"
index = "test"
type = "t"

# Wildcard table rule, the wildcard table must be in source tables
# All tables which match the wildcard format will be synced to ES index `test` and type `t`.
# In this example, all tables must have same schema with above table `t`;
[[rule]]
schema = "test"
table = "t_[0-9]{4}"
index = "test"
type = "t"

# Simple field rule
#
# desc tfield;
# +----------+--------------+------+-----+---------+-------+
# | Field    | Type         | Null | Key | Default | Extra |
# +----------+--------------+------+-----+---------+-------+
# | id       | int(11)      | NO   | PRI | NULL    |       |
# | tags     | varchar(256) | YES  |     | NULL    |       |
# | keywords | varchar(256) | YES  |     | NULL    |       |
# +----------+--------------+------+-----+---------+-------+
#
[[rule]]
schema = "test"
table = "tfield"
index = "test"
type = "tfield"

[rule.field]
# Map column `id` to ES field `es_id`
id="es_id"
# Map column `tags` to ES field `es_tags` with array type 
tags="es_tags,list"
# Map column `keywords` to ES with array type
keywords=",list"

# Filter rule 
#
# desc tfilter;
# +-------+--------------+------+-----+---------+-------+
# | Field | Type         | Null | Key | Default | Extra |
# +-------+--------------+------+-----+---------+-------+
# | id    | int(11)      | NO   | PRI | NULL    |       |
# | c1    | int(11)      | YES  |     | 0       |       |
# | c2    | int(11)      | YES  |     | 0       |       |
# | name  | varchar(256) | YES  |     | NULL    |       |
# +-------+--------------+------+-----+---------+-------+
#
[[rule]]
schema = "test"
table = "tfilter"
index = "test"
type = "tfilter"

# Only sync following columns
filter = ["id", "name"]

# id rule
#
# desc tid_[0-9]{4};
# +----------+--------------+------+-----+---------+-------+
# | Field    | Type         | Null | Key | Default | Extra |
# +----------+--------------+------+-----+---------+-------+
# | id       | int(11)      | NO   | PRI | NULL    |       |
# | tag      | varchar(256) | YES  |     | NULL    |       |
# | desc     | varchar(256) | YES  |     | NULL    |       |
# +----------+--------------+------+-----+---------+-------+
#
[[rule]]
schema = "test"
table = "tid_[0-9]{4}"
index = "test"
type = "t"
# The es doc's id will be `id`:`tag`
# It is useful for merge muliple table into one type while theses tables have same PK 
id = ["id", "tag"]

Docker 部署

待续

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

go-mysql-elasticsearch 使用 的相关文章

  • BIT(1) 的存储大小是多少?

    我一直认为a的存储大小BIT 1 列为 1 位 But http dev mysql com doc refman 5 6 en storage requirements html http dev mysql com doc refman
  • 将mysql数据导入kubernetes pod

    有谁知道如何将我的 dump sql 文件中的数据导入到 kubernetes pod 中 直接 与处理 docker 容器的方式相同 docker exec i container name mysql uroot password se
  • 使用WordPress get_results()数据库函数是否可以防止sql注入

    似乎找不到答案 但想知道以下对数据库的查询是否容易受到 SQL 注入的攻击 searchPostResults wpdb gt get results querySearchVals OBJECT 这是使用的查询 global wpdb o
  • 基于UnixTime的MySQL动态分区

    我的数据库设计包括多个 MYISAM 表 其中包含在线收集的测量值 每行记录包含自动递增的 id 一些数据和一个表示 unixtime 的整数 我正在设计一种老化机制 并且我有兴趣使用MySQL分区来基于unixtime动态地对每个这样的表
  • 如何在SQL中编写连接查询[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 问题 给定 Employee 和 AnnualReviews 表 编写一个查询以返回所有从未接受过按 HireDate 排序的评论的员
  • 如何修复损坏的 xampp 'mysql.user' 表?

    我昨天使用 Xampp 创建了一些简单的基于 Web 的实用工具 今天我想继续研究它 但 xampp 控制面板给了我一些奇怪的错误 这是 MySQL 错误日志 2019 07 20 23 47 13 0 Note InnoDB Uses e
  • 如何列出允许登录mysql的ip?

    我知道使用下面的命令 可以允许远程IP登录MySQL GRANT select insert update delete ON TO root my ip IDENTIFIED BY my password FLUSH PRIVILEGES
  • mysql查询where条件比较char字段与int 0的一些现象

    有一桌 root localhost test 05 35 05 gt desc t Field Type Null Key Default Extra id int 11 NO PRI NULL auto increment studio
  • 最佳实践:在 PHP 中导入 mySQL 文件;分割查询

    我遇到了一种情况 我必须更新共享托管提供商上的网站 该网站有一个 CMS 使用 FTP 上传 CMS 文件非常简单 我还必须导入一个大的 相对于 PHP 脚本的范围 数据库文件 未压缩时大约 2 3 MB Mysql 已关闭 无法从外部访问
  • 减少每日状态表以仅包含状态更改

    我有一个包含 10 万以上用户的大型每日状态表 5 7 亿行 目前它位于 MySQL 或 CSV 中 该表包含三列 user id status 和 date 理想情况下 我希望将表缩减为一个新表 其中包含每个状态期间的 user id s
  • 为什么我的 php 代码无法连接到远程 MySql 数据库?

    我正在尝试连接到远程 MySql 数据库 但收到以下错误消息 警告 mysqli connect HY000 2002 连接尝试失败 因为连接方在一段时间后没有正确响应 或者由于连接的主机未能响应而建立的连接失败 在 C myLocalDi
  • MySql - 自动完成

    我正在创建一个 Ajax 自动完成应用程序 并且想知道是否有一个 SQL 查询可以用于此目的 例如 如果有人键入 p 我想检索所有以 p 开头的单词 如果他们添加 e 检索所有以 pe 开头的单词 并继续这样 有人提出了下面的查询 但我认为
  • 如何使用 Sequel Pro 在导入过程中将字符串更改为日期?

    我正在尝试使用 Sequel Pro 将文件导入到 MySQL 表中 我知道我需要使用 STR TO DATE 但我无法找出正确的语法 我在每一行都收到一堆这样的错误 ERROR in row 1 You have an error in
  • MySQL使用long类型数字过滤varchar类型时返回额外记录

    一个简单的表格 CREATE TABLE tbl type test uid varchar 31 NOT NULL DEFAULT 0 value varchar 15 NOT NULL DEFAULT PRIMARY KEY uid E
  • 如何将html表单中的信息写入MySQL数据库

    好吧 我正在建立一个带有表单的网站 我想将用户在表单中输入的所有信息保存到我的 MySQL 数据库中 表单的编码如下
  • 是否可以在MySQL UDF中的IF条件中声明游标

    我可以在 if 语句中声明游标吗 如果可能的话我怎样才能做到 因为我刚刚做了这样的光标 CREATE FUNCTION fn test ProductID BIGINT 20 RETURNS DECIMAL 10 2 BEGIN DECLA
  • 通过左连接实现精确分页

    我已经思考这个问题有一段时间了 我认为最好四处询问并听听其他人的想法 我正在构建一个在 Mysql 上存储位置的系统 每个位置都有一个类型 有些位置有多个地址 表格看起来像这样 location location id autoincrem
  • 为什么 MySQL 将 é 与 e 视为相同?

    我使用 Django Web 应用程序将 Unicode 字符串存储在 MySQL 数据库中 我可以很好地存储 Unicode 数据 但是在查询时 我发现 and e被视为好像它们是同一个角色 In 1 User objects filte
  • 如何在SQL中查找单元格中的重复单词

    我有一个名为 situation 和 entityid 的列 Entityid Situation 1234 In the the world of of 3456 Total universe is is a 任何人都可以给我查询以找到这
  • 在旧版本的 MySQL (<5.5.0) 中模拟 TO_SECONDS()

    出于性能和简单性的原因 我想以秒的形式获取 MySQL 3 x 服务器中 DATETIME 列的内容 或者实际上任何数字类型 我只是想在使用 UNIX TIMESTAMP 时避免所有明显的时区问题 the我表中的日期确实来自不同的区域设置

随机推荐

  • JS 实现复制功能(document.execCommand)

    功能 xff1a 点击按钮 xff0c 复制值 实现方法 xff1a 通过原生js 的方法document execCommand 39 copy 39 坑 xff1a document execCommand copy 不生效 不能实现的
  • Linux chmod命令 修改文件权限被禁止(not permitted)的解决办法

    解决方法 在Linux环境下 xff0c 修改文件时以外导致文件没有权限读取和修改 xff0c 在修改相关文件 usr bin docker的属性的时 chmod 777 usr bin containerd chmod changing
  • springsource-tools下载安装

    下载springsource tools我弄了一个多小时才找到下载地址 xff0c 必须得好好记录一下 首先 需要避免一个误区 xff1a 下载的不是spring tools 这个下载后是一个jar包 也不是一个可执行文件的压缩包 xff0
  • canvas节点无法导出图片_前端实现图片压缩及遇到的问题

    图片上传是前端中常见的的业务场景 无论是前台还是后台 xff0c 适当的对图片进行压缩处理 xff0c 可以显著的提升用户体验 而在后台管理系统中 xff0c 图片压缩不仅仅能够提升后台管理员操作体验 xff0c 更是可以防止后台设置过大的
  • iframe嵌套其它网站页面详解

    iframe基本内涵 通常我们使用iframe直接直接在页面嵌套iframe标签指定src就可以了 lt iframe src 61 34 demo iframe sandbox htm 34 gt lt iframe gt 但是 xff0
  • iframe嵌入其他网站,如何自适应高度

    终于有一周时间 xff0c 工作不那么忙了 xff0c 腾出手来总结下工作过程中学到的知识 每天遇到新问题 xff0c 解决新问题 xff0c 但是却很少有时间去仔细研究下 xff0c 或者总结下 攒的多了 xff0c 就得从头捋一遍 说下
  • 解决anaconda安装pil包时的问题

    在anaconda中安装pil时出现UnsatisfiableError 看了较多的解决方法 看了较多的解决方法 很多都是讲怎样创建新的环境再安装 xff0c 在Linux中只需要将这样做 xff1a xff08 Linux小白的详细操作
  • 1.5 字符串

    1 5 1 单引号 双引号 三引号 a 61 34 Hello world 34 双引号 b 61 39 python is groovy 39 单引号 c 61 34 34 34 Computer says 39 No 39 34 34
  • leetcode 1357. 每隔 n 个顾客打折(C++)

    超市里正在举行打折活动 xff0c 每隔 n 个顾客会得到 discount 的折扣 超市里有一些商品 xff0c 第 i 种商品为 products i 且每件单品的价格为 prices i 结账系统会统计顾客的数目 xff0c 每隔 n
  • (Taro篇)如何自定义小程序Swiper面板指示点的样式

    效果图 轮播组件jsx span class token keyword import span span class token punctuation span Component span class token punctuatio
  • 如何使用Docker搭建Heimdall-打造你自己的专属浏览器首页

    一 介绍 Heimdall是一种以简单的方式组织所有指向您最常用的网站和 Web 应用程序的链接的方法 简单是 Heimdall 的关键 它甚至可以使用 Google Bing 或 DuckDuckGo 包含一个搜索栏 二 安装环境 系统
  • CentOS8中使用Libreoffice7.3遇到的问题

    首先借鉴了这篇文章对Libreoffice进行了下载和安装 https blog csdn net UnicornRe article details 119677482 在本地的centos7环境中测试word转pdf是没有问题的 xff
  • UIImageView的基本使用

    UIImageView作为iOS开发里基本控件 xff0c 是我们第四个需要学习的 下面我来为大家介绍一下UIImageView的一些常用属性和它们的用法 这里附上UI控件演示的源码地址 xff1a https github com LOL
  • 如何使用Docker搭建PhotoPrism - 打造基于AI私有化的个人相册系统

    一 简介 PhotoPrism 是一款由人工智能驱动的应用程序 xff0c 用于浏览 组织和分享您的照片集 它利用最新技术自动标记和查找图片 您可以在家里 私人服务器或云端运行它 PhotoPrism对很多设备提供了支持 xff0c 包括M
  • Power Keys - 彻底解放电脑使用效率

    简介 Power Keys 是一款十分强大的 快速启动 系统辅助工具 xff0c 支持 Windows 与 macOS xff0c 它可以利用 F1 F12 43 字母或数字 来启动程序或打开网页等操作 xff0c 还拥有类似 VIM 编辑
  • Windows安装Gradle详细图文教程

    简介 Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建开源工具 它使用一种基于Groovy的特定领域语言 DSL 来声明项目设置 xff0c 也增加了基于Kotlin语言的kotlin based D
  • CentOS7防火墙(Firewalld篇)

    一 防火墙设置 1 启用防火墙 systemctl start firewalld 2 关闭防火墙 systemctl stop firewalld 3 查看状态 systemctl status firewalld 4 开机启用防火墙 s
  • 9.图--拓补排序

    1 概念 无环图 xff1a 活动 2 拓补序列 xff1a 3 拓补排序 xff1a 对有向图构造拓补序列的过程 1 1 例子 比如有下表 xff0c 要学习 汇编语言 就需要先学习C1和C13课程 要将表画为AOV网图 xff1a 拓补
  • wxHelper使用教程

    方法介绍 前言1 工具介绍 x1f517 1 1 环境介绍1 2 功能介绍1 3 源码地址 2 使用说明 x1f517 2 1 Server说明2 2 引入jar包 3 方法介绍 x1f517 1 服务器配置 token验证 2 自定义菜单
  • go-mysql-elasticsearch 使用

    文档 github 链接 GitHub go mysql org go mysql elasticsearch Sync MySQL data into elasticsearch 参考博客 注意事项 go mysql elasticsea