elasticsearch搭建并通过go-mysql-elasticsearch同步db数据达到搜索引擎的目的
logstash-input-jdbc/elasticsearch-jdbc缺点:删除记录没有办法同步,只能两边执行自己的删除命令,版本16年后未更新。
go-mysql-elasticsearch缺点:国内的不是很稳定
elasticsearch-river-MYSQL 版本太旧,12年之后未更新。

es安装:
下载
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.6.zip
解压
unzip elasticsearch-5.6.6.zip
移动到/usr/local目录
mv elasticsearch-5.6.6 /usr/local/elsearch
按需求修改config/elasticsearch.yml文件
vim /usr/local/elsearch/config/elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/elsearch/data
#
# Path to log files:
#
path.logs: /usr/local/elsearch/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 172.21.0.15
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#
http.cors.enabled: true
http.cors.allow-origin: "*"
安装中文分词设置
cd /usr/local/elsearch/
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.6/elasticsearch-analysis-ik-5.6.6.zip
测试
curl -X PUT 'localhost:9200/accounts' -d '
{
"mappings": {
"person": {
"properties": {
"user": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"desc": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
}
}'
参考链接 http://www.ruanyifeng.com/blog/2017/08/elasticsearch.html
es-head安装
下载
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
解压
unzip master.zip
放到/usr/local/下
mv elasticsearch-head-master /usr/local/elsearch-head
安装node
于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包
yum -y install gcc make gcc-c++ openssl-devel wget
wget http://nodejs.org/dist/v0.10.26/node-v0.10.26.tar.gz
tar -zvxf node-v0.10.26.tar.gz
cd node-v0.10.26
make && make install
验证是否安装配置成功:
node -v
安装grunt
grunt是一个很方便的构建工具,可以进行打包压缩、测试、执行等等的工作,5.6里的head插件就是通过grunt启动的。因此需要安装一下grunt:
cd /usr/local/elsearch-head
npm install -g grunt-cli //执行后会生成node_modules文件夹
npm install
修改vim Gruntfile.js文件:增加hostname属性,设置为*
connect: {
server: {
options: {
port: 9100,
hostname: '*',
base: '.',
keepalive: true
}
}
}
修改 vim _site/app.js 文件:修改head的连接地址:
this.base_uri = this.config.base_uri || this.prefs.get(“app-base_uri”) || “http://192.168.0.153:9200“;
启动
cd elsearch-head
grunt server & #后台启动
安装go-mysql-elasticsearch进行同步
yum install go
go get github.com/tools/godep
go get github.com/siddontang/go-mysql-elasticsearch
cd $GOPATH/src/github.com/siddontang/go-mysql-elasticsearch
make
修改配置文件
vim /root/go/src/github.com/siddontang/go-mysql-elasticsearch/etc/river.toml
# MySQL address, user and password
# user must have replication privilege in MySQL.
my_addr = "172.21.0.15:3308"#mysql地址
my_user = "root"#用户名
my_pass = "123456"#密码
# Elasticsearch address
es_addr = "172.21.0.15:9200"#es安装地址
# Path to store data, like master.info, and dump MySQL data
data_dir = "./var"
# Inner Http status address
stat_addr = "172.21.0.15:12800"
# pseudo server id like a slave
server_id = 1
# mysql or mariadb
flavor = "mysql"#mysql数据库
# mysqldump execution path
# if not set or empty, ignore mysqldump.
mysqldump = "mysqldump"
# MySQL data source
[[source]]
schema = "test"#数据库名称
# Only below tables will be synced into Elasticsearch.
# "test_river_[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 = ["travelrecord10","travelrecord4","travelrecord5","travelrecord1"]#数据表名称,可以多个
# Below is for special rule mapping
#[[rule]]
#schema = "test"
#table = "test_river"
#index = "river"
#type = "river"
# only MySQL field in filter will be synced
#filter=["title","tags"]
# title is MySQL test_river field name, es_title is the customized name in Elasticsearch
#[rule.field]
# This will map column title to elastic search my_title
#title="es_title"
# This will map column tags to elastic search my_tags and use array type
#tags="my_tags,list"
# This will map column keywords to elastic search keywords and use array type
#keywords=",list"
# wildcard table rule, the wildcard table must be in source tables
[[rule]]
schema = "test"#数据库名称
table = "travelrecord10"#数据表名称
index = ""#生成es数据索引名称,对应schema
type = ""#生成es数据类型,对应table
#[[rule]]
#schema = "test"#数据库名称
#table = "travelrecord8"#数据表名称
#index = ""#生成es数据索引名称,对应schema
#type = ""#生成es数据类型,对应table
# title is MySQL test_river field name, es_title is the customized name in Elasticsearch
[[rule.fields]]
mysql = "title"
elastic = "es_title"
运行
cd $GOPATH/src/github.com/siddontang/go-mysql-elasticsearch
./bin/go-mysql-elasticsearch -config=./etc/river.toml > /home/heron/wwwlogs/go-mysql.log 2>&1 &
测试:
db增加数据,查看页面是否显示。
curl -XPOST -u elastic '10.168.2.10:9200/_xpack/security/user/demo' -d '{ "password" : "123456", "full_name" : " elastic", "email" : “elastic@163.com", "roles" : [ "clicks_admin" ] }'
不稳定现况,会自己挂掉,暂时没找到解决办法,只能挂掉立即重启

elasticsearch搭建并通过go-mysql-elasticsearch同步db数据达到搜索引擎的目的的更多相关文章
- 搭建zipkin并以mysql的方式存储数据
zipkin以mysql的方式存储 (centos+java8+mysql+zipkin2.3.1) 前言: 这篇教程用于搭建已mysql作为存储的zipkin.(还不知道zipkin是什么的小伙伴请 ...
- MySql 触发器同步备份数据表记录
添加记录到新记录表 DELIMITER $$ USE `DB_Test`$$ CREATE /*!50017 DEFINER = 'root'@'%' */ TRIGGER `InsertOPM_Al ...
- django连接mysql自动同步生成数据表
python manage.py makemigrations python manage.py migrate 如果是 Django 不主动提示创建管理员(Django 1.9不提示)用下面的命令创 ...
- Mysql主从同步(1) - 概念和原理介绍 以及 主从/主主模式 部署记录
Mysql复制概念Mysql内建的复制功能是构建大型高性能应用程序的基础, 将Mysql数据分布到多个系统上,这种分布机制是通过将Mysql某一台主机数据复制到其它主机(slaves)上,并重新执行一 ...
- Elasticsearch mysql 增量同步
主要用到了一个JDBC importer for Elasticsearch的库. 想要增量同步,有一些先决条件.首先数据库中要维护一个update_time的时间戳,这个字段表示了该记录的最后更新时 ...
- Elasticsearch学习(2) windows环境下Elasticsearch同步mysql数据库
在上一章中,我们已经能够通过spring boot来使用Elasticsearch,但是由于我们习惯性的将数据写入mysql,所以为了解决这个问题,Elasticsearch为我们提供了一个插件log ...
- 一文教您如何通过 Docker 快速搭建各种测试环境(Mysql, Redis, Elasticsearch, MongoDB) | 建议收藏
欢迎关注个人微信公众号: 小哈学Java, 文末分享阿里 P8 高级架构师吐血总结的 <Java 核心知识整理&面试.pdf>资源链接!! 个人网站: https://www.ex ...
- 使用Logstash同步数据至Elasticsearch,Spring Boot中集成Elasticsearch实现搜索
安装logstash.同步数据至ElasticSearch 为什么使用logstash来同步,CSDN上有一篇文章简要的分析了以下几种同步工具的优缺点:https://blog.csdn.net/la ...
- Docker Mysql主从同步配置搭建
Docker Mysql主从同步配置搭建 建立目录 在虚拟机中建立目录,例如路径/home/mysql/master/data,目录结构如下: Linux中 新建文件夹命令:mkdir 文件夹名 返回 ...
随机推荐
- chrome浏览器另存为/上传附件崩溃
x 前言 系统中有一个需要上传导入的功能,此功能在谷歌浏览器上传总是直接崩溃, 但是在火狐浏览器中就是好的. 自己想到的解决方案 谷歌浏览器版本号得问题?自己系统得问题? 谷歌浏览器卸载重新安装,还是 ...
- onu-reg-unreg.vbs
Sub Main crt.Sleep 10000 Dim cnt For cnt = 0 To 1000000 crt.screen.Send "admin-status down" ...
- CDI feature
CDI Java EE的上下文和依赖注入(Contexts and Dependency Injection for Java EE,CDI),CDI是即将完成的Java EE 6平台的关键组成部分, ...
- 在linux服务器下JMeter如何执行jmx性能脚本
准备环境:linux平台.jmeter安装包. jdk 一. 安装jdk jdk的安装可以参考以下内容 http://jingyan.baidu.com/article ...
- node.js爬取ajax接口数据
爬取页面数据与爬取接口数据,我还是觉得爬取接口数据更加简单一点,主要爬取一些分页的数据. 爬取步骤: 1.明确目标接口地址,举个例子 : https://www.vcg.com/api/common/ ...
- XLSReadWriteII5导入excel数据
procedure TForm1.Button1Click(Sender: TObject); var xls: TXLSReadWriteII5; openFile: TOpenDialog; Ro ...
- 20175201课下作业 MyCP
要求 编写MyCP.java 实现类似Linux下cp XXX1 XXX2的功能,要求MyCP支持两个参数: java MyCP -tx XXX1.txt XXX2.bin 用来把文本文件(内容为十进 ...
- github仓库的初步使用
github是被戏称为男人们的朋友圈,在github里可以很方便的和同伴合作.以下是github初步建立的步骤.(由于我已经安装好了,所有没有插入图片,如果有未降到的问题先自行百度,如果我后续碰到有关 ...
- mongodb细讲
一. 关系型数据库(sql) 1.建表 二.非关系型数据库(nosql 98提出的概念) 1.不用建库建表数据直接存入就可 优缺点: 关系型:节约资源(学生姓名和课程名不重复出现),开发不方便(需先 ...
- 一个Monkey测试的小坑
环境:Genymotion模拟器+Custome Phone-6.0.0,API 23 操作步骤如下: cd data/app ls //为了获取待测apk的包名 获取结果如下: 执行命令,其中包名使 ...