侧边栏壁纸
博主头像
程彬彬博主等级

业精于勤 荒于嬉 行成于思 毁于随

  • 累计撰写 101 篇文章
  • 累计创建 26 个标签
  • 累计收到 20 条评论

目 录CONTENT

文章目录
ELK

logstash同步MySQL数据

程彬彬
2019-12-20 / 0 评论 / 0 点赞 / 1,522 阅读 / 0 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2019-12-20,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
广告 广告

1.配置值说明 https://www.elastic.co/guide/en/logstash/7.5/plugins-inputs-jdbc.html

数据库驱动 mysql-connector-java-5.1.48.jar 放在 logstash-7.5.0/logstash-core/lib/jars 目录下

2.配置logstash-mysql.conf

input {
	jdbc {
		jdbc_driver_library => "mysql-connector-java-5.1.48.jar"
		jdbc_driver_class => "com.mysql.jdbc.Driver"
		jdbc_connection_string => "jdbc:mysql://192.168.124.4:3306/xx"
		jdbc_user => "root"
		jdbc_password => "123456"
		schedule => "* * * * *"
		jdbc_paging_enabled => "true"
		jdbc_page_size => "50000"
		statement => "SELECT * FROM t_device WHERE update_time >= :sql_last_value  and update_time<now() order by update_time desc"
		type => "t_device"
		lowercase_column_names => false
		record_last_run => true
		use_column_value => true
		tracking_column => "update_time"
		tracking_column_type => "timestamp"
		last_run_metadata_path => "/datas/elastic/logstash/position/t_device"
		clean_run => false
	}
	jdbc {
		jdbc_driver_library => "mysql-connector-java-5.1.48.jar"
		jdbc_driver_class => "com.mysql.jdbc.Driver"
		jdbc_connection_string => "jdbc:mysql://192.168.124.4:3306/xx"
		jdbc_user => "root"
		jdbc_password => "123456"
		schedule => "* * * * *"
		jdbc_paging_enabled => "true"
		jdbc_page_size => "50000"
		statement => "SELECT * FROM t_area_detail WHERE update_time >= :sql_last_value  and update_time<now() order by update_time desc"
		type => "t_area_detail"
		lowercase_column_names => false
		record_last_run => true
		use_column_value => true
		tracking_column => "update_time"
		tracking_column_type => "timestamp"
		last_run_metadata_path => "/datas/elastic/logstash/position/t_area_detail"
		clean_run => false
	}
}

filter {
	date {
		match => [ "timeslice", "yyyy-MM-dd HH:mm:ss" ]
		timezone => "Asia/Shanghai"
	}
	json {
		source => "message"
		remove_field => ["message"]
	}
}

	output {
	if [type]=="t_device"{
		elasticsearch {
			hosts => ["192.168.33.88:9200"]
			index => "device"
			document_id => "%{id}"
		}
	}
	if [type]=="t_area_detail"{
		elasticsearch {
			hosts => ["192.168.33.88:9200"]
			index => "t_area_detail"
			document_id => "%{id}"
		}
	}
	
	stdout {
		codec => json_lines
		}
}

3.启动 nohuo ./bin/logstash -f config/logstash-mysql.conf &

4.查询数据是否同步 image.png

0
广告 广告

评论区