Elasticsearch sync MySQL database under Windows platform

Source: Internet
Author: User
Tags logstash





Elasticsearch database

I'm using Elasticsearch's version of elasticsearch-6.3.1.

Elasticsearch create database


MySQL's data is 5.7, in fact, this relationship is not big.


Elasticsearch vs database

Logstash version is 6.3.1


Logstash database to elasticsearch

Elasticsearch plug-in Elasticsearch-head-master, now pressurized well, directly placed in the Elasticsearch directory under the good, this is not mandatory.


Why elasticsearch is not a database

This is the MySQL database connection driver Mysql--connector-java-5.1.18.zip



Because the Elasticsearch plugin is used, it is necessary to install Nondjs because the NPM












1: Start Elasticsearch first



Install ElasticSearch plug-in, directly double-click/bin/elasticsearch.bat, after successful startup: Http://127.0.0.1:9200/












2: Install, start Elasticsearch plugin



The grunt command is required to run the head, so you need to install grunt. So the first to install Nodejs, double plus exe can be. Then the cmd command, Node-v, if a version number appears, indicates that the installation was successful.



Then install GRUNT,NPM install-g grunt-cli, and if not, execute this command on the CD to the Nodejs installation directory.



After the grunt is installed, perform NPM install on the CD to the directory under which you unzipped the Elasticsearch-head-master (and the same directory as the bin), if this fails please refer to: 78742524



Boot CD to your extracted head directory, bin sibling, execute NPM run start, after successful execution: Http://localhost:9100/












3, first build a lib under the Logstash directory, and put your current MySQL connection drive Jar pack in






Build a SQL file, mine is built Jdbc.sql, inside is the SQL statement of the data table you want to synchronize,



SELECT
Id
Sys_log_level,
Project_Name,
Function_name,
Sys_log_msg,
Create_time
From
Log_sys
ORDER by
Create_time DESC









When these things are ready, modify the Logstash configuration file, not the one below the Config folder. The picture above is logstash.conf.






input {
	tcp {
		port=>5549
	}
	jdbc{
		jdbc_connection_string => "jdbc:mysql://192.168.2.104:33060/ygsc_scm?useSSL=false&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"
		jdbc_user => "tt"
		jdbc_password => "2344WsL1JrUntER2Zns32WmGwr"
		jdbc_driver_library => "lib\mysql-connector-java-5.1.18-bin.jar"
		jdbc_driver_class => "com.mysql.jdbc.Driver"
		jdbc_paging_enabled => "true"
		jdbc_page_size => "50000"
		statement_filepath => "jdbc.sql"
		schedule => "* * * * *"
		type => "jdbc"
	}
}
output {
	elasticsearch {
		index => "testdb"
		document_type => "%{type}"
		hosts => ["localhost:9200"] 
	}
}





After these logstash preparations are done, modify the Gemfile file under the Logstash folder, change the source to: https://gems.ruby-china.org, and then go to the Logstash bin directory,  Perform logstash-plugin install LOGSTASH-INPUT-JDBC here if there is a problem, please refer to: 79568743, install the plugin and then go to the Bin directory to execute the LOGSTASH.BAT-F Ogstash.conf, you can start it up.






This is the kind of service that the startup project will be made in later. It doesn't have to be started every time you click Bat or enter a command.






Elasticsearch sync MySQL database under Windows platform


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.