logstash同步pgsql数据到Elasticsearch

一、对于logstash的配置我就不在多说,主要是三部分,input、filter、output的配置

二、配置步骤

1、input配置

input {
    stdin {
    }
    jdbc {
      jdbc_connection_string => "jdbc:postgresql://127.0.0.1:5432/world"
      jdbc_user => "postgres"
      jdbc_password => "zhang123"
      jdbc_driver_library => "D:\logstash-6.4.0\bin\pgsql\postgresql-42.2.5.jar"
      jdbc_driver_class => "org.postgresql.Driver"
      jdbc_paging_enabled => "true"
      jdbc_page_size => "300000"
      use_column_value => "true"
      tracking_column => "id"
      statement_filepath => "D:\logstash-6.4.0\bin\pgsql\jdbc.sql"
	  schedule => "* * * * *"
	  type => "jdbc"
	  jdbc_default_timezone =>"Asia/Shanghai"
    }
}

2、filter配置

filter {
    json {
        source => "message"
        remove_field => ["message"]
    }
}

3、output 配置,就是elasticsearch的基本配置

output {
    elasticsearch {
        hosts => ["localhost:9200"]
        index => "test_out"
		template => "D:\logstash-6.4.0\bin\pgsql\es-template.json"
		template_name => "t-statistic-out-logstash"
		template_overwrite => true
		document_type => "out"
        document_id => "%{id}"
    }
    stdout {
        codec => json_lines
    }
}

以上就是整个logstash 的jdbc.conf

4、es-template.json的配置

{
	"template" : "t-statistis-out-template", 
	"order":1,
	"settings": {
            "index": {
                "refresh_interval": "5s"
            }
        },
		"mappings": {
            "_default_": {
			"_all" : {"enabled":false}, 
                "dynamic_templates": [
                    { 
              "message_field" : { 
                "match" : "message", 
                "match_mapping_type" : "string", 
                "mapping" : { "type" : "string", "index" : "not_analyzed" } 
              } 
            }, { 
              "string_fields" : { 
                "match" : "*", 
                "match_mapping_type" : "string", 
                "mapping" : { "type" : "string", "index" : "not_analyzed" } 
              } 
            }
                ],
                "properties": {
                    "@timestamp": {
                        "type": "date"
                    },
                    "@version": {
                        "type": "keyword"
                    },                    
					"id": {
                        "type": "keyword"
                    },
					"name": {
                        "type": "keyword"
                    },
					"pp": {
                        "type": "keyword"
                    }					
                }
            }
        },
        "aliases": {}
    
}

最后就是就是下载好pgsql的连接驱动,这个官网可以下载;配置好自己的数据库表格的数据

启动命令:进入到logstash的bin目录下,自己的logstash配置都是放在bin的pgsql这个目录下面(这个自己随意创建位置都可以)

logstash.bat -f ./pgsql/jdbc.conf

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

伏特加的滋味

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值