Ubuntu下安装Elasticsearch并同步MySQL数据

12 篇文章 0 订阅
9 篇文章 0 订阅

0.环境及各软件版本:

Ubuntu 16.04 Server 

Elasticsearch 5.6.1

MySQL 5.7

JDK 1.8 (已安装不在这里赘述)

golang 1.6

go-mysql-elasticsearch(数据同步)


1.安装MySQL

#更新源
apt update

#安装MySQL,此过程中会提示设置root密码
apt-get install mysql-server mysql-client

#使用mysql_secure_installation安全设置
#可更改root密码、移除MySQL的匿名用户、禁止root远程登录、删除test数据库
mysql_secure_installation

#登陆
mysql -u root -p

2.安装Elasticsearch

#官方安装文档
https://www.elastic.co/guide/en/elasticsearch/reference/5.6/zip-targz.html

#安装Elasticsearch5.6
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.1.tar.gz
sha1sum elasticsearch-5.6.1.tar.gz 
tar -xzf elasticsearch-5.6.1.tar.gz

#启动
cd elasticsearch-5.6.1/
./bin/elasticsearch -d -p pid

#访问测试
curl http://localhost:9200/


3.安装Golang,配置
go-mysql-elastisearch

apt install golang-go

#查看go的安装目录
whereis go

#配置环境变量
vi /etc/profile
export GOPATH=/usr/lib/go
export PATH=$PATH:$GOPATH/bin
source /etc/profile

#安包管理工具godep
go get github.com/tools/godep

#获取go-mysql-elastisearch插件
go get github.com/siddontang/go-mysql-elasticsearch
#编译
cd $GOPATH/src/github.com/siddontang/go-mysql-elasticsearch 
make

#修改.etc/river.toml配置文件,以下是我的配置, 其实按照作者给出的示例还可以做其他配置,这里就不一一列举了
schema = "opt_blog"
tables = ["blog"]
[[rule]]
schema = "opt_blog"
table = "blog"
index = "opt_blog"
type = "blog"

#修改MySQL配置文件,开启binlog,因为go-mysql-elasticsearch是通过binlog来获取数据更新的,所以必须开启binlog
#如果对go-mysql-elasticsearch有兴趣的话可以看下这篇文章 http://www.jianshu.com/p/05cff717563c
[mysqld]
log-bin=mysql-bin #添加这一行就ok
binlog-format=ROW #选择row模式
server_id=1 #开启binlog时需要设置,不然启动不了

#同步数据,可以通过nohup.out文件查看执行状态
nohup ./bin/go-mysql-elasticsearch -config=./etc/river.toml > nohup.out 2>&1 &

#向blog表中插入一条数据,测试搜索
curl http://localhost:9200/opt_blog/blog/1


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值