elasticsearch5.2.1 synchronizing MySQL with Logstash

Source: Internet
Author: User
Tags gpg stdin logstash

CentOS self-test can be installed first mysql,elasticsearch do not understand, please refer to another article

Installing Logstash
Official: https://www.elastic.co/guide/en/logstash/current/installing-logstash.html
1. Download the public key
RPM--import Https://artifacts.elastic.co/GPG-KEY-elasticsearch
2. Add Yum Source
Vim/etc/yum.repos.d/logstash.repo
Write in File
[logstash-5.x]
Name=elastic repository for 5.x packages
Baseurl=https://artifacts.elastic.co/packages/5.x/yum
Gpgcheck=1
Gpgkey=https://artifacts.elastic.co/gpg-key-elasticsearch
Enabled=1
Autorefresh=1
Type=rpm-md
Save exit
3. Installing with Yum
Yum Install Logstash
4. Verify that the installation is successful
Enter the Logstash installation directory
Cd/usr/share/logstash
Run
Bin/logstash-e ' input {stdin {}} ' output {stdout {}} '
Wait a few seconds to appear
The stdin plugin is now waiting for input:
And then enter
Hello World
Get a similar result
2016-11-24t08:01:55.949z Bogon Hello World

Installing the LOGSTASH-INPUT-JDBC Plugin

1. Install Ruby and RubyGems (note: Ruby is required in version 1.8.7 or more)
# yum Install-y Ruby RubyGems
To check the ruby version:
# ruby-v
Ruby 1.8.7 (2013-06-27 patchlevel 374) [X86_64-linux]
Replace mirrors in the country
Gem Sources--remove http://rubygems.org/

Gem Sources-a http://gems.ruby-china.org/
Verify success
Gem Sources-l
Modify the Gemfile data source address
Whereis Logstash # Check the location of the Logstash installation, my/usr/share/logstash directory

Cd/usr/share/logstash
Vim Gemfile
Modify the value of source to: "https://gems.ruby-china.org/"

Vim Gemfile.jruby-1.9.lock

# Locate remote to modify its value to: https://gems.ruby-china.org/

Start installation

./bin/logstash-plugin Install--no-verify LOGSTASH-INPUT-JDBC

2. Write the config file to start synchronizing VI xxx.conf

[HTML]View PlainCopy
  1. Input {
  2. JDBC {
  3. type => "User"
  4. jdbc_connection_string => "jdbc:mysql://192.168.33.101:3306/test"
  5. Jdbc_user => "root"
  6. Jdbc_password => "123456"
  7. jdbc_driver_library => "/usr/share/logstash/mysql-connector-java-5.1.41.jar"
  8. Jdbc_driver_class => "com.mysql.jdbc.Driver"
  9. jdbc_paging_enabled => "true"
  10. jdbc_page_size => "+"
  11. statement => "SELECT * from user"
  12. schedule => "* * * * * *"
  13. }
  14. JDBC {
  15. type => "task"
  16. jdbc_connection_string => "jdbc:mysql://192.168.33.101:3306/test"
  17. Jdbc_user => "root"
  18. Jdbc_password => "123456"
  19. jdbc_driver_library => "/usr/share/logstash/mysql-connector-java-5.1.41.jar"
  20. Jdbc_driver_class => "com.mysql.jdbc.Driver"
  21. jdbc_paging_enabled => "true"
  22. jdbc_page_size => "+"
  23. statement => "SELECT * from Task"
  24. schedule => "* * * * * *"
  25. }
  26. }
  27. filter{
  28. mutate{
  29. Remove_field => ["@timestamp", "@version"]
  30. }
  31. }
  32. Output {
  33. if [type] = = "User" {
  34. Elasticsearch {
  35. hosts => ["192.168.33.111:9200", "192.168.33.112:9200", "192.168.33.113:9200"]
  36. index => "Testindex"
  37. Document_type => "User"
  38. document_id => "%{id}"
  39. user => "Elastic"
  40. password => "changeme"
  41. }
  42. }
  43. if [type] = = "task" {
  44. Elasticsearch {
  45. hosts => ["192.168.33.111:9200", "192.168.33.112:9200", "192.168.33.113:9200"]
  46. index => "Testindex"
  47. Document_type => "task"
  48. document_id => "%{id}"
  49. user => "Elastic"
  50. password => "changeme"
  51. }
  52. }
  53. }


Execution: Bin/logstash-f Xxx.confok is done!!!

elasticsearch5.2.1 synchronizing MySQL with Logstash

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.