其实不管是gbase还是oracle、或是es本身或是其他数据源,只要logstash支持,都可以用下面这个方法去做,写写配置文件就可以实现导出csv文件。当然大部分时候是因为一些偏门的数据库,比如gbase、es,用自带的工具操作不了导出csv,navicat等又不支持。否则直接用navicat就好了。
配置文件如下:
input {
jdbc {
type => "type1"
jdbc_driver_library => "/home/logstash/gbase-connector-java-8.3.81.51-build-54.4.4-bin.jar"
jdbc_driver_class => "com.gbase.jdbc.Driver"
jdbc_connection_string => "jdbc:gbase://1.1.1.1:5258/db1"
jdbc_user => "***"
jdbc_password => "****#$"
statement => "select * from _log where xxxx"
jdbc_paging_enabled => true
jdbc_page_size => 100000
}
jdbc {
type => "type2"
jdbc_driver_library => "/home/logstash/gbase-connector-java-8.3.81.51-build-54.4.4-bin.jar"
jdbc_driver_class => "com.gbase.jdbc.Driver"
jdbc_connection_string => "jdbc:gbase://2.2.2.2:5258/db2"
jdbc_user => "****"
jdbc_password => "****#$"
statement => "select * from _log where xxxx"
jdbc_paging_enabled => true
jdbc_page_size => 100000
}
}
output {
if [type] == "type1" {
csv {
fields => ["user_id","user_name","operate_time"] // fields即查询表的字段
path => "/tmp/type1.csv"
}
}
if [type] == "type2" {
csv {
fields => ["user_id","user_name","operate_time"] // fields即查询表的字段
path => "/tmp/type2.csv"
}
}
}
网友评论