我的logstash配置文件如下(方案是从oracle中导出数据,然后导入到mysql中去,以下是一个测试配置,仅仅获取oracle PERSON_INFO表的ID字段,准备让mysql来接受这个字段的数据):
input {
stdin {
}
jdbc {
jdbc_driver_library => "/usr/share/logstash/config/ojdbc6.jar"
jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
jdbc_connection_string => "jdbc:oracle:thin:@//192.168.10.5:1521/orcl"
jdbc_user => "sdystr"
jdbc_password => "shandong"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
jdbc_default_timezone => "Asia/Shanghai"
statement => "select ID,INIT_SERVER_NO from Person_Info;"
# schedule => "* * * * * Asia/Shanghai"
type => ""#####LAB_SERVER_NO#####""
record_last_run => "true"
use_column_value => "true"
tracking_column_type => "timestamp"
tracking_column => "XXXXXX"
last_run_metadata_path => "/usr/share/logstash/config/last_datetime/Person_Info"
clean_run => "false"
lowercase_column_names => "false"
}
}
filter {
json {
source => "message"
remove_field => ["message","@version","host","@timestamp"]
}
}
output {
jdbc {
driver_jar_path => "/opt/logstash-6.3.1/config/mysql-connector-java-8.0.11.jar"
driver_class => "com.mysql.jdbc.Driver"
connection_string => "jdbc:mysql://192.168.10.61:3306//ystr2?autoReconnect=true&usrSSL=true&user=ystr2&password=ystr2"
statement => ["insert into table(column1,column2) values(?,?)","%{[message][1]}","%{[message][2]}"]
}
}
然后我就启动了这个conf文件,之后输出没有报错,但是mysql收到的字段显示为图片那的格式,如果有解答,必有重谢,QQ247991998
input {
stdin {
}
jdbc {
jdbc_driver_library => "/usr/share/logstash/config/ojdbc6.jar"
jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
jdbc_connection_string => "jdbc:oracle:thin:@//192.168.10.5:1521/orcl"
jdbc_user => "sdystr"
jdbc_password => "shandong"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
jdbc_default_timezone => "Asia/Shanghai"
statement => "select ID,INIT_SERVER_NO from Person_Info;"
# schedule => "* * * * * Asia/Shanghai"
type => ""#####LAB_SERVER_NO#####""
record_last_run => "true"
use_column_value => "true"
tracking_column_type => "timestamp"
tracking_column => "XXXXXX"
last_run_metadata_path => "/usr/share/logstash/config/last_datetime/Person_Info"
clean_run => "false"
lowercase_column_names => "false"
}
}
filter {
json {
source => "message"
remove_field => ["message","@version","host","@timestamp"]
}
}
output {
jdbc {
driver_jar_path => "/opt/logstash-6.3.1/config/mysql-connector-java-8.0.11.jar"
driver_class => "com.mysql.jdbc.Driver"
connection_string => "jdbc:mysql://192.168.10.61:3306//ystr2?autoReconnect=true&usrSSL=true&user=ystr2&password=ystr2"
statement => ["insert into table(column1,column2) values(?,?)","%{[message][1]}","%{[message][2]}"]
}
}
然后我就启动了这个conf文件,之后输出没有报错,但是mysql收到的字段显示为图片那的格式,如果有解答,必有重谢,QQ247991998
2 个回复
medcl - 今晚打老虎。
赞同来自: ljx95315
2.你已经指定了列名(ID,INIT_SERVER_NO),直接通过各个列名就可以拿到数据的,如:%{ID}
output里面:
statement => ["insert into table(column1,column2) values(?,?)","%{ID}","%{INIT_SERVER_NO}"]
ljx95315
赞同来自: