您好,登錄后才能下訂單哦!
2.3 Logstash掃描課程計劃媒資
Logstash定時掃描課程媒資信息表,并將課程媒資信息寫入索引庫。
‘ 2.3.1 創建索引
1、創建xc_course_media索引
2、并向此索引創建如下映射
Post http://localhost:9200/xc_course_media/doc/_mapping
[mw_shl_code=applescript,true]{ "properties" : {
"courseid" : {
"type" : "keyword"
},
"teachplan_id" : {
"type" : "keyword"
},
"media_id" : {
"type" : "keyword"
},
"media_url" : {
"index" : false,[/mw_shl_code][mw_shl_code=applescript,true]
"type" : "text"
},
"media_fileoriginalname" : {
"index" : false,
"type" : "text"
}
} }[/mw_shl_code]
2.3.2 創建Logstash模板文件
在logstach的con?g目錄創建xc_course_media_template.json,內容如下:
本教程的xc_course_media_template.json目錄是:D:/ElasticSearch/logstash7.2.1/con?g/xc_course_media_template.json
[mw_shl_code=applescript,true]{
"mappings" : {
"doc" : {
"properties" : {
"courseid" : {
"type" : "keyword"
},
"teachplan_id" : {
"type" : "keyword"
},
"media_id" : {
"type" : "keyword"
},
"media_url" : {
"index" : false,
"type" : "text"
},
"media_fileoriginalname" : {
"index" : false,
"type" : "text"
}
}
},
"template" : "xc_course_media" }[/mw_shl_code]
2.3.3 配置mysql.conf
在logstash的con?g目錄下配置mysql_course_media.conf文件供logstash使用,logstash會根據 mysql_course_media.conf文件的配置的地址從MySQL中讀取數據向ES中寫入索引。 參考https://www.elastic.co/guide/en/ ... ns-inputs-jdbc.html
配置輸入數據源和輸出數據源。
[mw_shl_code=applescript,true]
2.3.4 啟動logstash.bat
啟動logstash.bat采集teachplan_media_pub中的數據,向ES寫入索引。
input {
stdin {
} jdbc {
jdbc_connection_string => "jdbc:mysql://localhost:3306/xc_course? useUnicode=true&characterEncoding=utf‐8&useSSL=true&serverTimezone=UTC" # the user we wish to excute our statement as
jdbc_user => "root" jdbc_password => mysql
# the path to our downloaded jdbc driver
jdbc_driver_library => "F:/develop/maven/repository3/mysql/mysql‐connector‐java/5.1.41/mysqlconnector‐java‐5.1.41.jar" # the name of the driver class for mysql jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
#要執行的sql文件
#statement_filepath => "/conf/course.sql"
statement => "select * from teachplan_media_pub where timestamp >
date_add(:sql_last_value,INTERVAL 8 HOUR)"
#定時配置 schedule => "* * * * *" record_last_run => true last_run_metadata_path => "D:/ElasticSearch/logstash‐6.2.1/config/xc_course_media_metadata" } }
output {
elasticsearch {
#ES的ip地址和端口
hosts => "localhost:9200"
#hosts => ["localhost:9200","localhost:9202","localhost:9203"]
#ES索引庫名稱 index => "xc_course_media" document_id => "%{id}"
document_type => "doc"
template =>"D:/ElasticSearch/logstash‐6.2.1/config/xc_course_media_template.json" template_name =>"xc_course_media" template_overwrite =>"true" } stdout { #日志輸出 codec => json_lines } }[/mw_shl_code]
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。