Ubuntu下安装Elasticsearch并同步MySQL数据

来源:互联网 发布:手机上淘宝密码怎么改 编辑:程序博客网 时间:2024/06/05 12:31

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.6wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.1.tar.gzsha1sum 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/profileexport GOPATH=/usr/lib/goexport PATH=$PATH:$GOPATH/binsource /etc/profile#安包管理工具godepgo 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 #添加这一行就okbinlog-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


原创粉丝点击