Java的新项目学成在线笔记-day15(五)
发表于:2024-11-25 作者:热门IT资讯网编辑
编辑最后更新 2024年11月25日,2.3 Logstash扫描课程计划媒资Logstash定时扫描课程媒资信息表,并将课程媒资信息写入索引库。' 2.3.1 创建索引1、创建xc_course_media索引2、并向此索引创建如下映射
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的config目录创建xc_course_media_template.json,内容如下:本教程的xc_course_media_template.json目录是:D:/ElasticSearch/logstash7.2.1/config/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的config目录下配置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]