实现mysql与elasticsearch的数据同步
JDBC importer for Elasticsearch
The Java Database Connection (JDBC) importer allows to fetch data from JDBC sources for indexing into Elasticsearch.
The JDBC importer was designed for tabular data. If you have tables with many joins, the JDBC importer is limited in the way to reconstruct deeply nested objects to JSON and process object semantics like object identity. Though it would be possible to extend the JDBC importer with a mapping feature where all the object properties could be specified, the current solution is focused on rather simple tabular data streams.
一、安装 elasticsearch-jdbc-2.3.2.0-dist
[root@hadoop0 bigdata]# ls
apache-flume-1.6.0-bin apache-tomcat-7.0.69.zip hbase-1.1.5 jstorm-0.9.6.2 solr-5.5.2 sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz taokeeper-monitor.tar.gz
apache-flume-1.6.0-bin.tar.gz
elasticsearch-jdbc-2.3.2.0-dist.zip hbase-1.1.5-bin.tar.gz jstorm-0.9.6.2.zip solr-5.5.2.zip stomr096 tomcat7 apache-hive-2.0.1-bin.tar.gz hadoop272 hive2.0 kafka sqoop-1.4.6 stormtest-0.0.1-SNAPSHOT.jar zookeeper
[root@hadoop0 bigdata]# unzip elasticsearch-jdbc-2.3.2.0-dist.zip
[root@hadoop0 bigdata]# ls
apache-flume-1.6.0-bin apache-tomcat-7.0.69.zip hadoop272 hive2.0 kafka sqoop-1.4.6 stormtest-0.0.1-SNAPSHOT.jar zookeeper
apache-flume-1.6.0-bin.tar.gz elasticsearch-jdbc-2.3.2.0 hbase-1.1.5 jstorm-0.9.6.2 solr-5.5.2 sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz
taokeeper-monitor.tar.gz
apache-hive-2.0.1-bin.tar.gz elasticsearch-jdbc-2.3.2.0-dist.zip
hbase-1.1.5-bin.tar.gz jstorm-0.9.6.2.zip solr-5.5.2.zip stomr096 tomcat7
[root@hadoop0 bigdata]# cd elasticsearch-jdbc-2.3.2.0
[root@hadoop0 elasticsearch-jdbc-2.3.2.0]# ls
bin lib
[root@hadoop0 elasticsearch-jdbc-2.3.2.0]# cd bin/
二、查看示例
[root@hadoop0 bin]# ls
geo.dump mysql-delete-document.sh mysql-geo-shapes.sh mysql-metawiki.sh mysql-schedule.sh mysql-state-example.sh oracle-connection-properties.sh postgresql-simple-example.sh
log4j2.xml mysql-geo-points.sh mysql-ignore-null-values.sh mysql-schedule-acknowledge.sh mysql-simple-example.bat mysql-wikimedia-example.sh postgresql-geo.sh
[root@hadoop0 bin]# cat mysql-schedule.sh
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bin=${DIR}/../bin
lib=${DIR}/../lib
echo '
{
"type" : "jdbc",
"jdbc" : {
"metrics" : {
"lastexecutionstart" : "2015-05-10T10:58:00.038Z",
"lastexecutionend" : "2015-05-10T10:58:00.044Z",
"counter" : 1234
},
"schedule" : "0 0-59 0-23 ? * *",
"url" : "jdbc:mysql://localhost:3306/test",
"user" : "",
"password" : "",
"sql" : "select *, id as _id, \"myjdbc\" as _index, \"mytype\" as _type from test",
"index" : "myjdbc",
"type" : "mytype",
"index_settings" : {
"index" : {
"number_of_shards" : 1
}
}
}
}
' | java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter
[root@hadoop0 bin]# cat mysql-delete-document.sh
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bin=${DIR}/../bin
lib=${DIR}/../lib
echo '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://localhost:3306/test",
"user" : "",
"password" : "",
"sql" : "select deletethisdoc as _id, delete as _optype from orders"
}
}
' | java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter
[root@hadoop0 bin]# cd ../
[root@hadoop0 elasticsearch-jdbc-2.3.2.0]# pwd
/opt/bigdata/elasticsearch-jdbc-2.3.2.0
三、编写导入例子
[root@hadoop0 elasticsearch-jdbc-2.3.2.0]# vi import.sh
#!/bin/sh
bin=/opt/bigdata/elasticsearch-jdbc-2.3.2.0/bin
lib=/opt/bigdata/elasticsearch-jdbc-2.3.2.0/lib
echo '{
"type" : "jdbc",
"jdbc": {
"elasticsearch.autodiscover":true,
"elasticsearch.cluster":"ffcs-test",
"url":"jdbc:mysql://localhost:3306/test",
"user":"root",
"password":"123456",
"sql":"select * from ffcs",
"index" : "test",
"type" : "ffcs"
}
}' | java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter
四、测试解决JDK版本问题
[root@hadoop0 elasticsearch-jdbc-2.3.2.0]# sh import.sh
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/xbib/tools/Runner : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
[root@hadoop0 elasticsearch-jdbc-2.3.2.0]#
[root@hadoop0 bigdata]# cd jdk
jdk1.8.0_131/ jdk-8u131-linux-i586.tar.gz
[root@hadoop0 bigdata]# cd jdk1.8.0_131/
[root@hadoop0 jdk1.8.0_131]# ls
bin COPYRIGHT db include javafx-src.zip jre lib LICENSE man README.html release src.zip THIRDPARTYLICENSEREADME-JAVAFX.txt THIRDPARTYLICENSEREADME.txt
[root@hadoop0 jdk1.8.0_131]# cd bin/
[root@hadoop0 bin]# ls
appletviewer idlj java javafxpackager javapackager jcmd jdb jinfo jmc jrunscript jstat keytool pack200 rmid serialver unpack200 xjc
ControlPanel jar javac javah java-rmi.cgi jconsole jdeps jjs jmc.ini jsadebugd jstatd native2ascii policytool rmiregistry servertool wsgen
extcheck jarsigner javadoc javap javaws jcontrol jhat jmap jps jstack jvisualvm orbd rmic schemagen tnameserv wsimport
[root@hadoop0 bin]# pwd
/opt/bigdata/jdk1.8.0_131/bin
[root@hadoop0 bin]# wheris java
-bash: wheris: command not found
[root@hadoop0 bin]# whereis java
java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java /opt/jdk1.7.0_79/bin/java /usr/share/man/man1/java.1.gz
[root@hadoop0 bin]# ls -l /usr/bin/java
lrwxrwxrwx. 1 root root 22 Mar 3 2016 /usr/bin/java -> /etc/alternatives/java
[root@hadoop0 bin]# rm -rf /usr/bin/java
[root@hadoop0 bin]# ln -l /opt/bigdata/jdk1.8.0_131/bin
ln: invalid option -- 'l'
Try `ln --help' for more information.
[root@hadoop0 bin]#
[root@hadoop0 bin]# ln -l /opt/bigdata/jdk1.8.0_131/bin/java /usr/bin/java
ln: invalid option -- 'l'
Try `ln --help' for more information.
[root@hadoop0 bin]# ln -s /opt/bigdata/jdk1.8.0_131/bin/java /usr/bin/java
[root@hadoop0 bin]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) Client VM (build 25.131-b11, mixed mode)
[root@hadoop0 bin]# pwd
/opt/bigdata/jdk1.8.0_131/bin
[root@hadoop0 bin]# cd ../..//
[root@hadoop0 bigdata]# ls
apache-flume-1.6.0-bin apache-tomcat-7.0.69.zip hadoop272 hive2.0 jstorm-0.9.6.2 solr-5.5.2 sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz taokeeper-monitor.tar.gz
apache-flume-1.6.0-bin.tar.gz elasticsearch-jdbc-2.3.2.0 hbase-1.1.5 jdk1.8.0_131 jstorm-0.9.6.2.zip solr-5.5.2.zip stomr096 tomcat7
apache-hive-2.0.1-bin.tar.gz elasticsearch-jdbc-2.3.2.0-dist.zip hbase-1.1.5-bin.tar.gz jdk-8u131-linux-i586.tar.gz kafka sqoop-1.4.6 stormtest-0.0.1-SNAPSHOT.jar zookeeper
[root@hadoop0 bigdata]# cd elasticsearch-jdbc-2.3.2.0/
[root@hadoop0 elasticsearch-jdbc-2.3.2.0]# ls
bin import.sh lib
五、测试OK
[root@hadoop0 elasticsearch-jdbc-2.3.2.0]# vi import.sh
#!/bin/sh
bin=/opt/bigdata/elasticsearch-jdbc-2.3.2.0/bin
lib=/opt/bigdata/elasticsearch-jdbc-2.3.2.0/lib
echo '{
"type" : "jdbc",
"jdbc": {
"elasticsearch.autodiscover":true,
"elasticsearch.cluster":"my-application",
"url":"jdbc:mysql://192.168.1.102:3306/test",
"user":"root",
"password":"root",
"sql":"select * from people",
"elasticsearch" : {
"host" : "192.168.1.111",
"port" : 9300
},
"index" : "index_users3",
"type" : "ffcs"
}
}' | java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter
[root@hadoop0 elasticsearch-jdbc-2.3.2.0]# sh import.sh
[root@hadoop0 elasticsearch-jdbc-2.3.2.0]#
相关推荐
1. **安装插件**:将下载的`elasticsearch-jdbc-2.2.0.0`文件解压,并将包含的JAR文件添加到Elasticsearch的`plugins`目录下。 2. **配置连接**:创建一个配置文件(如`jdbcRiver.json`),设置数据库连接参数(如...
使用Elasticsearch-JDBC连接MySQL的过程大致如下: 1. **配置JDBC River**: 在Elasticsearch中创建一个名为"river"的特殊索引类型,用于定义数据源和导入规则。配置包括数据库URL、用户名、密码、表名以及映射到...
- **安装**:下载elasticsearch-jdbc-2.2.0.0压缩包,将其解压至Elasticsearch的plugins目录下。 - **配置**:创建配置文件,设置数据库连接信息、Elasticsearch的地址、索引和映射等。 - **启动导入**:运行插件...
8. **配置文件**:在`elasticsearch-jdbc-2.2.0.0`压缩包中,很可能包含了一个示例配置文件(如`river.json`),用于指导用户如何配置数据导入作业。 9. **命令行工具**:Elasticsearch-JDBC通常通过命令行工具启动...
**Elasticsearch-jdbc数据同步配置** 在大数据分析和搜索引擎领域,Elasticsearch因其高效、可扩展和实时的搜索能力而被广泛应用。然而,数据往往存储在关系型数据库如MySQL中,为了实现数据的实时或者定期同步到...
Elasticsearch JDBC driver(x-pack-sql-jdbc-8.5.3.jar)
java -cp elasticsearch-jdbc-<version>.jar:river.properties org.elasticsearch.bootstrap.Elasticsearch ``` 这里的`<version>`是下载的Elasticsearch-JDBC版本号。 3. **停止同步**:在需要停止数据导入时,...
elasticsearch-river-jdbc-1.5.0.5.jar
x-pack-sql-jdbc-7.7.1是数据库客户端连接elasticsearch的驱动jdbc库
这个驱动的两个版本——x-pack-sql-jdbc-7.7.1.jar和x-pack-sql-jdbc-7.5.1.jar,分别对应Elasticsearch的7.7.1和7.5.1版本,确保与不同版本的Elasticsearch系统兼容。 1. **JDBC接口介绍** JDBC是Java中用于访问...
x-pack-sql-jdbc-6.4.0到x-pack-sql-jdbc-7.6.0各个版本jdbc驱动下载
x-pack-sql-jdbc-7.8.0.jar 连接es的数据库jdbc 驱动包 x-pack-sql-jdbc-7.8.0.jar 连接es的数据库jdbc 驱动包
x-pack-sql-jdbc-7.9.1.jar
elasticsearch的 8.11.3 的jdbc驱动,欢迎下载。
The Java Database Connection (JDBC) importer allows to fetch data from JDBC sources for indexing into Elasticsearch. The JDBC importer was designed for tabular data. If you have tables with many ...
elastic serach 数据库jdbc驱动。x-pack-sql-jdbc-7.5.1.jar
连接es所需jar包 ...-- https://mvnrepository.com/artifact/org.elasticsearch.plugin/x-pack-sql-jdbc --> <groupId>org.elasticsearch.plugin <artifactId>x-pack-sql-jdbc <version>6.8.15 </dependency>
在实际应用中,开发人员可以使用诸如Java的JDBC API或者IDE中的数据库工具(如IntelliJ IDEA或Eclipse)来连接Elasticsearch。以下是一个简单的Java代码示例: ```java Class.forName("org.elasticsearch.xpack.sql...
elasticSearch 6.8 客户端连接JAR包x-pack-sql-jdbc-6.8.0
数据库客户端连接elasticsea rch的驱动jdbc库 x-pack-sql-jdbc-7.8.0.jar