• elasticsearch5.2.1使用logstash同步mysql


    centos 本人亲测可以 得意得意 首先安装好mysql,elasticsearch   不懂的请参考另一篇文章

    安装logstash
    官方:https://www.elastic.co/guide/en/logstash/current/installing-logstash.html
    1.下载公共密钥
    rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
    2.添加yum源
    vim  /etc/yum.repos.d/logstash.repo
    文件中写入
    [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
    保存退出
    3.使用yum安装
    yum install logstash
    4.验证是否安装成功
    进入 logstash 安装目录
    cd /usr/share/logstash
    运行
    bin/logstash -e 'input { stdin { } } output { stdout {} }'
    等待几秒钟 出现  
    The stdin plugin is now waiting for input:
    然后输入 
    hello world
    得到类似的结果
    2016-11-24T08:01:55.949Z bogon hello world

    安装logstash-input-jdbc插件

    1.安装 ruby 和 rubygems(注意:需要 ruby 的版本在 1.8.7 以上)
    # yum install -y ruby rubygems
    检查 ruby 版本:
    # ruby -v
    ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
    替换国内的镜像
    gem sources --remove http://rubygems.org/

    gem sources -a http://gems.ruby-china.org/
    验证是否成功
    gem sources -l
    修改Gemfile的数据源地址
    whereis logstash # 查看logstash安装的位置, 我的在 /usr/share/logstash目录

    cd /usr/share/logstash
    vim Gemfile
    修改 source 的值 为: "https://gems.ruby-china.org/"

    vim  Gemfile.jruby-1.9.lock 

    # 找到 remote 修改它的值为:https://gems.ruby-china.org/

    开始安装

    ./bin/logstash-plugin install --no-verify  logstash-input-jdbc

    2.写配置文件开始同步 vi xxx.conf

    [html] view plain copy
     
    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 => "1000"  
    11.       statement => "select * from user"  
    12.       schedule => "* * * * *"  
    13.     }  
    14.   
    15.     jdbc {  
    16.       type => "task"  
    17.       jdbc_connection_string => "jdbc:mysql://192.168.33.101:3306/test"   
    18.       jdbc_user => "root"      
    19.       jdbc_password => "123456"  
    20.       jdbc_driver_library => "/usr/share/logstash/mysql-connector-java-5.1.41.jar"  
    21.       jdbc_driver_class => "com.mysql.jdbc.Driver"  
    22.       jdbc_paging_enabled => "true"  
    23.       jdbc_page_size => "1000"  
    24.       statement => "select * from task"  
    25.       schedule => "* * * * *"  
    26.     }  
    27. }  
    28.   
    29. filter{  
    30.  mutate{  
    31.        remove_field => [ "@timestamp", "@version"]  
    32.  }  
    33. }  
    34.   
    35. output {  
    36.    if [type] == "user" {  
    37.     elasticsearch {  
    38.         hosts  => ["192.168.33.111:9200","192.168.33.112:9200","192.168.33.113:9200"]  
    39.         index => "testindex"  
    40.         document_type => "user"  
    41.         document_id => "%{id}"  
    42.         user => "elastic"  
    43.         password => "changeme"  
    44.     }  
    45.    }  
    46.    if [type] == "task" {  
    47.     elasticsearch {  
    48.         hosts  => ["192.168.33.111:9200","192.168.33.112:9200","192.168.33.113:9200"]  
    49.         index => "testindex"  
    50.         document_type => "task"  
    51.         document_id => "%{id}"  
    52.         user => "elastic"  
    53.         password => "changeme"  
    54.     }  
    55.    }  
    56. }  


    执行:bin/logstash -f xxx.conf
    ok   大功告成!!!
  • 相关阅读:
    php intval()函数
    MVC开发模式
    Session详解
    JSP入门
    Response中文乱码问题
    cookie入门
    idea实现更改servlet模板
    使用new和newInstance()创建类的区别
    Servlet 3.0 新特性详解
    web Servlet 3.0 新特性之web模块化编程,web-fragment.xml编写及打jar包
  • 原文地址:https://www.cnblogs.com/a-du/p/8304409.html
Copyright © 2020-2023  润新知