1、安装GO环境
安装go
#yum install -y go
安装godep
#go get github.com/tools/godep
2、MySQL开启binlog
Mysql必须开启binlog(binlog-format=ROW, binlog_row_image = FULL);
要赋予用于连接mysql的账户RELOAD权限以及REPLICATION权限, SUPER权限;
#GRANT REPLICATION SLAVE ON *.* TO ’数据库账号'@'%';
#GRANT REPLICATION CLIENT ON *.* TO '数据库账号'@'%';
#GRANT RELOAD ON *.* TO '数据库账号'@'%';
#UPDATE mysql.`user` SET Super_Priv = 'Y' WHERE USER = '数据库账号' AND HOST = '%';
3、安装GO依赖包
#vim /etc/profile
底部添加:
export GOPROXY=https://goproxy.io
设置生效
#source /etc/profile
4、下载go-mysql-elasticsearch代码包
下载go-mysql-elastisearch插件
#go get github.com/siddontang/go-mysql-elasticsearch
进入对应目录,比如我使用的如下目录/root/go/src/github.com/siddontang/go-mysql-elasticsearch
#cd /root/go/src/github.com/siddontang/go-mysql-elasticsearch
编译
#make
5、mysqldump安装及配置
#yum -y install holland-mysqldump.noarch
mysqldump备份简单操作:
#mysqldump -h[ip] -P[端口号] -u[用户名] -p 数据库名 表名 >导出的文件名.sql
#mysqldump -h[ip] -P[端口号] -u[用户名] -p 数据库名 表名1 表名2 表名3 | gzip >导出的文件名.sql.gz
例如:mysqldump -h127.0.0.1 -P 3306 -u root -p db_name table_name >/data/xxx.sql(回车输入密码)
6、配置go-mysql-elasticsearch
#vim etc/river.toml
================================================
# MySQL address, user and password
# user must have replication privilege in MySQL.
my_addr = "CHANGEME"#数据库ip:端口
my_user = "CHANGEME"#数据库账号
my_pass = "CHANGEME"#数据库密码
my_charset = "utf8"
# Set true when elasticsearch use https
#es_https = false
# Elasticsearch address
es_addr = "CHANGEME"#ES库ip:端口
# Elasticsearch user and password, maybe set by shield, nginx, or x-pack
es_user = "CHANGEME"#es账号
es_pass = "CHANGEME"#es密码
# 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 = "./devdata"
# Inner Http status address
stat_addr = "127.0.0.1:12800"
stat_path = "/metrics"
# pseudo server id like a slave
server_id = 3001
# 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 = "CHANGEME"#数据库库名
# 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 = ["CHANGEME"]#数据库表
# 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 = "CHANGEME"#数据库库名
table = "CHANGEME"#数据库表
index = "CHANGEME"#ES库索引
type = "CHANGEME"#ES库类型
================================================
7、运行
#rm -f var/master.info
#nohup bin/go-mysql-elasticsearch -config=river.toml &
8、使用head检测
chrome浏览器安装head插件直接使用。