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
- Input {
- JDBC {
- type => "User"
- jdbc_connection_string => "jdbc:mysql://192.168.33.101:3306/test"
- Jdbc_user => "root"
- Jdbc_password => "123456"
- jdbc_driver_library => "/usr/share/logstash/mysql-connector-java-5.1.41.jar"
- Jdbc_driver_class => "com.mysql.jdbc.Driver"
- jdbc_paging_enabled => "true"
- jdbc_page_size => "+"
- statement => "SELECT * from user"
- schedule => "* * * * * *"
- }
- JDBC {
- type => "task"
- jdbc_connection_string => "jdbc:mysql://192.168.33.101:3306/test"
- Jdbc_user => "root"
- Jdbc_password => "123456"
- jdbc_driver_library => "/usr/share/logstash/mysql-connector-java-5.1.41.jar"
- Jdbc_driver_class => "com.mysql.jdbc.Driver"
- jdbc_paging_enabled => "true"
- jdbc_page_size => "+"
- statement => "SELECT * from Task"
- schedule => "* * * * * *"
- }
- }
- filter{
- mutate{
- Remove_field => ["@timestamp", "@version"]
- }
- }
- Output {
- if [type] = = "User" {
- Elasticsearch {
- hosts => ["192.168.33.111:9200", "192.168.33.112:9200", "192.168.33.113:9200"]
- index => "Testindex"
- Document_type => "User"
- document_id => "%{id}"
- user => "Elastic"
- password => "changeme"
- }
- }
- if [type] = = "task" {
- Elasticsearch {
- hosts => ["192.168.33.111:9200", "192.168.33.112:9200", "192.168.33.113:9200"]
- index => "Testindex"
- Document_type => "task"
- document_id => "%{id}"
- user => "Elastic"
- password => "changeme"
- }
- }
- }
Execution: Bin/logstash-f Xxx.confok is done!!!
elasticsearch5.2.1 synchronizing MySQL with Logstash