博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java的新项目学成在线笔记-day11(五)
阅读量:7022 次
发布时间:2019-06-28

本文共 4417 字,大约阅读时间需要 14 分钟。

3.4.3 创建模板文件

Logstash的工作是从MySQL中读取数据,向ES中创建索引,这里需要提前创建mapping的模板文件以便logstash 使用。
在logstach的config目录创建xc_course_template.json,内容如下:
本教程的xc_course_template.json目录是:D:/ElasticSearch/logstash-6.2.1/config/xc_course_template.json

[mw_shl_code=applescript,true] {    "mappings" : {       "doc" : {          "properties" : {             "charge" : {                "type" : "keyword"             },             "description" : {                "analyzer" : "ik_max_word",                "search_analyzer" : "ik_smart",                "type" : "text"             },             "end_time" : {                "format" : "yyyy‐MM‐dd HH:mm:ss",                "type" : "date"             },             "expires" : {                "format" : "yyyy‐MM‐dd HH:mm:ss",                "type" : "date"             },             "grade" : {                "type" : "keyword"             },             "id" : {                "type" : "keyword"             },             "mt" : {                "type" : "keyword"             },            "name" : {[/mw_shl_code][mw_shl_code=applescript,true] "analyzer" : "ik_max_word",                "search_analyzer" : "ik_smart",                "type" : "text"             },             "pic" : {                "index" : false,                "type" : "keyword"             },             "price" : {                "type" : "float"             },             "price_old" : {                "type" : "float"             },             "pub_time" : {                "format" : "yyyy‐MM‐dd HH:mm:ss",                "type" : "date"             },             "qq" : {                "index" : false,                "type" : "keyword"             },             "st" : {                "type" : "keyword"             },             "start_time" : {                "format" : "yyyy‐MM‐dd HH:mm:ss",                "type" : "date"             },             "status" : {                "type" : "keyword"             },             "studymodel" : {                "type" : "keyword"             },             "teachmode" : {                "type" : "keyword"             },             "teachplan" : {                "analyzer" : "ik_max_word",                "search_analyzer" : "ik_smart",                "type" : "text"             },             "users" : {                "index" : false,                "type" : "text"             },             "valid" : {                "type" : "keyword"             }          }       }   },[/mw_shl_code][mw_shl_code=applescript,true] "template" : "xc_course" } [/mw_shl_code]3.4.4 配置mysql.conf 在logstash的config目录下配置mysql.conf文件供logstash使用,logstash会根据mysql.conf文件的配置的地址从 MySQL中读取数据向ES中写入索引。 参考https://www.elastic.co/guide/en/ ... ns-inputs-jdbc.html配置输入数据源和输出数据源。[mw_shl_code=applescript,true]    "template" : "xc_course" }    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 course_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/logstash_metadata"   } }     output {   elasticsearch {   #ES的ip地址和端口   hosts => "localhost:9200"  #hosts => ["localhost:9200","localhost:9202","localhost:9203"]   #ES索引库名称   index => "xc_course"   document_id => "%{id}"[/mw_shl_code][mw_shl_code=applescript,true]document_type => "doc"   template =>"D:/ElasticSearch/logstash‐6.2.1/config/xc_course_template.json"   template_name =>"xc_course"   template_overwrite =>"true"   }   stdout {  #日志输出   codec => json_lines   } } [/mw_shl_code]

说明:

1、ES采用UTC时区问题 ES采用UTC 时区,比北京时间早8小时,所以ES读取数据时让最后更新时间加8小时 where timestamp > date_add(:sql_last_value,INTERVAL 8 HOUR)
2、logstash每个执行完成会在D:/ElasticSearch/logstash-6.2.1/config/logstash_metadata记录执行时间下次以此 时间为基准进行增量同步数据到索引库。

转载于:https://blog.51cto.com/13517854/2397751

你可能感兴趣的文章
我的友情链接
查看>>
关于securecrt7.2版本安装在win8系统激活的问题
查看>>
我的友情链接
查看>>
C028 unable to connect to siebel gateway name server
查看>>
PLSQL Developer连接远程Oracle数据库
查看>>
JS一个非常经典的问题:在遍历数组时对DOM监听事件,索引值将始终等于遍历结束后的值...
查看>>
python 路径问题
查看>>
flink could not find implicit value for evidence parameter of type
查看>>
Centos6.3 下apache-solr-3.6.2安装和配置
查看>>
Windows程序中的字符编码问题
查看>>
iOS应用崩溃日志分析
查看>>
Redhat安装hba卡,配置emc powerpath,配置LVM
查看>>
html 的最简洁的遮罩
查看>>
我的友情链接
查看>>
走出问题的乌托邦
查看>>
今天的工作日志
查看>>
Opensuse12.2配置 Apache2+PHP5+MySQL(LAMP)
查看>>
经典SQL语法大全
查看>>
使用数据库统一管理ssh登陆用户密钥信息
查看>>
Active 与 Service 的生命周期、保存数据----Day04 2014.5.29
查看>>