mac部署logstash,并增量同步mysql数据到elasticsearch

1.下载 logstash-6.2.3.tar.gz

2.解压

3.安装插件
bin/logstash-plugin install logstash-input-jdbc
bin/logstash-plugin install logstash-output-elasticsearch

4.logstash-6.2.3下新建目录
postion目录和jar目录

5.将mysql驱动mysql-connector-java-5.1.46.jar复制到jar目录

6.修改config/pipelines.yml文件

- pipeline.id: table1
  path.config: "pipelines"

注:path.config为执行运行sql的配置文件目录

7.logstash-6.2.3目录下新建pipelines目录
新建配置文件school.conf

input {
 stdin { }
    jdbc {
        jdbc_connection_string => "jdbc:mysql://xxx/common?characterEncoding=UTF-8"
        jdbc_user => "root"
        jdbc_password => "root"
        jdbc_driver_library => "./jar/mysql-connector-java-5.1.46.jar"
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        jdbc_paging_enabled => "true"
        jdbc_page_size => "500"
        schedule => "* * * * *"
        use_column_value => true
        tracking_column => update_at
        tracking_column_type => "numeric"
        record_last_run => true
        last_run_metadata_path => "./postion/school_postion.txt"
        statement => "select t.*,t.university_id as id from sys_university t where update_at > :sql_last_value"
    }
 }
  
 output {
     stdout {
        codec => json_lines
    }
    elasticsearch {
        hosts => "10.1.0.176:9200"
        index => "common_index"
        document_type => "sys_university"
        document_id => "%{id}"
    }
}

注:
#如果为ture,需要提供增量查询字段,如果update_at
use_column_value => true
#指定增量的字段名
tracking_column => update_at
#增量字段的类型
tracking_column_type => “numeric”
#记录最后一条数据结果
record_last_run => true
#保存位置
last_run_metadata_path => “./postion/school_postion.txt”

8.运行
./bin/logstash

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值