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 使用 的相关文章

  • 单行的总和值?

    我有一个 MySQL 查询 它返回由一系列 1 和 0 组成的单行 它用于进度条指示器 我现在在代码中对它进行求和 但我尝试对查询中的值求和 并意识到我无法使用 SUM 因为它们有很多列 但只有一行 有没有办法可以在查询中自动求和 就像这样
  • 嵌套类型的动态映射

    我正在尝试为如下对象创建动态映射 product productId 99999 manufacturerId A0001 manufacturerCode A101LI name Test Product description Desc
  • PHP 绑定“bigint”数据类型(MySQLi 准备好的语句)

    studentId 57004542323382 companyOfferId 7 sql INSERT INTO studentPlacement companyOfferId studentId VALUES if stmt db gt
  • 按存储桶键值过滤 Elasticsearch 聚合

    我有一个 Elasticsearch 文档索引 其中有一个包含 URL 列表的字段 正如预期的那样 对该字段进行聚合可以计算出唯一 URL 的数量 GET models search query match all size 0 aggs
  • 阻止注销页面后的后退按钮

    我有 php 注销页面 当用户单击注销链接时 请参阅此页面并重定向到索引页面 但是当单击后退按钮时 我会看到带有用户数据的上一页 当然 当我刷新页面时 我看不到以前的页面和数据 我在单击注销并单击后退按钮后检查了其他代码 drupal 但我
  • MySQL 使用 ALTER IGNORE TABLE 出现重复错误

    我的 MySQL 中有一个有重复项的表 我尝试删除重复项并保留一项 我没有主键 我可以通过以下方式找到重复项 select user id server id count as NumDuplicates from user server
  • 无法通过套接字“/var/lib/mysql/mysql.sock”连接到本地 MySQL 服务器 (2)

    当我尝试连接 mysql 时出现以下错误 Can t connect to local MySQL server through socket var lib mysql mysql sock 2 这个错误有解决办法吗 其背后的原因可能是什
  • Mysql 中 UNION 子句的替代方案

    我有两张桌子 表 a 表 b table a ID 1 2 3 4 5 7 table b ID 2 3 4 5 6 我必须得到这样的输出而无需UNION命令 ID 1 2 3 4 5 6 7 注意 我有一个联合解决方案 select fr
  • Apache、PHP 和 MySQL 可移植吗?

    我可以在外部硬盘上运行 Apache PHP 和 MySQL 吗 我需要这个 因为我在不同的地方工作 计算机 有时我没有安装和配置所有使用的应用程序 当然可以 XAMPP http www apachefriends org en xamp
  • MySQL MIN/MAX 所有行

    我有桌子Races与行ID Name and TotalCP 我选择分钟 TotalCP FROM Races 但是我想选择具有最小值的整行 我如何在单个查询中做到这一点 从聚合值获取整行的一般形式是 SELECT FROM Races W
  • Mysql 创建定义器

    我创建了一个在 CentOS Web 服务器上运行的 Intranet Web 应用程序 该应用程序使用另一个本地服务器 始终是 CentOS 作为 MySQL 数据库 在数据库内部我创建了例程 这些例程总是这样开始 CREATE DEFI
  • 如何更新与elasticsearch中的查询匹配的多个文档

    我的文档最初只包含 url 已分析 和 respsize 未分析 字段 我想更新与 url 匹配的文档并添加新字段 类别 我是说 首先doc1 url http stackoverflow com users 4005632 mehmet
  • 如何使用 vitess 仅对特定表进行分片

    我创建了一个包含三个表的未分片键空间 现在我想对前两个表的键空间进行分片 但不想对第三个表进行分片 如何才能做到这一点 Vitess 文档不包含任何与此相关的信息或示例 请帮忙 Thanks vitess 中的垂直分片与水平分片类似 您应该
  • Mysql 将 int 转换为 MAC

    我有一些数据可以转换 其中有 2 列 其中一列有 IP 它包含整数值 我在 mysql 查询中使用了以下函数 是否有一个函数可以用来转换我的 mac 列 其中包含整数和数据类型是bigint to MAC地址 SELECT INET NTO
  • Java JDBC:更改表

    我希望对此表进行以下修改 添加 状态列 varchar 20 日期列 时间戳 我不确定该怎么做 String createTable Create table aircraft aircraftNumber int airLineCompa
  • SonarQube 进程已退出,退出值 [es]:137

    我想在我的 vps linux x86 64 debian 9 上安装声纳 但是当我执行这个 cdm sonar sh 控制台时 我有以下日志 Running SonarQube wrapper gt Wrapper Started as
  • 在 PHP 字符串中格式化 MySQL 代码

    是否有任何程序 IDE 可以在 PHP 字符串中格式化 MySQL 代码 例如 我使用 PHPStorm IDE 但它无法做到这一点 它对 PHP 和 MYSQL 执行此操作 但不适用于 php 字符串内的 MYSQL 我已准备好使用新的
  • 同一配置文件上的两个不同提供程序

    我在用着实体框架 6 1 0 I have 2 家提供者 MysqlClient 和 SQLServerCE 我需要创建2个不同的DBContext 这迫使我创造2个配置类因为mysql有一些不同的东西 但是当我初始化应用程序时 Datab
  • 我可以使用 HSQLDB 进行 junit 测试克隆 mySQL 数据库吗

    我正在开发一个 spring webflow 项目 我想我可以使用 HSQLDB 而不是 mysql 进行 junit 测试吗 如何将我的 mysql 数据库克隆到 HSQLDB 如果您使用 spring 3 1 或更高版本 您可以使用 s
  • 在 MySQL 中存储表情符号的编码问题:如何使用 Prisma ORM 在 NodeJS 中定义字符排序规则?

    亲爱的 Nodejs 专家和数据库专家 我们在 MySQL 数据库中存储表情符号和其他特殊字符时遇到问题 我们使用 Prisma 得到一个错误 这是我们使用的 ORM 参数无法从排序规则 utf8 general ci 转换为 utf8mb

随机推荐

  • 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