需要用到 https://github.com/siddontang/go-mysql-elasticsearch
第一步是安装 go 环境,版本要 1.9+
下载go
cd /home
mkdir app
cd app
wget wget https://storage.googleapis.com/golang/go1.9.4.linux-amd64.tar.gz
tar zxvf go1.9.4.linux-amd64.tar.gz
新建GOPATH目录
mkdir /home/work
vi /etc/profile
export GOROOT=/home/app/go
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN
export GOPATH=/home/work
执行 source /etc/profile 生效
查看是否配置成功,执行 go version ,如果返回版本号就正常了。
修改数据库配置文件,默认文件位置为:/etc/my.cnf , 确保有以下配置内容
- 开启bin-log
- binglog_foramt格式必须为row ; binlog_format=ROW
- binlog-row-image 必须为FULL
修改 river.toml 配置文件 /home/work/src/github.com/siddontang/go-mysql-elasticsearch/etc/river.toml
- 如果可能,创建关联的Elasticsearch索引,文档类型和映射,否则,Elasticsearch将自动创建这些索引。
执行./bin/go-mysql-elasticsearch -config=./etc/river.toml
开始同步数据,以后新增数据都会自动同步到ES中。