book
  • 关于
  • golang
    • 代码片段
  • LANMP
    • 安装
    • Linux
      • 源码编译
      • Linux基本操作命令
      • Linux网络相关命令
      • Crontab 计划任务
    • Nginx
      • 安装
      • 负载均衡
      • 负载均衡分配方式
      • 高可用
    • MySQL
      • 安装
      • 高可用
    • PHP
      • PHP内核
      • 代码段
      • Laravel
    • Swoole
      • easyswoole
        • 安装
    • 设计模式
  • 操作系统和网络
    • 计算机网络
      • IP协议
      • TCP协议
      • UDP协议
      • HTTP协议
      • HTTPS协议
      • HTTP2协议
      • HTTP1 HTTP2的区别
      • Websocket
      • 域名解析
      • Http压测工具 wrk
  • 工具
    • 版本控制
      • git
    • gitbook
      • 配置和插件
      • 插件
      • gitlab + gitbook
    • jenkins
      • 安装
      • 自动部署
    • Elasticsearch
    • go-mysql-elasticsearch
  • Python
    • Python基础
      • list 和 tuple
      • dict 和 set
    • Python爬虫
      • 爬取elasticsearch英文文档
    • 第三方包
      • Scoop
  • 运维
    • 运维
      • Logrotate
      • 服务器记录操作日志
    • 安全
    • Shell
    • VMWare
  • Java
    • Java基础
  • 前端
    • npmjs
由 GitBook 提供支持
在本页
  • install
  • 添加到systemd.server
  • Notice
  • my.cnf
  • 待完善
  1. 工具

go-mysql-elasticsearch

上一页Elasticsearch下一页Python基础

最后更新于2年前

将MySQL数据同步到elasticsearch中

install

  • Install Go (1.9+) and set your GOPATH, yum install -y go 查看版本 go version

  • go get github.com/siddontang/go-mysql-elasticsearch 忽略控制台的消息

  • cd $GOPATH/src/github.com/siddontang/go-mysql-elasticsearch 这里$GOPATH 可以通过go env GOPATH 得知

  • make

本来我想做成RPM包,那样就可以rpm安装,但是弄了1天还没弄出来,放弃了,如果有谁知道怎么制作,请联系我

添加到systemd.server

复制 go-mysql-elasticsearch 整个目录到 /usr/local/ 下

vim /usr/lib/systemd/system/go-mysql-elasticsearch.service

  1 [Unit]
  2 Description=go-mysql-elasticsearch
  3
  4 [Service]
  5 Type=simple
  6 User=root
  7 Environment=GO_AGENT_LOG=/var/log/es-agent/go-mysql-elasticsearch.log
  8 ExecStart=/usr/local/go-mysql-elasticsearch/bin/go-mysql-elasticsearch -config=/etc/river.toml -log_path=${GO_AGENT_LOG} -log_level=info
  9 ExecReload=/usr/bin/kill -s HUP $MAINPID
 10  ExecStop=/usr/bin/kill -s QUIT $MAINPID
 11 PIDFile=/var/run/go-mysql-elasticsearch.pid
 12 KillMode=process
 13 Restart=always
 14 StartLimitInterval=0
 15 StandardOutput=null
 16
 17 [Install]
 18 WantedBy=multi-user.target

后面就可以用 systemctl start|reload|stop go-mysql-elasticsearch 启动了

Notice

  • MySQL supported version < 8.0

  • ES supported version < 6.0

  • binlog format must be row.

  • binlog row image must be full for MySQL, you may lost some field data if you update PK data in MySQL with minimal or noblob binlog row image. MariaDB only supports full row image.

  • Can not alter table format at runtime.

  • MySQL table which will be synced should have a PK(primary key), multi columns PK is allowed now, e,g, if the PKs is (a, b), we will use "a:b" as the key. The PK data will be used as "id" in Elasticsearch. And you can also config the id's constituent part with other column.

  • You should create the associated mappings in Elasticsearch first, I don't think using the default mapping is a wise decision, you must know how to search accurately.

  • mysqldump must exist in the same node with go-mysql-elasticsearch, if not, go-mysql-elasticsearch will try to sync binlog only.

  • Don't change too many rows at same time in one SQL.

my.cnf

[mysqld]
log-bin=mysql-bin
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=true
binlog-format=ROW
binlog-row-image = full
sync-binlog=1
server-id=1
socket=/usr/local/mysql/mysql.sock
symbolic-links=0
binlog-cache-size=4M
max-binlog-size=1G
max-binlog-cache-size=2G
binlog-checksum=CRC32
wait-timeout=200
interactive-timeout=200
open-files-limit=60000

[mysqld_safe]
log-error=/var/log/mysqld.log

待完善

  • master.info 这个文件的目录没有自定义

github