logstash采集mysql不同表的数据到es不同的索引库中

1 篇文章 0 订阅
1 篇文章 0 订阅

1.需求:采集同一个数据库中不同的表到同一个es服务的不同索引中
2.配置文件

input {
  stdin {
  }
  #操作mysql取出数据
  jdbc {
	  jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/数据库名称?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC"
	  #用户名
	  jdbc_user => "*****"
	  #密码
	  jdbc_password => "****"
	  jdbc_driver_library => "mysql数据库连接jar包位置"
	  jdbc_driver_class => "com.mysql.jdbc.Driver"
	  jdbc_paging_enabled => "true"
	  jdbc_page_size => "50000"
	  statement => "select * from course_pub where timestamp > date_add(:sql_last_value,INTERVAL 8 HOUR)"
	  schedule => "* * * * *"
	  record_last_run => true
	  last_run_metadata_path => "采集记录的时间戳文件路径"
	  type => "表名1"  
      tags => "表名1"
  }
  jdbc {
	  jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/数据库名称?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC"
	   #用户名
	  jdbc_user => "*****"
	  #密码
	  jdbc_password => "****"
	  jdbc_driver_library => "mysql数据库连接jar包位置"
	  jdbc_driver_class => "com.mysql.jdbc.Driver"
	  jdbc_paging_enabled => "true"
	  jdbc_page_size => "50000"
	  statement => "select * from teachplan_media_pub where timestamp > date_add(:sql_last_value,INTERVAL 8 HOUR)"
	  schedule => "* * * * *"
	  record_last_run => true
	  last_run_metadata_path => "采集记录的时间戳文件路径"
	  type => "表名2"  
      tags => "表名2"
  }
}


output {
	if [type] == "表名1"{
       elasticsearch {
		  hosts => "localhost:9200"
		  index => "索引1"
		  document_id => "%{id}"
		  document_type => "doc"
		  template =>"模板位置"
		  template_name =>"模板名称"
		  template_overwrite =>"true"
	  }
    }
    if [type] == "表名2"{
        elasticsearch {
		  hosts => "localhost:9200"
		  index => "索引2"
		  document_id => "%{teachplan_id}"
		  document_type => "doc"
		  template =>"模板位置"
		  template_name =>"模板名称"
		  template_overwrite =>"true"
		}
    }
  stdout {
	  codec => json_lines
  }
}

2.运行,进入logstash的bin目录,
.\logstash -f ..\config\配置文件的名称.conf
参考:https://www.cnblogs.com/sanduzxcvbnm/p/12859292.html

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值