go-mysql-elasticsearch 是国内作者开发的一款插件。测试表明:该插件优点:能实现同步增、删、改、查操作。不足之处(待完善的地方):
1、日志不是很详细,但是能满足基本需求;
2、初始化时,无法自动同步mysql中存在的以前的数据,需要自行解决初始导入(如重建索引批量导入)
go-mysql-elasticsearch 安装
步骤1:安装go
yum install go
步骤2:安装godep
go get github.com/tools/godep
步骤3:获取go-mysql-elastisearch插件
go get github.com/siddontang/go-mysql-elasticsearch
步骤4:安装go-mysql-elastisearch插件
cd $GOPATH/src/github.com/siddontang/go-mysql-elasticsearch
make
go-mysql-elasticsearch 使用
1 修改配置文件 vi river.toml
#以下为同步的mysql配置
my_addr = “127.0.0.1:3306”
my_user = “root”
my_pass = “123456”
my_charset = “utf8”
#es_https = false
es_addr = “192.168.100.90:9200”
es_user = “”
es_pass = “”
data_dir = “./var”
stat_addr = “127.0.0.1:12800”
server_id = 1001
flavor = “mysql”
#mysqldump = “mysqldump”
#skip_master_data = false
bulk_size = 128
flush_bulk_time = “200ms”
skip_no_pk_table = false
[[source]]
schema = “zkbh_nbjd”
#同步的数据表列表,多个表用,隔开
tables = [“sys_user”,“sys_log”]
t
will be synced to ES index test
and type t
同步zkbh_nbjd数据库下的sys_user表数据到索引user中
[[rule]]
schema = “zkbh_nbjd”
table = “sys_user”
index = “user”
type = “novel”
test
and type t
.t
;同步zkbh_nbjd数据库下的sys_log表数据到索引log中
[[rule]]
schema = “zkbh_nbjd”
table = “sys_log”
index = “log”
type = “log”
3.启动 go-mysql-elasticsearch
cd /root/go/src/github.com/siddontang/go-mysql-elasticsearch
nohup ./bin/go-mysql-elasticsearch -config=./etc/river.toml & 为后台启动,否则会因为登录linux的用户退出而关闭服务。此处需要引入Screen 窗口管理器来保证 go-mysql-elasticsearch服务不会关闭,具体请查看相关资料