logstash 配置多个conf和配置增量更新

参考:https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html

logstash可以配置多个pipeline,每一个pipeline设置不同的参数,包括读取的conf;

也可以配置一个pipeline,读取多个conf,其读取多个conf,实际上是把它们合并一起,所以,conf里面需要写上type,通过type来判断写入那个索引。

logstash.yml的配置修改如下:

logstash.yml的设置:
# pipeline.id: main
pipeline.id: d_bzdz

#
# path.config:
path.config: "/map/es/soft/logstash-7.6.2/config/myconfig/*.conf"

运行的时候就不需要 -f conf参数。

运行 ./bin/logstash
# Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.

input{
	# stdin{}
	jdbc{
		jdbc_connection_string => "jdbc:oracle:thin:@//:1521/GIS"
		jdbc_user => ""
		jdbc_password => ""
		jdbc_driver_library => "/es/soft/logstash-7.6.2/lib/ojdbc7.jar"
		jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
		# jdbc_default_timezone => "Asia/Shanghai"  
        # 统一用一个时间标准即可,不需要设置。oracle本来的时区也是+00。
		# plugin_timezone => "local"
		# 228万条记录 12分钟完成同步
		jdbc_paging_enabled => "true"
		# 每批传输数量
		jdbc_page_size => "100000"
		# sql_last_value 是最后查询的值(时间或者id),未执行查询之前,它的值是1970.1.1,应该是时间戳的值;
		# 如果设置 use_column_value => "true"  
#和tracking_column ,sql_last_value 的默认值是0,之后是这个字段的最新值。
		# 如果use_column_value => "false",
#后续每次查询,都会记录执行查询的logstash时间 作为sql_last_value
		statement => "select t.systemid .... and t.lastupdatedtime > :sql_last_value order by t.lastupdatedtime asc"		
		# 设置为true时,sql_last_value的值是tracking_column的值;
#设置为false是,sql_last_value的值是上次执行的值。
		use_column_value => "true"
		# 是否保存状态
		record_last_run => "true"
		# 记录最后一条数据的时间戳,所以,sql语句里面需要 有
#order by t.lastupdatedtime asc
		tracking_column => "lastupdatedtime"
		# 只有两种类型numberic 和timestamp
		tracking_column_type => "timestamp"		
		# 记录 sql_last_value的文件
		last_run_metadata_path => "/es/soft/logstash-7.6.2/config/myconfig/mlp_parameter.txt"
		#设置监听间隔,各字段(分、时、天、月、年),全部*代表每分钟都更新
		# "0 * * * *" 在每小时每天的第0分钟运行
		# 设置每天12点0分运行  corn表达式
		schedule => "47 12 * * *"
		# 这个类型可以判断输入到哪个索引,因为我设置了一个pipeline读取多个conf,
#它实际是把多个conf合并成一个。
		type => "mlp_jdbc"
	}
}

filter {
	if[type] == "mlp_jdbc" {
		mutate {
			add_field => ["[location][lat]","%{zxwd}"]
			add_field => ["[location][lon]","%{zxjd}"]
		}

		ruby {
			code => "event.set('timestamp',event.get('@timestamp').time.localtime )"
		}

		ruby {
			code => "event.set('@timestamp',event.get('timestamp'))"
		}

		mutate {
			remove_field => ["timestamp"]
		}
	}	
}

output{
	if[type] == "mlp_jdbc" {
		elasticsearch{
			hosts => "localhost:9200"
			index => "d_bzdz_mlp"
			document_id => "%{systemid}"	
		}
		stdout{
			codec => "json_lines"
			# codec => "rubydebug"
		}
	}	
}

猜你喜欢

转载自blog.csdn.net/aganliang/article/details/107555735