Linux uses the ELASTICSEARCH-JDBC tool to implement MySQL sync to Elasticsearch and Linux 64-bit CentOS system installation jdk1.8

Source: Internet
Author: User
Tags curl

First step: Environment matching

1) Elasticsearch 2.3.3 Successful Installation deployment
2) MySQL installation success, delete and change to check the correct ~ ~.

3) To ensure that the ELASTICSEARCH-JDBC version is consistent with the elasticsearch version (the content below will prompt for download). Otherwise the error will be made and the subsequent steps cannot be performed.

(e.g. Elasticsearch-jdbc-2.3.3.0-dist.zip (corresponding to your elaseticsearh-2.3.3)

4) (Linux jdk1.8 installed under centos) (mine is CentOS release 6.5 (Final))

Recommended JDK version for 1.8 Best (I was 1.7 error at first)--Exception in thread " Main "java.lang.unsupportedclassversionerror:org/xbib/tools/runner:unsupported Major.minor version 52.0

Because the JDK 1.7 version is versions , and 1.6 is the Edition, it needs to be installed The version of1.8is the best. otherwise , it's over before it starts. !!! ~~

Rpm-qa|grep JDK// Check the previous version

JAVA-1.7.0-OPENJDK-1.7.0.45-2.4.3.3.EL6.X86_64//Previous version

RPM-E--nodeps java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64// Delete it

Download JDK

Website:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Choose

Select Accept License Agreement, then click on the corresponding version to download, here only to introduce the source installation

installing jdk1.8 under CentOS

1. Extracting Files

TAR-ZXVF jdk-8u101-linux-x64.tar.gz

2. move the extracted files directory to /usr/local

MV Jdk1.8.0_101/usr/local

3. Configure Environment Variables

Vi/etc/profile

Put it in the end.

#set Java JDK

Export java_home=/usr/local/jdk1.8.0_101/

Export JRE_HOME=${JAVA_HOME}/JRE

Export Classpath=.:${java_home}/lib:${jre_home}/lib

Export Path=${java_home}/bin: $PATH

4. make the profile effective immediately:

Source/etc/profile

5. Check if the configuration is successful

Java-version

Step two: Download the JDBC tool

Select the version you want to download. (e.g. Elasticsearch-jdbc-2.3.3.0-dist.zip (corresponding to your elaseticsearh-2.3.3), download suffix dist.zip)

Address:

http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc/

Step three: Import a directory under Linux

Unzip the downloaded file unzip Elasticsearch-jdbc-2.3.3.0-dist.zip (can also be extracted under windows and then import Linux without this command, Recommended tool WINSCP (it can be used to drag files between Windows and Linux two platform data OH), play Linux necessary tools and Xshell (use words to explore Baidu a bit ~~! ))

I put it in the default root directory:/elasticsearch-jdbc-2.3.3.0

Fourth step: Synchronize the key to import data, create a new script

cd/elasticsearch-jdbc-2.3.3.0/bin/(Create our new script in the bin directory)

VI import_es.sh

#!/bin/sh

Bin=/elasticsearch-jdbc-2.3.3.0/bin

Lib=/elasticsearch-jdbc-2.3.3.0/lib

Echo ' {

"Type": "JDBC",

"JDBC": {

"Elasticsearch.autodiscover": true,

"Elasticsearch.cluster": "Ffcs-test", Cluster Name: #默认elasticsearch, see ELASTICSEARCH.YML

"url": "Jdbc:mysql://localhost:3306/test", #mysql数据库地址, 3306 is the default port, test is the database name

"User": "Root", #mysql用户名

"Password": "123456", #mysql密码

"SQL": "SELECT * from Ffcs", #ffcs是数据库表名

"Index": "Test", #自定义索引名

' type ': ' Ffcs ' #自定义类型名

}

} ' | Java \

-CP "${lib}/*" \

-dlog4j.configurationfile=${bin}/log4j2.xml \

Org.xbib.tools.Runner \

Org.xbib.tools.JDBCImporter

Note: In the copy of the # kanji can not be copied in, otherwise there will be a variety of inexplicable situation

After that you can write the JSON content to www.json.cn verification is correct, if not correct after the error will be

{

"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"

}

}

is the above content to the site of the analysis check to see if you write your own errors, avoid the execution of the script when there are unnecessary errors

Add executable permissions for import_es.sh.

chmod a+x import_es.sh//(A+x is to add executable permissions to everyone, including owner, group, and other people o+x just add executable permissions to others )

Execute script:./import_es.sh

Fifth step: Detect whether the data has been added successfully

Does Curl ' localhost:9200/_cat/indices?pretty '// index have new??

Curl-xget ' Http://localhost:9200/test/ffcs/_search?pretty '// fetch display Data

Query by various criteria

Curl ' localhost:9200/test/ffcs/_search?pretty '-d '

{

"Filter": {"term": {"name": "John"}}

}‘

Curl ' localhost:9200/test/ffcs/_search?pretty '-d '

{

"Filter": {"term": {"id": "5"}}

}‘

The above can be explained that you are done oh ~ ~

I've tried the elasticsearch-1.7.1 version before, and I'm having an error.

[ERROR] [Importer.jdbc.source.standard] [Pool-2-thread-1] While opening read connection:jdbc:mysql://localhost:3306/test No suitable driver found for jdbc:mysql ://localhost:3306/test
Java.sql.SQLException:No suitable driver found for jdbc:mysql://localhost:3306/test

Unable to find the right driver ...

In this case, the index and type can be successfully established ~, but there is no data in the OH ~~null.

(Hope to help you!!) ~ ~)

Linux uses the ELASTICSEARCH-JDBC tool to implement MySQL sync to Elasticsearch and Linux 64-bit CentOS system installation jdk1.8

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.