ElasticSearch插件-elasticsearch-jdbc

来源:互联网 发布:淘宝兼职 刷单怎么 编辑:程序博客网 时间:2024/05/16 07:07

简介

elasticsearch-jdbc是mysql同步至es的一个插件,其实插件不止一种,目前该领域比较牛的插件有:

  • elasticsearch-jdbc,严格意义上它已经不是第三方插件。已经成为独立的第三方工具。https://github.com/jprante/elasticsearch-jdbc
  • elasticsearch-river-MySQL插件 https://github.com/scharron/elasticsearch-river-mysql
  • go-mysql-elasticsearch(国内作者siddontang) https://github.com/siddontang/go-mysql-elasticsearch

但是相比较而言,go-mysql-elasticsearch仍处理开发不稳定阶段,elasticsearch-river-mysql 2012年12月13日后便不再更新,而elasticsearch-jdbc更通用,github也更活跃,因此我都是用elasticsearch-jdbc。

插件安装

插件安装,需要根据所安装的elasticSearch版本匹配,可参考如下表格

Release date JDBC Importer version Elasticsearch version Aug 28 2016 2.3.4.1 2.3.4 Aug 1 2016 2.3.4.0 2.3.4 Jul 6 2016 2.3.3.1 2.3.3 May 28 2016 2.3.3.0 2.3.3 May 27 2016 2.3.2.0 2.3.2 Apr 9 2016 2.3.1.0 2.3.1 Apr 9 2016 2.2.1.0 2.2.1 Feb 5 2016 2.2.0.0 2.2.0 Dec 23 2015 2.1.1.2 2.1.1 Nov 29 2015 2.1.0.0 2.1.0 Oct 29 2015 2.0.0.1 2.0.0 Oct 28 2015 2.0.0.0 2.0.0 Oct 23 2015 1.7.3.0 1.7.3 Sep 29 2015 1.7.2.1 1.7.2 Jul 24 2015 1.7.0.1 1.7.0 Jul 24 2015 1.6.0.1 1.6.0

下载地址:
http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc//elasticsearch-jdbc--dist.zip

例如下载2.3.4.1:

wget http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc/2.3.4.1/elasticsearch-jdbc-2.3.4.1-dist.zip

插件配置

unzip elasticsearch-jdbc-2.3.4.1-dist.zip

下文是es-jdbc的基本配置

#!/bin/shDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"bin=${DIR}/../binlib=${DIR}/../libecho '{    "type" : "jdbc",    "jdbc" : {        "url" : "jdbc:mysql://localhost:3306/blog",        "statefile" : "statefile.json",        "schedule" : "0 0-59 0-23 ? * *",        "user" : "blog",        "password" : "12345678",        "sql" : [{                "statement": "select id as _id, id, post_title as title, post_content as content from wp_posts where post_status = ? and post_modified > ? ",                "parameter": ["publish", "$metrics.lastexecutionstart"]}            ],        "index" : "article",        "type" : "blog",        "metrics": {            "enabled" : true        },        "elasticsearch" : {             "cluster" : "elasticsearch",             "host" : "localhost",             "port" : 9300         }       }}' | java \    -cp "${lib}/*" \    -Dlog4j.configurationFile=${bin}/log4j2.xml \    org.xbib.tools.Runner \    org.xbib.tools.JDBCImporter

包括数据库、SQL、任务执行计划、es基本信息等,具体可配置参数可参考下文:
https://github.com/jprante/elasticsearch-jdbc
注:
* statefile,是下次执行计划的基本配置文件,首次执行时会生成这个文件,下次执行是直接读取statefile文件,因此如果修改mysql-blog.sh,需要删除statefile文件,否则不会生效
* cluster,是es集群的名称,需要同es的一样
* schedule 是执行计划,规划多久间隔执行一次

测试

脚本配置完成后,执行命令启动脚本:

nohup ./mysql-blog.sh &

注:
* elasticsearch-jdbc,启动需要适配jdk版本,2.3.4.1是108版本编译的,因此需要安装jdk1.8

0 0
原创粉丝点击